Part VI — Applied Decentralization · Chapter 3

Zero-knowledge proofs

Hook

You need to prove you know the password to an account, or the private key behind a signature, or that you're over 21 — without ever handing over the password, the key, or your birth date. Is it actually possible to convince someone a secret exists and that you have it, while giving them zero information about what the secret actually is?

Intuition

Commit Prover picks random r = 4, sends c = r² mod 91 = 16. (The verifier never learns r itself yet.)

Challenge Verifier flips a coin and asks for branch 0.

Respond Prover reveals r = 4 directly.

✓ Verified — the check for branch 0 holds.

The prover commits to a random number first, before knowing which question the verifier will ask. Whichever branch gets challenged, the prover can answer honestly — but each answer alone (just r, or just r·x mod n) looks like a random number to the verifier. Neither branch, on its own, reveals x.

Formalize

This is a simplified Fiat-Shamir identification scheme. Public knowledge: a modulus nn and a value y=x2modny = x^2 \bmod n. The prover claims to know a square root xx of yy, without revealing it.

b=0:  r2modn=cb=1:  z2modn=cymodnb=0:\ \ r^2 \bmod n = c \qquad\qquad b=1:\ \ z^2 \bmod n = c\cdot y \bmod n
  • nn, yy — public: the modulus, and y=x2modny=x^2 \bmod n, the value whose root is being proven known.
  • rr — a fresh random number the prover picks each round; never revealed directly unless b=0b=0.
  • cc — the commitment, c=r2modnc = r^2 \bmod n, sent before the challenge is known.
  • bb — the verifier's random challenge bit, 00 or 11, chosen after cc is committed.
  • zz — the response when b=1b=1: z=rxmodnz = r\cdot x \bmod n, which mixes in xx but never exposes it alone.
  1. A cheater can prepare for at most one branch

    Without knowing xx, an impostor can fake a valid-looking commitment for one branch (say, honestly revealing some rr for b=0b=0) — but has no way to produce a zz with z2modn=cymodnz^2 \bmod n = c\cdot y \bmod n for b=1b=1, since that requires actually knowing xx.

  2. One round only catches a cheater half the time

    The verifier's challenge is random, so an impostor who guessed which branch to prepare for gets away with it whenever the verifier happens to ask that same branch — a coin flip, 50/50.

  3. Independent rounds multiply — probability of cheating shrinks fast

    Repeating with a fresh random rr and a fresh random challenge each round, the rounds are independent: the chance a cheater survives all of them is (1/2)rounds(1/2)^{\text{rounds}}, collapsing toward zero very quickly.

  4. Yet the verifier never learns x

    Each round leaks only rr or rxmodnr\cdot x \bmod n — one masked value, chosen fresh every round — never enough, across any number of rounds, to isolate xx itself.

Play

y = x² mod 91 = 25 is public; x itself is never revealed, in any round.

After 1 independent round, an impostor who doesn’t know x fools the verifier with probability (1/2)1 = 0.5000 (50.00%).

Drag the rounds slider and watch (1/2)rounds(1/2)^{\text{rounds}} collapse: by round 5 an impostor's odds are already under 1 in 30, and it keeps falling from there — all while the verifier still never learns xx.

Worked example

Public setup: n=91n = 91, secret x=5x = 5, public y=x2mod91=25y = x^2 \bmod 91 = 25. The prover picks r=4r=4 for this round.

  1. Commit

    c=r2mod91=16mod91=16c = r^2 \bmod 91 = 16 \bmod 91 = 16. The prover sends 16 and waits for the challenge.

  2. Branch b=0: reveal r

    Response =r=4= r = 4. Verifier checks 42mod91=164^2 \bmod 91 = 16, which matches c=16c=16. ✓ Passes — and the verifier has learned only that some rr with r2mod91=16r^2\bmod 91=16 exists, nothing about xx.

  3. Branch b=1: reveal r·x mod n instead

    Response =(4)(5)mod91=20= (4)(5) \bmod 91 = 20. Verifier checks 202mod91=400mod91=3620^2 \bmod 91 = 400 \bmod 91 = 36, and separately cymod91=16×25mod91=400mod91=36c \cdot y \bmod 91 = 16 \times 25 \bmod 91 = 400 \bmod 91 = 36. Both sides equal 36. ✓ Passes.

  4. Rounds needed for under 5% cheating odds
    • At 4 rounds: (1/2)4=0.0625(1/2)^4 = 0.0625 — still above 5%
    • At 5 rounds: (1/2)5=0.03125(1/2)^5 = 0.03125 — clears it

    So 5 rounds is the smallest number that pushes a cheater's odds below 5%.

Checkpoint

Move the rounds slider to the smallest number of rounds that drops an impostor’s cheating probability to 5% or below — not just any round count past that point.

1 round → cheating probability = 0.50000 (50.00%)

Move the slider to try it
Summary
r2modn=c,z2modn=cymodn,P(cheat)=(1/2)roundsr^2 \bmod n = c, \qquad z^2 \bmod n = c\cdot y \bmod n, \qquad P(\text{cheat}) = (1/2)^{\text{rounds}}

A zero-knowledge proof convinces a verifier that a secret exists — by making a cheater's odds of bluffing through every round vanish — while each round leaks only one masked value that, alone, carries no information about the secret at all.