Merkle tree

On this page 7

A Merkle tree is a binary tree of cryptographic hashes in which every leaf holds the hash of a data item and every internal node holds the hash of its two children, so that a single Merkle root at the top commits to the entire data set. In blockchain fundamentals it is the structure that binds all transactions of a block to the block header, which allows any participant to verify that one transaction is included without downloading the whole block.

The idea dates back to Ralph Merkle’s work on digital signatures in the late 1970s, long before Crypto & blockchain systems existed. Bitcoin adopted it to keep block headers small, and nearly every later public blockchain uses a Merkle tree or one of its variants to commit to transactions, receipts or account state.

How a Merkle tree is built

A Merkle tree is built bottom-up by repeated pairwise hashing. Each transaction is first hashed to produce a leaf. Adjacent leaves are then concatenated and hashed again to form their parent, and the process repeats level by level until only one hash remains, the Merkle root.

In Bitcoin the hash function is double SHA-256, and when a level has an odd number of nodes the last node is duplicated so that it can be paired. Because each parent depends on both children, changing even one bit in any transaction changes its leaf, every ancestor above it and finally the root. The root therefore acts as a compact fingerprint of the full transaction list and its order.

The table describes the elements of the structure and their role.

ElementContentRole
Leaf nodeHash of one transactionRepresents a single data item
Internal nodeHash of two child hashesLinks lower levels together
Merkle rootSingle top-level hashCommits to the whole set in the header
Sibling hashNeighbor at each levelNeeded to recompute a path upward
Merkle pathOrdered list of sibling hashesForms the inclusion proof
Elements of a Merkle tree

Merkle proofs and light node verification

A Merkle proof, also called an inclusion proof, shows that a specific transaction belongs to a block by supplying only the sibling hashes along its path to the root. The verifier hashes the transaction, combines it step by step with the provided siblings and checks whether the result equals the Merkle root stored in the block header.

The efficiency is the point. For a block of n transactions, a proof contains only about log2(n) hashes. A block with roughly 4,000 transactions needs about 12 sibling hashes, which is under 400 bytes with 32-byte hashes, compared with the full block of one to several megabytes. This is what makes Simplified Payment Verification (SPV), described in the Bitcoin white paper, practical for wallets and light nodes.

The following table shows how proof size grows with the number of transactions.

Transactions in blockTree depthProof size
164 levels128 bytes
1,02410 levels320 bytes
4,09612 levels384 bytes
1,048,57620 levels640 bytes
Proof size for 32-byte hashes

A light node still has to trust that the header belongs to the valid chain with the most work, so it downloads and checks all block headers. The Merkle proof only answers inclusion; it does not prove that the transaction is valid or that the block will not be reorganized away.

Variants used by different blockchains

Different blockchains adapt the basic structure to what they need to commit to. Bitcoin commits only to an ordered transaction list, whereas account-based chains also need to commit to a large and constantly changing global state, which requires a tree that supports efficient updates and key lookups.

VariantTypical useKey property
Binary Merkle treeBitcoin transaction commitmentSimple, compact inclusion proofs
Merkle Patricia trieEthereum state, transactions, receiptsKey-value lookups with path compression
Sparse Merkle treeState commitments and non-membershipFixed positions for every possible key
Merkle mountain rangeAppend-only historiesCheap appends without rebuilding
Verkle treeProposed Ethereum state upgradeMuch smaller proofs via vector commitments
Merkle tree variants in blockchain systems

Bitcoin’s SegWit upgrade added a second Merkle commitment for witness data, placed inside the coinbase transaction, so that signatures are committed without changing how the original transaction identifiers are computed.

A Merkle tree is one layer in a chain of commitments. Each block header contains the Merkle root of its transactions and the hash of the previous header, so the header chain secures the roots, and the roots secure every transaction. The comparison below separates the Merkle tree from neighboring ideas that are often confused with it.

ConceptWhat it securesRelationship
Merkle treeSet of items inside one blockProduces the root stored in the header
Hash chain of blocksOrder and history of blocksLinks headers, each holding a root
Block headerMetadata and commitmentsCarries the Merkle root and previous hash
UTXO setCurrently spendable outputsNot committed by a Merkle root in Bitcoin
Full node validationCorrectness of every ruleGoes beyond inclusion proofs
Merkle tree compared with related concepts

The distinction between inclusion and validity is the most important practical lesson: a light node relying on Merkle proofs inherits weaker security guarantees than a full node that executes every transaction.

Limitations and known pitfalls

Merkle trees are robust, but their security depends on careful implementation details. Several historical bugs came not from the hash function but from how trees were constructed or interpreted.

  • Duplicate-leaf ambiguity: Bitcoin’s rule of duplicating the last odd node allows two different transaction lists to share one root, which was assigned the identifier CVE-2012-2459 and is mitigated by extra validation checks.
  • Leaf and node confusion: without domain separation (different prefixes for leaves and internal nodes), an internal node can sometimes be presented as a leaf; Certificate Transparency in RFC 6962 adds such prefixes for this reason.
  • No non-membership proof in a plain binary tree: proving that a transaction is absent requires sorted or sparse variants.
  • Data availability: a root proves commitment, not that the underlying data was published, which is a central concern for rollups and scaling designs.

Hash collisions are not a practical risk with SHA-256 or Keccak-256 today, so most real failures come from protocol design and parsing errors rather than broken cryptography.

In everyday language

Imagine summarizing a thick binder of receipts with one short code. Pairs of receipts are summarized together, then pairs of summaries, until a single code stands for the whole binder. If anyone changes a single receipt, that final code changes too.

This lets someone check one receipt without reading the entire binder. They only need the few summaries along the way up, which is why phones and small wallets can confirm a payment quickly without storing the entire blockchain.

Seen in the real world

A mobile Bitcoin wallet receives a payment from a customer at a small online shop. The wallet does not store the full blockchain, which exceeds several hundred gigabytes; it keeps only the chain of 80-byte block headers, which takes well under 100 megabytes.

When the transaction is mined into a block containing about 3,000 transactions, the wallet asks a connected server for a Merkle proof. The server returns 12 sibling hashes, under 400 bytes of data. The wallet hashes the transaction, combines it with the siblings in order and obtains a value matching the Merkle root in the header it already holds.

The shop owner sees the payment as confirmed within seconds of the block arriving, and after several further blocks are added on top, treats it as settled, all without running a full node.