~$ crypto-under-the-hood

# The machinery behind the coins

~/notes / reading on-chain data

What a Merkle Tree Actually Does

The structure that lets you verify one transaction is in a block without downloading the block. It is simpler than the name suggests.

Ivan Kruse · · 2 min

A Merkle tree solves one problem: proving that a specific item belongs to a large set, without needing the whole set.

That sounds abstract until you consider what it enables, which is every light client and every mobile wallet that does not download the entire chain.

The construction

Take a list of transactions. Hash each one. Then take the hashes in pairs, concatenate each pair, and hash the result. Repeat with the resulting hashes, pairing and hashing, until one hash remains.

That final hash is the Merkle root, and it goes into the block header. It is a fingerprint of every transaction in the block, in order.

Why this is useful

Change any transaction and its hash changes. That changes the hash of the pair it belongs to, and so on up the tree, and the root changes. So the root commits to the entire contents of the block.

The clever part is the proof. To demonstrate that a particular transaction is in the block, you do not need the other transactions. You need the transaction, and one hash from each level of the tree, which lets you recompute the path up to the root.

For a block with a thousand transactions, that is about ten hashes rather than a thousand transactions. For a million, about twenty.

The proof size grows logarithmically with the set size, which is why this works at scale.

What it enables in practice

Light clients. A wallet that downloads only block headers can verify that a transaction affecting it is included, using a proof supplied by a full node. It does not need the chain and does not need to trust the node, because the proof is checkable against the header.

Efficient verification generally. Any time a system needs to prove membership in a large set, this structure applies. Airdrop eligibility lists, state proofs, and cross-chain messaging all use it.

Reserve attestations. The better exchange proof-of-reserves implementations build a Merkle tree of customer balances and publish the root. Each customer receives a proof that their balance was included in the total, without learning anyone else’s. This is what distinguishes a verifiable attestation from a press release.

Where the structure appears in a chain

In Bitcoin, the block header contains a Merkle root of the block’s transactions.

In Ethereum, there are several: a root for transactions, one for receipts, and one for the entire state of the network. The state root is why a node can prove any account balance at any block with a compact proof.

The limitation worth knowing

A Merkle proof shows that an item was in the committed set. It says nothing about whether the set itself is correct or complete.

For proof of reserves, this is precisely the gap. A customer can verify their balance was included in the total. They cannot verify that the total represents all liabilities, because an exchange could omit some customers entirely and every included customer’s proof would still check out.

Venues publishing this properly, including a platform with real on-chain withdrawals, let an individual customer check their own inclusion rather than taking the total on trust. This is why a reserve attestation needs both a Merkle-based inclusion proof and an auditor attesting to completeness. The first is cryptographic and the second is not, and the whole exercise depends on the weaker half.

# Corrections and technical nitpicks are welcome. Send them over. They get published with the fix.

cryptographymerkleverification

# related notes