작성자 :
11주차 유진영

요약parity의 garbage collectionwiki.parity 내용State storage 관리(db, cache)geth 기준(참고) Empty account를 이용한 attack (EIP158, 161)
요약
parity는 touched empty account와, balance를 기준으로 정한 dust account를 삭제할수 있게 하였다. (contract account 포함)
우리는 오랜기간 사용하지않는 account를 compress하여 저장하고, 복구가 가능하도록 하려한다.
parity의 garbage collection
Parity는
removeDustContract
option으로 실행시 garbage collection을 수행.kill_garbage()
함수를 이용하여 touched empty account 나 dust account(EOA)를 삭제한다. - 모든 touched empty account삭제
- An account is considered to be touched when it is involved in any potentially state-changing operation. This includes, but is not limited to, being the recipient of a transfer of zero value.
- An account is considered empty when it has no code and zero nonce and zero balance.
- (
empty_and_is_null()
중is null()
역시 nonce = balance == 0 이면서 storage는 empty)
touched empty account : 0 을 전송 받았지만(*거래에는 참여하여 account의 state가 trie에 포함됨) tx를 발생시킨적 없는 계정
EIP 161 중 touched와 empty
*state-bloating attack 방지를 위해 Account생성 후 바로 trie에 추가되지 않고, 트랜잭션이 성공적으로 실행된것이 확인된 후(해당 트랜잭션이 포함된 블록이 채굴된 후) 추가된다고 한다.
- min_balance(100이하, 단위는 모르겠음..)보다 작은 balance를 가진 account 이면서
- (
is_basic()
codeHash가 empty) - 해당하는 contract account 삭제
(old_balance와 비교해) balance가 줄어들었다면
해당하는 basic account(즉, EOA계정) 삭제
wiki.parity 내용
"dustProtectionTransition"
- Activates Mainnet specific EIP-168 and EIP169 - Not active by default.
"nonceCapIncrement"
- U64 - Nonce cap increase per block. Nonce cap is only checked if dust protection is enabled..
"removeDustContracts"
- bool - Enable dust cleanup for contracts.- CleanDustMode는 3가지로 나뉜다. default는 off.
CleanDustMode가 WithCodeAndStorage
Off, BasicOnly(basic dust만 삭제), WithCodeAndStorage(basic and contract dust 둘다 삭제)
EIP168.C, 169.C 를 레퍼런스로함
EIP-168.C
An account is considered dust when it has a balance less than the transaction's gas_price multiplied by 21000 and no code.
EIP-169.C
a. Newly created account entries get a nonce equal to the current block number times
MAX_TXS_PER_ACCT_PER_BLOCK
.b. Transactions can only be sent from a nonempty account.
c. If an account has nonzero nonce, then a transaction sent from it may be included in the current block iff:
- the transaction has the same nonce as the account nonce; and
- the nonce divided by
MAX_TXS_PER_ACCT_PER_BLOCK
is no greater than the current block number.The account nonce is incremented as normal if the transaction is included.
Example
MAX_TXS_PER_ACCT_PER_BLOCK
could be 64.State storage 관리(db, cache)
geth 기준
Restart시 reorgs 상황을 대비하여 127개까지 접근가능한 과거 state를 db에저장함
- db에 저장한 state는 삭제불가
- Cache에 저장된것은 삭제 가능
db에 저장되지 않는 경우가 별로 없으므로 state가 지워지는 경우는 거의 없다.
- db에 저장되는 경우
caching된 것은 서버가 정상 종료시 db에 저장
생성후 128블록이 지나면 db에 저장
캐시 크기를 넘기면 db에 저장
마지막으로 캐시된 state가 db에 저장된지 5분이 지나면 db에 저장
(참고) Empty account를 이용한 attack (EIP158, 161)
2016년 9월말 DoS attack으로 1900만개의 empty account 생성
the attackers created significant state bloat of account empties; lacking code, balance, storage, and nonce == 0.
이를 해결하고 앞으로의 attack을 방지 하기 위해
EIP- 158(채택 안됨,161로 대체)
EIP-161(시행됨, State-trie clearing)
낮은 비용으로 빈 계정 제거를 가능하게하고, 빈계정을 생성하는 DoS공격을 예방
EIP-161 was designed to clean these account empties and was implemented on November 22, 2016, block 2675000.
하지만 이후 다른 버그가 발견되어 다시 사양이 수정됨
(빈 계정을 삭제하는 트랜잭션이 out-of-gas 예외로 종료되면 빈계정삭제를 되돌리는걸(revert) 실패했음. 제대로 되돌려지도록 하기위해 사양이 수정됨)
사용하지않는 계약에 공간사용료 부과하는 방법에 대한 내용도 어디서 본듯