EIPs Explained

EIP-7610 · Last Call · Core · 2024-02-02

EIP-7610: Revert creation in case of non-empty storage

Makes contract creation fail if the target address already has storage, closing an old edge case where code could be deployed over leftover state and simplifying client implementations.

What problem does it solve?

A new contract can only be deployed to an address that is "empty". EIP-684 defined empty as: nonce is zero and there is no code. That check missed one case.

Before EIP-161 (2016), a freshly created contract started with nonce 0, not 1. If its constructor wrote storage but returned no code, the address ended up with zero nonce, zero code, and non-empty storage. Per EIP-684 a later CREATE or CREATE2 landing on that address would be allowed, deploying new code on top of old storage. The spec counts 28 such addresses on mainnet.

Actually hitting one of them would require a hash collision, but clients and test suites still had to model "account reset" behaviour for the case, and different clients handled it differently. EIP-7610 removes the ambiguity.

How it works

One extra condition is added to the deployment check. Contract creation, whether from a creation transaction, CREATE, CREATE2 or any other path, must fail if the destination has any of:

  • a nonzero nonce,
  • nonzero code length, or
  • non-empty storage (new).

The failure behaves as if the first byte of the init code were an invalid opcode: the creation fails and consumes its gas, exactly like an existing collision under EIP-684.

The rule applies retroactively to all blocks. That is safe because no such collision has ever happened, so re-executing history gives the same result.

EIP-7702 is unaffected: an authority's nonce is always incremented when an authorization is applied, so the nonce condition already blocks deployment there.

Sample code

The creation-collision check, before and after (pseudocode):

def can_deploy_at(state, addr) -> bool:
    acct = state.get_account(addr)
    # EIP-684
    if acct.nonce != 0 or len(acct.code) != 0:
        return False
    # EIP-7610
    if not state.storage_is_empty(addr):
        return False
    return True

def create(state, addr, init_code, gas):
    if not can_deploy_at(state, addr):
        return fail_consuming_all_gas()   # as if init_code[0] were INVALID
    return run_init_code(state, addr, init_code, gas)

Things to know

  • Status is Last Call.
  • For contract developers nothing changes in practice: the only addresses affected are the few legacy ones, and reaching them with CREATE2 (EIP-1014) would require a hash collision.
  • The spec frames it as a security fix that enforces the immutability of deployed code, and notes that existing tests relying on account reset need to be refilled.

#evm #create #create2 #core #storage

Details

Authors
Gary Rong (@rjl493456442), Martin Holst Swende (@holiman)
Status
Last Call
Type
Standards Track / Core
Created
2024-02-02
Required by

Machine-readable: Markdown · JSON