The last lesson locked in one value, and then one polynomial, with a commitment. Now the problem gets bigger: how do you lock in a whole list — millions of names, accounts, or transactions — and later prove that one item is on it, without handing over the list? The tool for that is the Merkle tree. By the end of this lesson the goal is to see how it’s built, why nobody can quietly edit it, how a handful of hashes can prove one item belongs, and how a ZK proof hides which item you’re proving while still stopping you from using it twice.
Building a Merkle tree
A fingerprint for a whole pile sounds easy: just hash everything together. But then proving one document is in the pile would mean handing over the entire pile. A Merkle tree builds the fingerprint in layers instead, a bit like a tournament bracket where a hash moves up each round.
Hash each leaf on its own: , and so on. Pair them up and hash the pair: — write and next to each other, then hash the result. Repeat one level up: .
The root commits to everything below it, and everyone only has to remember that one short value, not the whole list.
Nobody edits it quietly
This is the property that makes the root worth trusting: no leaf can be edited without the root changing, and there’s no way to patch the root to match without finding a hash collision — which the last lesson but one already showed is infeasible.
Say someone swaps one leaf for something else. That leaf’s hash comes out different, which changes the pair it belongs to, which changes the root. The left half of the tree — everything not on that leaf’s path — never has to be touched, and never changes.
Proving membership
Here’s the harder question: how does a verifier, holding only the published root, get convinced that one specific leaf is really in the tree — without being handed the whole tree? The trick is that the verifier doesn’t need most of it. They only need the hashes sitting right next to the leaf’s path, because those are exactly what’s missing to rebuild the root.
To prove belongs, send the three sibling hashes on its path — , , — each marked with which side it sits on, since . The verifier recomputes , then , then , then , and checks .
One caveat worth flagging: this proof on its own is not private. The verifier sees the leaf itself and exactly where it sits in the tree. That’s fine for public data, but it isn’t zero-knowledge — the last section of this lesson fixes that.
Proof size grows slowly
A Merkle proof needs one sibling hash per level of the tree, and each level is one halving of the pile — so the proof length is . That grows remarkably slowly.
Eight items need three hashes. Grow the tree to over four billion leaves — thirty-two doublings — and the proof grows by exactly thirty-two hashes. At roughly 32 bytes per hash, that’s about one kilobyte to prove one name out of four billion.
Vector commitments
A Merkle tree commits to an ordered list with one short value, and lets you open any single position — but it’s one way to do that job, not the only way. The general idea has a name: a vector commitment.
A Merkle tree needs nothing but a hash function, and no trusted setup, at the cost of a -sized proof. KZG, from the previous topic, compresses the proof down to a single point, at the cost of a trusted setup and the pairings built two lessons back. To use KZG on a list: turn the vector into a polynomial through Lagrange interpolation, then commit to that polynomial with KZG. Opening position then means proving the polynomial’s value at .
Nullifiers
Here’s the problem a private membership proof creates: it lets any member prove they belong without revealing which member it was — but nothing stops that same member from proving it again, say to vote twice. The fix is a second value, derived from the member’s secret, that comes out the same every time for the same member and means nothing to anyone else: a nullifier.
Each member’s leaf is for two secrets and . Spending publishes . Because a hash is one-way, doesn’t reveal which leaf it came from — but the same always produces the same , so a second spend publishes the same again, and gets rejected against the used list.
This is a simplified version of the idea — real protocols like Tornado Cash and Semaphore use different exact formulas, but they all follow this same pattern.
Why this matters for ZK
The membership proof from earlier in this lesson wasn’t private: the verifier saw the leaf and its whole path. Move that exact check inside a ZK circuit, and the secrets never leave the prover at all.
The leaf secrets and the Merkle path stay private, inside the circuit. The circuit rebuilds the leaf, hashes up the path and checks it equals the root, and computes — all without ever showing its work. Out come only the root the verifier already knew, the nullifier , and the proof itself. One practical note: hashing inside a circuit is expensive, so real systems use hash functions designed for circuits, like Poseidon, playing the same role as throughout this lesson.
That’s the core of anonymous membership — private voting, anonymous credentials, mixers — and it’s built from nothing more than the Merkle tree this lesson opened with.
- A Merkle tree commits to a whole list with one short root, built by hashing leaves in pairs up to a single value.
- Changing any leaf changes the root, and producing a different leaf that keeps the same root means finding a hash collision — infeasible.
- A membership proof needs only the sibling hashes on a leaf’s path, so proof size grows as — about 32 hashes proves one item among 4 billion.
- A vector commitment generalizes this same promise; KZG is an alternative that compresses the proof to one point, at the cost of a trusted setup and pairings.
- Nullifiers () let a member prove membership exactly once without revealing which member they are — the basis of anonymous voting, credentials, and mixers.