EIPs Explained

EIP-7748 · Draft · Core · 2024-07-23

EIP-7748: State conversion to Verkle Tree

Draft plan to migrate Ethereum's entire state from the Merkle Patricia Tree to a Verkle tree a fixed number of items per block, so the overlay tree can eventually be removed.

What problem does it solve?

Moving Ethereum to a Verkle tree (for smaller witnesses and stateless clients) means every account and storage slot must end up in the new tree. EIP-7612 defines an overlay tree: new writes go to the Verkle tree, reads fall back to the old Merkle Patricia Tree (MPT). But if migration only happens when transactions touch data, much of the state would sit in the MPT forever, and clients would have to keep both trees indefinitely.

EIP-7748 actively walks through the whole MPT and copies everything over in bounded steps, so the migration finishes in a predictable time.

How it works

  • From CONVERSION_START_TIMESTAMP, every block runs a conversion step before executing its transactions.
  • Each step converts up to CONVERSION_STRIDE conversion units. A unit is either one storage slot, or one account's basic data (nonce, balance, code hash, etc.) plus its code.
  • The client walks accounts in MPT key order. For each account it first converts its storage slots one by one, then its code (chunked and inserted in one go) and account data, then moves to the next account.
  • The client state tracks a cursor (current account and phase) so the walk resumes in the next block.
  • Storage values are only written if the Verkle tree does not already have them, because a transaction may have written a newer value there in an earlier block.
  • Accounts with nonce 0 and no code skip storage conversion; this covers the 28 inaccessible accounts described in EIP-7610.
  • When the walk passes the last account, the conversion is finished and the overlay can be dropped.

Sample code

Simplified per-block step (pseudocode adapted from the spec):

def state_convert(state, stride):
    n = 0
    while n < stride and not state.conversion_finished:
        acct = state.conversion_cursor()
        if acct.nonce == 0 and not acct.code:
            acct.phase = ACCOUNT_DATA            # skip unreachable storage
        if acct.phase == STORAGE:
            slot, value, next_key = storage_trie(acct).next_at(acct.next_key)
            if slot is not None:
                write_storage_if_empty(acct.address, slot, value)
                n += 1
            if next_key is None:
                acct.phase = ACCOUNT_DATA
            else:
                acct.next_key = next_key
        else:
            write_code_chunks(acct.address)       # whole code in one go
            write_account_data(acct.address)       # nonce, balance, code hash...
            n += 1
            state.advance_to_next_account()

Things to know

  • Status is Draft. Both CONVERSION_START_TIMESTAMP and CONVERSION_STRIDE are still TBD, and test cases are not yet in the spec.
  • It requires EIP-7612, which is Stagnant, as is the Verkle state EIP EIP-6800. Recent stateless work has been exploring a binary tree instead (EIP-7864); a similar conversion would be needed there.
  • Because code is converted in one step, a single large contract can push a block over the stride by roughly 24 KB / 31 ≈ 793 units. The authors accepted this to keep the algorithm simple.
  • Clients must be able to map hashed MPT keys back to the original addresses and slots (a flat database or a preimage dump) to write Verkle keys.

#core #state #verkle #stateless #migration

Details

Authors
Guillaume Ballet (@gballet), Ignacio Hagopian (@jsign), Gajinder Singh (@g11tech), Ansgar Dietrichs (@adietrichs), Gottfried Herold (@GottfriedHerold), Jamie Lokier (@jlokier), Tanishq Jasoria (@tanishqjasoria), Parithosh Jayanthi (@parithosh), Gabriel Rocheleau (@gabrocheleau), Karim Taam (@matkt)
Status
Draft
Type
Standards Track / Core
Created
2024-07-23
Requires

Machine-readable: Markdown · JSON