EIPs Explained

EIP-4762 · Draft · Core · 2022-02-03

EIP-4762: Statelessness gas cost changes

Draft gas repricing for stateless Ethereum: state and code accesses are charged by how much they add to a block's witness, making grouped storage cheap and large code reads more expensive.

What problem does it solve?

In a stateless Ethereum, nodes verify blocks without holding the full state. Instead, each block ships with a witness: the pieces of state it touches plus proofs that they are correct. Today's gas schedule (EIP-2929 cold/warm pricing) does not reflect what each access adds to that witness. Reading 31 bytes of code, for example, is essentially free, even though in a stateless world that code must be shipped with the block.

EIP-4762 rewrites gas costs around witness size, for a tree layout in which each account's header fields, its first storage slots and its code chunks are grouped into "stems" of 256 leaves (as in the unified Verkle tree of EIP-6800). It was designed to ship before the tree switch, so developers and client teams could adapt early.

How it works

Every state touch is turned into an access event (address, sub_key, leaf_key), and every modification also into a write event. Per transaction, the client tracks which subtrees (stems) and leaves have been accessed or edited, and charges only the first time:

Constant Gas Charged when
WITNESS_BRANCH_COST 1900 first access to a stem
WITNESS_CHUNK_COST 200 first access to a leaf
SUBTREE_EDIT_COST 3000 first write to a stem
CHUNK_EDIT_COST 500 first write to a leaf
CHUNK_FILL_COST 6200 writing a leaf that held no value

What triggers events:

  • Account headers: *CALL, BALANCE, EXTCODESIZE, EXTCODECOPY, SELFDESTRUCT, contract creation, and value transfers touch the account's basic-data leaf; EXTCODEHASH touches the code-hash leaf. Precompiles and system contracts are mostly exempt.
  • Storage: SLOAD/SSTORE map a slot to a stem and leaf. Slots 0–63 live in the account's header stem, and slots sharing key // 256 share a stem.
  • Code: code is split into 31-byte chunks. Each chunk executed (including PUSH data and jump targets) or copied by CODECOPY/EXTCODECOPY is an access.

Several old costs are removed (the 200 gas/byte code deposit, the value-transfer CALL surcharge, most EIP-2200 SSTORE costs) and CREATE/CREATE2 drop to 1000 gas.

Sample code

Simplified witness-cost accounting for an access event (Python, after the spec):

WITNESS_BRANCH_COST, WITNESS_CHUNK_COST = 1900, 200

accessed_subtrees: set = set()
accessed_leaves: set = set()

def on_access(address: bytes, sub_key: int, leaf_key: int | None) -> int:
    gas = 0
    if (address, sub_key) not in accessed_subtrees:
        gas += WITNESS_BRANCH_COST
        accessed_subtrees.add((address, sub_key))
    if leaf_key is not None and (address, sub_key, leaf_key) not in accessed_leaves:
        gas += WITNESS_CHUNK_COST
        accessed_leaves.add((address, sub_key, leaf_key))
    return gas

# Reading slot 5, then slot 6, of the same contract:
# first SLOAD pays 1900 + 200, second pays only 200 (same stem)

Things to know

  • Status: Draft. Parts of the spec are still marked TODO (for example account abstraction interactions), and values may change.
  • Per the spec's rationale, the per-chunk code charge was estimated to raise average gas usage by roughly 6–12%, while cheaper adjacent and low-numbered storage slots should offset part of that. Compilers that pack hot variables into slots 0–63 benefit most.
  • The tree design has been evolving: alongside the Verkle proposal (EIP-6800), a unified binary tree (EIP-7864) has also been proposed. The access-event model here is meant to price witnesses for such grouped layouts.
  • Clients must store each stem's leaves together on disk; otherwise the cheaper grouped accesses would become a DoS vector.
  • Historical block hashes served from state (EIP-2935) are part of the same push towards stateless verification.

#gas #statelessness #verkle #witness #state #core

Details

Authors
Guillaume Ballet (@gballet), Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad), Ignacio Hagopian (@jsign), Tanishq Jasoria (@tanishqjasoria), Gajinder Singh (@g11tech)
Status
Draft
Type
Standards Track / Core
Created
2022-02-03
Required by

Machine-readable: Markdown · JSON