In this track: Trees, roots and proofs
advanced · 4 MIN READ

Hash a Merkle leaf

The leaf encoding is part of the tree definition.

LET’S PICTURE IT

A filing system must decide exactly how each record is written before fingerprinting it.

SEE IT FOR YOURSELF
Build a root and follow one membership proofStep 1 / 4
Build a root and follow one membership proofA0x03783f…b760B0x1f675b…9111C0x017e66…8f72D0x6c3fd3…79f2A0x03783f…b760B0x1f675b…9111C0x017e66…8f72D0x6c3fd3…79f2hash(A,B)0x69de75…24a0hash(C,D)0xe62e1d…b5a4A0x03783f…b760B0x1f675b…9111C0x017e66…8f72D0x6c3fd3…79f2hash(A,B)0x69de75…24a0hash(C,D)0xe62e1d…b5a4ROOT0x4e2b32…5956A0x03783f…b760B0x1f675b…9111C0x017e66…8f72D0x6c3fd3…79f2hash(A,B)0x69de75…24a0hash(C,D)0xe62e1d…b5a4ROOT0x4e2b32…5956

This example hashes UTF-8 A, B, C and D. The displayed hashes are abbreviated, and the tree uses the playground’s sorted-pair convention.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Choose the original value

The playground takes a text item such as A. It hashes that item’s UTF-8 bytes, not its displayed hex characters or an ABI tuple.

Compute the leaf digest

Keccak-256 maps those bytes to a fixed thirty-two-byte value. The leaf does not expose the original text as a reversible encoding.

Document preprocessing

Trimming, case folding or normalization can change the bytes. The playground trims each input line; a production protocol must specify its own exact preprocessing rules.

Keep other conventions separate

An allowlist may hash a typed address-and-amount record or use double hashing. Matching the hash algorithm is insufficient if the original leaf encoding differs.

Follow the proof model

Convention: UTF-8 leaves, Keccak-256, lexicographically sorted hash pairs
leaf A: 0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760
sibling B: 0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111
parent AB: 0x69de756fea16daddbbdccf85c849315f51c0b50d111e3d2063cab451803324a0
sibling parent CD: 0xe62e1dfc08d58fd144947903447473a090c958fe34e2425d578237fcdf1ab5a4
root: 0x4e2b32e9c7b10ee15f38192ed65b95656a84e32531157b9384ef0d3cabe95956

Binary examples use the stated local playground convention. They are not Ethereum account or storage trie proofs.

TURN UNDERSTANDING INTO PRACTICEOpen the Merkle trees →
QUICK CHECK · NO PRESSURE

Is the leaf encoding part of the tree convention?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.