Thousands of computers, none of them trusting each other, need to agree on one shared ledger — and instantly notice if a single character in a single past transaction gets changed. No central server is checking. What makes that even possible?
Every transaction gets hashed. Every pair of hashes gets combined into a new hash, one level up. Do that until only one hash is left — the root. Nothing here is fixed in place; if any transaction below changes, the specific hash sitting above it changes too, and so does everything above that.
This Part shares one concrete, deterministic hash function everywhere it's needed: toyHash(input),
which returns a number in , and toyHashPair(left, right), which combines two child hashes
into a parent's. Real hash functions (SHA-256) return 256-bit numbers instead of one in , but
behave the same way qualitatively — deterministic, and a one-character change in the input scrambles the
output unpredictably (the avalanche effect).
- Hash every transaction
Leaf 's hash is — one hash per transaction, independent of every other transaction.
- Combine pairs going up
Each parent combines two children: . With 4 transactions that gives 2 parents.
- Repeat until one hash remains — the root
The root is the parents' parent: . A block's entire set of transactions is now represented by exactly one number.
- A digital signature binds one signer to one message
A signature is a value only the holder of a private key can produce for a given message, and anyone who knows the corresponding public key can check. This chapter's toy version, , is symmetric rather than truly asymmetric — but it demonstrates the operational property that matters: change the key, or the message, and verification fails.
- — the -th transaction, as raw text.
- — that transaction's leaf hash, .
- — a parent hash, combining two children with .
- root — the single hash at the top, standing in for every transaction below it at once.
root = 577 — Alice's signature over the original message still verifies ✓
Tamper with transaction 0 and watch two things break at once: the Merkle root changes (anyone recomputing it from the transactions sees a mismatch instantly), and Alice's signature — computed over the original wording — no longer verifies against the tampered one. Two independent tripwires over the same data.
Four fixed transactions: alice pays bob 3, bob pays carol 1, carol pays dave 2, dave pays alice 1.
- Hash each leaf
- Combine into parents
- Combine into the root
.
- Now tamper with transaction 0
Change it to
alice pays bob 9:- Its leaf hash becomes instead of — a one-character change, an unrelated-looking output
- Parent 0 becomes instead of
- Parent 1 is untouched, still , since it doesn't depend on
- The root becomes — nowhere near the original , even though only one transaction out of four changed
Click any one transaction below to tamper with it (a character gets appended), and watch the root change from its original value of 577.
A Merkle tree compresses any number of transactions into one root hash, and changing any transaction anywhere in the tree changes the root — no central authority has to re-check every transaction by hand; everyone just compares one number. Digital signatures add the other half: proof that a specific party authorized a specific transaction in the first place. The next chapters build an entire consensus mechanism — proof-of-work — on top of exactly this hash function.