EIP-2584 · Stagnant · Core · 2020-04-03
EIP-2584: Trie format transition with overlay trees
A stagnant plan to switch Ethereum's state from a hexary to a binary trie without halting the chain, by writing new state to an overlay trie while the old one is converted in the background.
What problem does it solve?
Ethereum stores its state in a hexary Merkle Patricia Trie: each branch node has 16 children. A binary trie (2 children per branch) gives much smaller Merkle proofs, which matters for stateless clients and light clients.
The hard part is the migration. The full state is far too large to convert within one block time, so you cannot just flip a switch at a fork block. Earlier ideas were "stop the world" (halt the chain during conversion) or "copy on write" (convert branches only when touched, which may never finish). EIP-2584 proposes a method that keeps the chain running and still completes in predictable time.
How it works
Three phases (the abstract calls it four, but the text describes three):
- Phase 1 — overlay. From block
h₁, all state writes go to a new, initially empty binary overlay trie, whose root is a new block-header field. The old hexary base trie is frozen; reads check the overlay first, then fall back to the base. Deleted accounts are marked in the overlay with the empty hash. Meanwhile every node converts the frozen hexary trie to binary in the background. - Phase 2 — merge. At block
h₂, the state root switches to the converted binary base root. The overlay becomes read/delete only; writes go to the base trie. Before each block, the firstNaccounts (in key order) are moved out of the overlay into the base trie. - Phase 3 — done. Once the overlay is empty, its root field is removed from the header.
h₂ must be far enough after h₁ for miners to finish converting; the author reports a prototype converting in roughly 30 minutes on a fast machine.
Sample code
Pseudocode for state access during phase 1:
EMPTY = keccak(b"")
def read_account(addr):
v = overlay.get(addr)
if v == EMPTY: # deleted during the transition
return None
if v is not None:
return v
return base_hex.get(addr) # frozen hexary trie
def write_account(addr, value):
overlay.put(addr, value) # base trie is never touched in phase 1
def delete_account(addr):
overlay.put(addr, EMPTY)
And the per-block merge step in phase 2:
for addr, v in overlay.first_n_sorted(N):
if v == EMPTY:
base_bin.delete(addr)
else:
base_bin.put(addr, v)
overlay.delete(addr)
Things to know
- Status is Stagnant. It is a hard fork that changes block format and hashes, and was never scheduled.
- Security notes in the spec: an attacker could bloat the overlay to prolong phase 2 (possibly mitigated by pricier
SSTOREin phase 1), and ifh₂comes too soon, miners might not compute the converted root in time. - The overlay idea lived on in later state-migration work: EIP-7612 (overlay transition to Verkle) and EIP-7748 (state conversion). The target tree has since shifted from Verkle (EIP-6800) to a unified binary tree (EIP-7864), both still drafts or stagnant.