Skip to content

Merkle Tree

Paper: A Digital Signature Based on a Conventional Encryption Function

Merkle Tree

A Merkle tree is a binary tree where each leaf node represents a hash of some data, and each intermediate node is a hash of its two child nodes. The topmost node is known as the Merkle root.

Merkle trees significantly enhance the efficiency of data processing and verification.

  • The leaf nodes contain the hashes of the data blocks.
  • Non-leaf nodes are created by hashing the concatenation of their child nodes.
  • The topmost node is called the root hash, representing the entire dataset.
  • Any change in the data will result in a different root hash, ensuring data integrity.
  • This structure allows for efficient proof of data inclusion and exclusion.

Merkle Proof

Each block in a blockchain typically contains a Merkle tree root hash that summarizes all transactions included within that block.

Merkle trees allow users to verify transactions without needing to download the entire blockchain, which is particularly beneficial for lightweight clients.

By leveraging this structure, blockchains can maintain high levels of security while optimizing data storage and retrieval.

  • Each block's Merkle root is included in the block header.
  • Users can verify specific transactions using Merkle proofs without accessing the full block.
  • This minimizes the amount of data that needs to be shared and stored.
  • It enhances the scalability of blockchain networks by allowing for faster data verification.
  • Merkle trees contribute to the overall security and trustworthiness of the blockchain.

Hash Algorithm

Merkle Tree 本身是一种结构性设计,而它使用的哈希算法可以根据应用场景自由选择。

应用场景使用的哈希算法
比特币 Merkle TreeSHA-256(双重 SHA-256)
以太坊 Merkle Patricia TreeKeccak-256(接近 SHA-3)
Git(版本控制系统)SHA-1(已转向 SHA-256)
IPFS(内容寻址)多种可选(SHA-256、BLAKE2、SHA3 等)
现代通用实现SHA-256 / SHA-3 / BLAKE3 等

References