EIPs Explained

EIP-4747 · Stagnant · Core · 2022-02-02

EIP-4747: Simplify EIP-161

Proposed retroactively rewriting EIP-161's empty-account cleanup rules into a much shorter version, dropping edge cases that never occurred on mainnet once all empty accounts had been removed.

What problem does it solve?

The 2016 DoS attacks left millions of "empty" accounts in the state: zero nonce, zero balance, no code. EIP-161 (Spurious Dragon) stopped new ones from being created and deleted old ones whenever they were "touched" by one of eleven "potentially state-changing operations".

Those rules are intricate, under-documented and hard to test, and every new client has to implement them to sync from genesis. The EIP points out that the last empty accounts on mainnet were cleared in block 14,049,881, so many of the edge cases can never happen again and, in fact, never happened at all.

EIP-4747 rewrites EIP-161 so that client teams only implement what mainnet actually needs.

How it works

It retroactively replaces EIP-161 from its activation (block 2,675,000) with three rules:

  1. New accounts start with nonce 1 before running initcode.
  2. Empty accounts are treated as non-existent during EVM execution; anything that would create an empty account leaves it non-existent instead.
  3. An empty account is deleted only if it:
    • receives a zero-value CALL,
    • is the recipient of a zero-value transaction, or
    • is the beneficiary of a zero-value SELFDESTRUCT.

If that call, transaction or self-destruct is reverted, the deletion is reverted too (the spec lists one historical exception involving the RIPEMD160 precompile). Deletion may happen immediately or at the end of the transaction.

The other eight triggers in EIP-161 are dropped because they were impossible, could not apply to an empty account, or would make it non-empty anyway. Interactions with STATICCALL, which no EIP ever specified, are explicitly left undefined.

The spec also lists the only post-Byzantium state-clearing events on mainnet, so clients that want to can simply hardcode them.

Sample code

The simplified clearing rule as client pseudocode:

def is_empty(acct) -> bool:
    return acct.nonce == 0 and acct.balance == 0 and acct.code == b""

def maybe_clear(state, addr, value: int, kind: str):
    """kind in {'call', 'tx', 'selfdestruct_beneficiary'}."""
    acct = state.get(addr)
    if acct is not None and is_empty(acct) and value == 0:
        state.mark_for_deletion(addr)  # undone if the frame/tx reverts

# Any other operation touching an empty account: no special handling needed.

Things to know

  • Status: Stagnant. Clients still follow the original EIP-161 behaviour as tested; this proposal was not adopted as a replacement.
  • It is meant to be equivalent to EIP-161 on mainnet only. The spec notes that Ropsten and Ethereum Classic were not checked for edge cases.
  • Its correctness rests on three facts the authors state as assumptions: no empty account is ever touched and reinstated in the same transaction, the listed transactions are the only post-Byzantium clearings, and all empty accounts are gone.
  • Related cleanups: EIP-158 (the original state-clearing proposal) and EIP-6780, which later restricted SELFDESTRUCT.

#state #accounts #core #cleanup #clients

Details

Authors
Peter Davies (@petertdavies)
Status
Stagnant
Type
Standards Track / Core
Created
2022-02-02
Requires

Machine-readable: Markdown · JSON