Merkle Trees
Lesson, slides, and applied problem sets.
View SlidesLesson
Merkle Trees & Transaction Commitments
Why this module exists
Blocks commit to all transactions using a single hash. This enables light clients, efficient verification, and tamper evidence.
1) Merkle root
A Merkle tree reduces N transaction hashes to 1 root:
- Leaves are txids (double SHA-256 of tx bytes)
- Internal nodes hash
left || right - Odd counts duplicate the last hash
This creates a deterministic commitment for the block header.
2) Inclusion proofs
A proof is a path of sibling hashes from leaf to root. A verifier can recompute the root without seeing all transactions.
Properties:
- Proof size is
O(log N) - A single bit-flip in any tx changes the root
3) Security intuition
- Merkle roots prevent silent mutation of tx lists
- Proofs enable SPV-style verification
- Duplicating the last hash avoids ambiguous shapes
What you will build
- Merkle root computation
- Merkle proof generation
- Proof verification
Key takeaways
- Merkle roots bind content and order.
- Proofs are compact and verifiable.
- Consistent tree construction is a consensus rule.