Loading Crypto System...
Initializing Python environment in browser
Back
Hashing & Merkle Trees Lab

Hashing and Merkle Trees

Understanding Cryptographic Hashing and Merkle Tree Verification

1
2
3
4
5
Click "Next Step" to begin

Step 1: Why This Matters

Real Problem:

Imagine you have a Bitcoin wallet on your phone. Your phone can't store the entire blockchain (it's huge!), but you still need to verify that transactions are real. How do you do that?

Answer: Merkle Trees! Your phone only needs the block header (which contains the Merkle root) and a small "proof path" to verify any transaction. This is called "Simplified Payment Verification" (SPV) - and it's what makes light wallets possible!

What You'll Learn:

How hashes work: See how one tiny change creates a completely different hash
How Merkle trees organize data: Build a tree step-by-step and see how it commits to everything
How to verify without downloading everything: Use a "proof path" to prove a transaction exists
Why details matter: See how changing the order breaks everything!

Step 2: Avalanche Effect

A single-bit change flips ~50% of output bits → tamper detection. Try changing one character!

SHA-256: Converts text → bytes → 256-bit (64 hex) digest (always fixed size)
One character change (l→m) = completely different hash. Security by unpredictability!

Step 3: Building a Merkle Tree

🌿 Leaves: Your data (transactions) → hashed. 🌳 Branches: Two children hashed together. 👑 Root: One hash representing everything. Change any leaf → root changes!
Each line represents one transaction. In Bitcoin, these would be actual transaction data.

Step 4: Inclusion Proof

Light wallet scenario: You only have the block header (root). Someone claims "tx2" is in the block. Can you verify without all transactions? YES - with a proof path (leaf + siblings)!
The proof will show just the sibling hashes needed - not all transactions!

Step 5: Why Order Matters

Critical: H(left || right) ≠ H(right || left)! Everyone must use the same order (Bitcoin uses H(left || right)). Different order = different root = broken verification.

Correct: H(left || right)

Wrong: H(right || left)