courtesy of Claude A Merkle tree (or hash tree) is a binary tree where:
- Leaf nodes contain hashes of individual data items (transactions in Bitcoin)
- Non-leaf nodes contain hashes of their child nodes combined
- The root node (Merkle root) provides a single hash representing all data below it
The construction process is:
- Hash each transaction individually
- Pair adjacent transaction hashes and hash them together
- Continue pairing and hashing until you reach a single hash (the Merkle root)
How Merkle Trees Are Used in Bitcoin Blocks
In Bitcoin:
- Each block header (80 bytes) contains:
- The Merkle root of all transactions in the block
- Previous block hash
- Nonce, timestamp, etc.
- Benefits this provides:
- Efficient Verification: Light clients can verify if a transaction is included in a block without downloading all transactions
- Space Efficiency: Only need to store the 80-byte block header instead of full blocks
- Tamper Evidence: Any change to any transaction changes the Merkle root
- Merkle proofs:
- Allow proving a transaction exists in a block by providing ~log₂(n) hashes
- Enable SPV (Simplified Payment Verification) clients that don’t store the full blockchain