定义
A Merkle tree (also called a hash tree) is a hierarchical data structure in which every leaf node contains the 密码哈希 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
| 日期 | 创建 |
| 1979 | Ralph Merkle invents hash trees as part of his Stanford PhD work and files U.S. Patent application on September 5 |
| 1982 | U.S. Patent No. 4,309,569 (“Method of Providing Digital Signatures”) is granted to Merkle on January 5 |
| 1992 | Merkle trees are adopted in early peer-to-peer file verification systems to detect corrupted data blocks |
| 2002 | Merkle’s patent expires, making the data structure freely available for any application |
| 2008 | Satoshi Nakamoto uses Merkle trees in the Bitcoin design, placing the Merkle root in every block header |
| 2015 | Ethereum launches with Merkle Patricia Tries, extending the concept to account state and smart contract storage |
| 2020s | Verkle 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.”
运作模式
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))
特性:
- 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) “`
| 特性 | Flat Hash List | 默克尔树 |
| Detect any change | Must re-hash all items | Root hash changes automatically |
| Verify one item | Must download all items | Need only log2(N) sibling hashes |
| Proof size for 1M items | All 1M items | ~20 hashes (640 bytes) |
| 使用者 | Simple checksums | Bitcoin, Ethereum, Git, IPFS |
| 结构 | 线性推力器 | Binary tree (hierarchical) |
简单来说
- 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.
- 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.
- 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.
- 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.
- 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.
实际例子
| EventXtra XNUMX大解决方案 | 技术实施 | 成果 |
| Bitcoin transaction verification | Every block contains a Merkle tree of all transactions; the root is stored in the 80-byte block header | SPV wallets verify payments with just a few hundred bytes of proof data, rather than the full block |
| Git 版本控制 | Git uses Merkle trees (via SHA-1 hash objects) to represent the state of a repository at each commit | Any change to any file produces a different tree hash; integrity of the entire project history is verifiable |
| IPFS content addressing | Files are split into chunks, each chunk is hashed, and a Merkle DAG links them together | Users can verify that downloaded file chunks are authentic without trusting the server that delivered them |
优势
| 企业优势 | 描述 |
| 高效验证 | Verifying one item out of N requires only log2(N) hashes, not the entire data set |
| 篡改检测 | Any modification to any leaf changes the root hash, making unauthorized changes immediately visible |
| 节省带宽 | Proofs are compact (hundreds of bytes), enabling verification on low-bandwidth and resource-constrained devices |
| 确定性 | The same set of data always produces the same tree and root, ensuring all participants agree on the state |
缺点与风险
| 坏处 | 描述 |
| Tree construction cost | Building the full tree requires hashing every data block and every intermediate node, which takes O(N) time |
| No native proof of absence | Proving that a piece of data is not in the tree requires extra structures (sorted Merkle trees, sparse Merkle trees) |
| Hash function dependency | The tree’s security is only as strong as the underlying hash function; a broken hash algorithm compromises all proofs |
| 存储开销 | Storing all intermediate hashes roughly doubles the storage requirement compared to storing only the raw data |
风险管理提示:
- Use well-established 哈希函数 (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).
常见问题解答
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.







