Merkle Tree

 Definition

A Merkle tree (also called a hash tree) is a hierarchical data structure in which every leaf node contains the cryptographic hash of a data block, and every non-leaf node contains the hash of its child nodes concatenated together. This recursive hashing produces a single value at the top – the Merkle root – that acts as a tamper-evident fingerprint of the entire data set. If any piece of data at the bottom of the tree is changed, the modification cascades upward through every parent hash, producing a completely different root.

Merkle trees were invented by Ralph Merkle in 1979 as part of his Stanford PhD dissertation on digital signatures and public-key cryptography. He filed the patent on September 5, 1979, and it was issued as U.S. Patent No. 4,309,569 on January 5, 1982. The patent expired in 2002. Today, Merkle trees are used in virtually every blockchain protocol. Bitcoin uses a binary Merkle tree to organize transactions within each block. Ethereum uses a modified version called the Merkle Patricia Trie to store account state, transactions, and receipts. Beyond blockchain, Merkle trees are used in distributed file systems (IPFS), version control systems (Git), certificate transparency logs, and peer-to-peer file sharing protocols (BitTorrent). Origin & History

DateEvent
1979Ralph Merkle invents hash trees as part of his Stanford PhD work and files U.S. Patent application on September 5
1982U.S. Patent No. 4,309,569 (“Method of Providing Digital Signatures”) is granted to Merkle on January 5
1992Merkle trees are adopted in early peer-to-peer file verification systems to detect corrupted data blocks
2002Merkle’s patent expires, making the data structure freely available for any application
2008Satoshi Nakamoto uses Merkle trees in the Bitcoin design, placing the Merkle root in every block header
2015Ethereum launches with Merkle Patricia Tries, extending the concept to account state and smart contract storage
2020sVerkle Trees, zero-knowledge Merkle proofs, and sparse Merkle trees push the concept into next-generation scaling solutions
“A hash tree allows efficient and secure verification of the contents of a large data structure.”
Ralph Merkle

 How It Works

DATA BLOCKS: D1      D2      D3      D4

|       |       |       | v       v       v       v H(D1)  H(D2)  H(D3)  H(D4)     LEVEL 0: Hash each data block \     /         \     / v   v           v   v H(1+2)          H(3+4)        LEVEL 1: Hash pairs of hashes \             / v           v MERKLE ROOT                LEVEL 2: Final single hash H((1+2)+(3+4))

PROPERTIES:

  • Change D3 –> H(D3) changes

–> H(3+4) changes –> Merkle Root changes

  • Verification of D3 requires only: H(D4) + H(1+2)

(log2 of N hashes, not all N data blocks) “`

PropertyFlat Hash ListMerkle Tree
Detect any changeMust re-hash all itemsRoot hash changes automatically
Verify one itemMust download all itemsNeed only log2(N) sibling hashes
Proof size for 1M itemsAll 1M items~20 hashes (640 bytes)
Used bySimple checksumsBitcoin, Ethereum, Git, IPFS
StructureLinearBinary tree (hierarchical)

 In Simple Terms

  1. A Merkle tree is a way to organize data so you can tell if anything changed by looking at just one number – the root hash at the top of the tree.
  2. It works by hashing data in pairs from the bottom up. Each level of the tree combines two hashes into one, until a single hash remains.
  3. If someone tampers with any piece of data at the bottom, every hash above it changes, and the root no longer matches. The corruption is instantly detectable.
  4. Merkle trees are what make lightweight blockchain wallets possible. Your phone can verify a transaction by checking a short path of hashes rather than downloading the entire block.
  5. Nearly every blockchain uses Merkle trees. Bitcoin uses them for transactions, Ethereum uses them for state, and protocols like IPFS use them to verify file integrity across distributed networks.

 Real-World Examples

ScenarioImplementationOutcome
Bitcoin transaction verificationEvery block contains a Merkle tree of all transactions; the root is stored in the 80-byte block headerSPV wallets verify payments with just a few hundred bytes of proof data, rather than the full block
Git version controlGit uses Merkle trees (via SHA-1 hash objects) to represent the state of a repository at each commitAny change to any file produces a different tree hash; integrity of the entire project history is verifiable
IPFS content addressingFiles are split into chunks, each chunk is hashed, and a Merkle DAG links them togetherUsers can verify that downloaded file chunks are authentic without trusting the server that delivered them

 Advantages

AdvantageDescription
Efficient verificationVerifying one item out of N requires only log2(N) hashes, not the entire data set
Tamper detectionAny modification to any leaf changes the root hash, making unauthorized changes immediately visible
Bandwidth savingsProofs are compact (hundreds of bytes), enabling verification on low-bandwidth and resource-constrained devices
DeterministicThe same set of data always produces the same tree and root, ensuring all participants agree on the state

 Disadvantages & Risks

DisadvantageDescription
Tree construction costBuilding the full tree requires hashing every data block and every intermediate node, which takes O(N) time
No native proof of absenceProving that a piece of data is not in the tree requires extra structures (sorted Merkle trees, sparse Merkle trees)
Hash function dependencyThe tree’s security is only as strong as the underlying hash function; a broken hash algorithm compromises all proofs
Storage overheadStoring all intermediate hashes roughly doubles the storage requirement compared to storing only the raw data

Risk Management Tips:

  • Use well-established hash functions (SHA-256, Keccak-256) that have been extensively analyzed by the cryptographic community.
  • For applications requiring proof of absence, consider sorted Merkle trees or sparse Merkle trees that support non-membership proofs.
  • Keep implementations up to date with any hash function migration plans (e.g., post-quantum hash considerations).

FAQ

Who invented the Merkle tree?

Ralph Merkle, as part of his 1979 PhD dissertation at Stanford University on digital signatures and public-key cryptography. The patent was filed on September 5, 1979.

How does a Merkle tree differ from a regular hash?

A regular hash produces one fixed-size output from the entire input. A Merkle tree hashes data in a structured, hierarchical way so that individual pieces can be verified without re-processing the entire data set.

 Which blockchains use Merkle trees?

Virtually all of them. Bitcoin uses binary Merkle trees for transactions. Ethereum uses Merkle Patricia Tries for state, transactions, and receipts. Many other chains (Solana, Cardano, Polkadot) use variations for their own data structures.

What is a sparse Merkle tree?

A Merkle tree where most leaves are empty (default values). It allows efficient proofs of both inclusion and non-inclusion, making it useful for rollups and privacy protocols that need to prove an account does not exist.

 Are Merkle trees being replaced?

In some contexts, yes. Ethereum is planning to migrate to Verkle Trees, which use polynomial commitments instead of hashes to produce smaller proofs. But standard Merkle trees remain widely used and well understood.

Check your own numbers

The Free UEEx Calculator returns liquidation price, margin usage and fees for any position size

UEEx Weekly Digest

Market analysis and security alerts, read by 10,000 traders