EIPs Explained

EIP-7612 · Stagnant · Core · 2024-01-25

EIP-7612: Verkle state transition via an overlay tree

Proposed switching Ethereum's state to a Verkle tree by freezing the existing Merkle Patricia tree and writing all new state into a Verkle 'overlay' on top of it, deferring the slow migration of old data to a later step.

What problem does it solve?

Moving Ethereum's state from the hexary Merkle Patricia Tree (MPT) to a Verkle tree (EIP-6800) is a precondition for stateless clients. But converting the whole state is hard: contracts with huge storage are being read and written while you convert them, and a long conversion slows full sync, reorgs and client release cycles. And the larger the state grows, the longer any conversion takes.

EIP-7612 offers a stopgap: stop the MPT from growing now, and convert the historical data later.

How it works

  • At FORK_TIME (never set) the MPT is frozen. A new, initially empty Verkle overlay tree is created.
  • Writes (accounts, storage slots, code chunks) go only to the overlay tree, using EIP-6800 key derivation. Account basic data (version, code size, nonce, balance) is packed into one leaf, with the code hash in a sibling leaf.
  • Reads check the overlay first and fall back to the frozen MPT if the key is not there.
  • From the fork block, the block header's stateRoot is the Verkle root, not the MPT root.
  • Once the freeze block is finalized, clients can delete the MPT's internal nodes to save disk space. They still need the leaf data until it is migrated.

Migrating the frozen MPT data into the Verkle tree is explicitly left to a later EIP (EIP-7748 describes one such conversion). No consensus-layer changes are needed.

Sample code

The modified state accessors, simplified from the spec's execution-spec diff:

def get_account_optional(state, address):
    acct = verkle_get_account(state._overlay_tree, get_tree_key_for_version(address))
    if acct is not None:
        return acct
    return trie_get(state._main_trie, address)          # frozen MPT fallback

def set_account(state, address, account):
    verkle_set_account(state._overlay_tree, get_tree_key_for_version(address), account)

def get_storage(state, address, slot):
    v = state._overlay_tree.get(get_tree_key_for_storage_slot(address, slot))
    if v is not None:
        return v
    trie = state._storage_tries.get(address)
    return U256(0) if trie is None else trie_get(trie, slot)

def set_storage(state, address, slot, value):
    state._overlay_tree.set(get_tree_key_for_storage_slot(address, slot), value)

Things to know

  • Status is Stagnant. FORK_TIME is TBD and the security section reads "needs discussion".
  • It depends on EIP-6800 (Verkle state, also Stagnant), EIP-4762 (stateless gas costs) and EIP-7545 (proof precompile, Stagnant). A unified binary tree (EIP-7864, Draft) has since been proposed as the target state structure.
  • The double lookup (overlay, then MPT) costs extra reads until the old state is fully migrated.
  • The reference implementation is a go-ethereum research branch, not a released client feature.

#verkle #state #stateless #migration #core

Details

Authors
Guillaume Ballet (@gballet), Ansgar Dietrichs (@adietrichs), Ignacio Hagopian (@jsign), Gottfried Herold (@GottfriedHerold), Jamie Lokier (@jlokier), Tanishq Jasoria (@tanishqjasoria), Parithosh Jayanthi (@parithosh), Gabriel Rocheleau (@gabrocheleau), Karim Taam (@matkt)
Status
Stagnant
Type
Standards Track / Core
Created
2024-01-25
Requires
Required by

Machine-readable: Markdown · JSON