MASTERING-BITCOIN ยท Interactive Practice | Unit 12 ยท Video 3
| Concept | Formula / Rule | Description |
|---|---|---|
| Parent hash | Concatenate two 32-byte children, double-hash | |
| Output size | Always 32 bytes | Regardless of how many transactions in the block |
| Proof size | hashes | Sibling hashes needed for inclusion proof |
| Odd-count rule | Duplicate last hash, pair with itself | Keeps tree balanced (source of CVE-2012-2459) |
| SPV verification | Header (80 B) + Merkle path | Phones verify without full blocks |
Adjust the slider to change the number of transactions in the block. Notice how the tree height grows logarithmically โ doubling the number of transactions only adds one level. No matter how many transactions, the root is always 32 bytes.
โ interactive visualization โ coming to this page format soon
Notice: Each time you double the number of transactions, only one new level appears. Dashed red circles mark hashes that had to be duplicated to maintain pairs (the odd-count rule). The gold root at the top is always exactly 32 bytes โ whether N = 2 or N = 16,000.
An inclusion proof requires only the sibling hashes along the path from a leaf to the root โ that's hashes of 32 bytes each. Use the slider to see how proof size grows with block size.
โ interactive visualization โ coming to this page format soon
Reflect: Try moving the slider from N = 16 to N = 16,000. The block grows 1,000ร larger, but the proof grows from 4 hashes to only 14 hashes โ less than 4ร growth. This is the magic of logarithmic scaling that makes SPV wallets practical on mobile phones.
Pick a transaction (A through P) in a 16-transaction block. The visualization highlights the path from your leaf to the root (green) and the sibling hashes (orange) you need to include in the proof.
โ interactive visualization โ coming to this page format soon
Notice: No matter which of the 16 transactions you select, the proof always contains exactly 4 sibling hashes (because ). The verifier recomputes each green path node by hashing it with its orange sibling, and finally checks the recomputed root against the one in the block header.
Question 1
A Bitcoin block contains 1,024 transactions. How many sibling hashes are required to prove that any single transaction is included in the block?
โ Correct! logโ(1024) = 10, so the proof needs 10 sibling hashes (320 bytes).
โ Not quite. The proof size is logarithmic, not linear or fixed. Compute logโ(N).
Solution:
The number of sibling hashes equals the tree depth, which is .
So a verifier needs 10 sibling hashes (10 ร 32 = 320 bytes) to reconstruct the path from any leaf to the root. This is the whole point of Merkle trees: proof size grows logarithmically, not linearly.
Question 2
A Bitcoin block has 5 transactions at the bottom level. According to Bitcoin's Merkle tree construction rules, what happens at the pairing step?
โ Correct! Bitcoin duplicates the lone hash: Hโ pairs with Hโ to form a new parent.
โ Not quite. Bitcoin doesn't reject odd counts or pad with zeros โ it duplicates.
Solution:
Bitcoin's rule for odd-count levels: duplicate the last hash and pair it with itself.
So with hashes , the pairing becomes:
This keeps the tree balanced (every internal node has two children) and lets the same hashing rule apply at every level. Unfortunately, this exact rule is what enabled CVE-2012-2459: the duplication creates collisions between blocks with different transaction lists but identical roots.
Question 3
True or False: If even one bit of a single transaction in a block changes, the Merkle root of that block will also change.
โ Correct! A single bit flip propagates up the path and changes the root.
โ Not quite. That's the whole purpose of a cryptographic commitment โ any change is detectable.
Solution:
True. This is the whole point of cryptographic commitments.
This is why a 32-byte root can "commit to" every byte of a 4 MB block: any tampering, anywhere, is detectable at the root.
Question 4
An SPV (Simplified Payment Verification) wallet receives a merkleblock
message containing the 80-byte block header plus a Merkle path for a
transaction it cares about. What does the wallet verify with this data?
โ Correct! Two-part verification: Merkle path proves membership; header chain proves the block belongs.
โ Not quite. SPV wallets don't validate signatures or other transactions โ they verify membership and chain inclusion.
Solution:
The SPV wallet performs two distinct checks:
Transaction is in the block: Use the Merkle path (sibling hashes) to recompute the root from the transaction's hash. Compare with the root stored in the 80-byte block header.
Block is in the blockchain: Verify the chain of block headers (each header references the previous one's hash, and proof-of-work is checked on each).
Together these give strong assurance without downloading the full ~4 MB block. The wallet does not verify other transactions' signatures or contents โ it trusts the network's miners to have done that work via proof-of-work.
Total bandwidth per relevant block: typically under 1 KB, compared to 4 MB for the full block.
Solved: 0 / 4