EIP-7643 · Stagnant · Core · 2024-02-29
EIP-7643: History accumulator for pre-PoS data
Proposes one fixed SSZ root that commits to every proof-of-work block hash and total difficulty, so pre-Merge history can be verified, and proven block by block, without re-executing the old chain.
What problem does it solve?
Ethereum's proof-of-work history (everything before the Merge) is frozen: it will never change. Yet to trust a downloaded copy of it, a client today must either re-execute every block or walk the header chain backwards from a trusted point, hash by hash. Proving that one specific old block is canonical also requires that long header chain.
As clients move toward not storing old history themselves (EIP-4444) and fetching it from other sources, a compact, fixed commitment to the pre-Merge chain makes that data easy to check.
How it works
The EIP defines an SSZ structure, the historical hashes accumulator:
- Blocks are grouped into epochs of
8192blocks. - For each block, a
HeaderRecordstores itsblock_hashand the chain'stotal_difficultyat that block. - Each full epoch's list of records is reduced to a single
bytes32hash tree root and appended tohistorical_epochs(up to 2048 entries).
The hash tree root of this accumulator over all blocks before block 15537394 (the first proof-of-stake block) is fixed by the spec as:
0xec8e040fd6c557b41ca8ddd38f7e9d58a9281918dc92bdb72342a38fb085e701
That root can be hard-coded into clients. Two uses follow:
- Bulk verification. Download the pre-Merge headers, hash them, build the accumulator and compare its root with the constant. No execution needed.
- Short proofs. Any single pre-Merge block can be proven with an
O(log n)Merkle proof against the root, instead of a chain of headers.
Total difficulty is included so clients can still answer JSON-RPC calls that report it and can verify the terminal total difficulty of the last PoW block.
Sample code
The SSZ definitions from the spec, plus a sketch of the verification loop:
EPOCH_SIZE = 8192 # blocks per epoch
MAX_HISTORICAL_EPOCHS = 2048
HeaderRecord = Container[block_hash: bytes32, total_difficulty: uint256]
EpochRecord = List[HeaderRecord, max_length=EPOCH_SIZE]
HistoricalHashesAccumulator = Container[
historical_epochs: List[bytes32, max_length=MAX_HISTORICAL_EPOCHS],
current_epoch: EpochRecord,
]
PRE_POS_ROOT = "0xec8e040fd6c557b41ca8ddd38f7e9d58a9281918dc92bdb72342a38fb085e701"
def verify_pre_merge(headers):
acc, td = HistoricalHashesAccumulator(), 0
for h in headers: # blocks 0 .. 15537393, in order
td += h.difficulty
if len(acc.current_epoch) == EPOCH_SIZE:
acc.historical_epochs.append(hash_tree_root(acc.current_epoch))
acc.current_epoch = EpochRecord()
acc.current_epoch.append(HeaderRecord(keccak(rlp(h)), td))
return hash_tree_root(acc) == PRE_POS_ROOT
Things to know
- Status is Stagnant. It was not scheduled for a network upgrade. The accumulator itself is not a consensus change: it commits to data that already exists.
- The spec's test cases list the expected root of each early epoch, which helps implementers check their accumulator.
- It fits the history-expiry work: EIP-4444 (clients stop serving old history), EIP-7639 and EIP-7642 (networking changes for that). Recent block hashes are served in state by EIP-2935.
- It covers proof-of-work blocks only. Post-Merge blocks are already committed to by the beacon chain's own historical roots.