EIPs Explained

EIP-3102 · Stagnant · Core · 2020-09-01

EIP-3102: Binary trie structure

Proposed replacing Ethereum's hexary Merkle Patricia Trie with a single binary trie, merging account and storage data, dropping RLP and hashing with blake2b, to shrink stateless proofs.

What problem does it solve?

Ethereum's state lives in a hexary Merkle Patricia Trie (16 children per node), with a separate storage trie per contract. That made sense when the bottleneck was database reads, but it produces large proofs: each level of a Merkle proof must include all sibling hashes, and with 16 children that is 15 hashes per level.

For a stateless Ethereum, where blocks ship with proofs (witnesses) of the state they touch, proof size is what matters. The spec's back-of-envelope table for 2²⁴ elements gives about 768 bytes per branch for a binary tree versus 2,880 bytes for a hexary one. Clients had also moved to flat key/value databases, so the hexary layout no longer bought much on disk.

How it works

  • One trie. Account and storage tries are merged into a single binary trie; keys are 32 to 64 bytes.
  • Account layout. For address a, take hash(a) minus its last two bits and append a 2-bit tag:
    • 00 balance, 01 nonce, 10 code, 11 storage root
    • storage slot k lives at … ++ 0b11 ++ hash(k)
    • with code merkleization (EIP-2926), code chunk c lives under the 10 branch.
  • Simpler encoding. No RLP, no hex-prefix leaf marker (a leaf is just a node with no children), and every node is hashed regardless of size.
  • Hash function. blake2b replaces keccak256 for speed, to offset the roughly 4× increase in node count.

Merkleization rule:

internal_hash = hash(left_child_hash || right_child_hash)
leaf_hash     = hash(hash(key) || hash(leaf_value))
# nodes with a prefix (extension) additionally commit to path length:
prefixed_hash = hash(u256(path_length - 1) || <hash above>)

Committing to the full path length from the root (not just the prefix) means deleting a leaf does not force rehashing its sibling.

Sample code

Computing the key for an account field and a storage slot (Python, using blake2b):

from hashlib import blake2b

def h(x: bytes) -> bytes:
    return blake2b(x, digest_size=32).digest()

def account_key(address: bytes, tag: int) -> int:
    """Return the 256-bit key: first 254 bits of h(address) ++ 2-bit tag."""
    stem = int.from_bytes(h(address), "big") >> 2
    return (stem << 2) | tag

BALANCE, NONCE, CODE, STORAGE = 0b00, 0b01, 0b10, 0b11

def storage_key(address: bytes, slot: int) -> bytes:
    prefix = account_key(address, STORAGE).to_bytes(32, "big")
    return prefix + h(slot.to_bytes(32, "big"))   # 64-byte key

Things to know

  • Status: Stagnant. It was not adopted, and a switch would require a hard fork plus a full state conversion. The spec points to EIP-2584 for a transition approach.
  • Later stateless-state designs took a different shape: EIP-6800 proposed a unified verkle tree, and EIP-7864 returns to a unified binary tree with a different key layout.
  • The rationale for blake2b over BLAKE3 was the lack of an official Go BLAKE3 release at the time.
  • The spec mentions a 32-byte code chunk size from an older version of EIP-2926; that EIP now uses 31 bytes.

#state #trie #statelessness #merkle #core

Details

Authors
Guillaume Ballet (@gballet), Vitalik Buterin (@vbuterin)
Status
Stagnant
Type
Standards Track / Core
Created
2020-09-01

Machine-readable: Markdown · JSON