Zero-knowledge proof: graph 3-coloring
A coloring you never show
Ali Baba’s cave showed the order commitment, challenge, response with a picture of a door. Here the same pattern works on a real problem. A graph is 3-colorable if its vertices can be painted with three colors so that the two ends of every edge differ. A finished coloring is checked at a glance, finding one is hard: 3-coloring is NP-complete, so for large graphs nobody knows a fast method. The prover wants to convince the verifier that they know a coloring, and give away nothing of it.
The protocol comes from Goldreich, Micali and Wigderson (“Proofs that yield nothing but their validity”, FOCS 1986, J. ACM 1991). One round has four steps. The prover draws a permutation of the three colors and renames the coloring with it — still valid, only with fresh color names. Then they commit to every vertex’s color: C = SHA-256(r ‖ m), where r is 32 random bytes and m the color’s digit, as in the Commitments station. The verifier picks a random edge. The prover opens its two ends, and the verifier checks both hashes and that the colors differ and are among the three.
Whoever does not know a coloring has at least one edge with matching ends and cannot change the commitments afterwards. The verifier hits it with probability at least 1/|E|, where |E| is the number of edges. With 11 edges that is 1/11 per round, far less than 1/2 in the cave, so more rounds are needed: a cheater passes n rounds with probability at most (1 − 1/|E|)ⁿ and drops below one chance in a million only after 145 rounds (in the cave, after 20). GMW repeat the round |E|² times, which gives (1 − 1/|E|)|E|² ≈ e−|E|.
Why zero knowledge? In each round the verifier sees the edge they picked and two different colors. Thanks to the permutation that is a random pair out of six, independent of the real coloring, and the other commitments reveal nothing. A simulator that does not know the coloring guesses the edge, paints its ends two different colors and the other vertices anyhow, and redoes the take when the verifier picks another edge — like the editor of the cave film. The opened pairs have the same distribution as an honest prover’s, and the sealed commitments hide noise instead of a coloring — as long as the commitments hide, the two transcripts cannot be told apart. In the toy you forge such a transcript from your rounds.
Three colors, one edge at a time
Toy implementation — do not use in productionThe graph has 7 vertices, so you can find its coloring in your head. The proof makes sense for graphs nobody can color in reasonable time.
You are the verifier. The prover knows a coloring of the graph with three colors. Before each round they shuffle the colors and send a commitment to every vertex’s color. You pick an edge, and they open its two ends.
Pick an edgeThe prover is shuffling the colors and computing the commitments…
Color 1 — circle, 2 — square, 3 — diamond, with its digit inside. Dashed circle with “?” — a sealed commitment. Thick line — this round’s edge.
A cheater without a coloring is caught in each round with probability at least 1/11: they pass all 145 rounds with probability at most 1 in 1,004,475.
The cheater and the curious verifier
A cheating prover has one hope at most: that the verifier misses the bad edge. The best they can have without a coloring is one such edge — and they are still caught every 11 rounds on average, while the verifier adds rounds cheaply. The protection rests on two things. The commitments must bind: if C could be opened as another color, the cheater would change the color after the challenge and pass every round. The edge must be unpredictable and picked only after the commitments: whoever knows it in advance colors just that edge properly — the predictable challenge from the cave.
A cheater without a coloring
You shuffle the colors and send commitments like an honest prover. The verifier draws the edge with crypto.getRandomValues only after that, so you do not know whether it will hit A–B.
The prover is shuffling the colors and computing the commitments…
Only you see your colors. Dashed line with ✕ — your bad edge A–B. Thick line — the edge the verifier picked.
The verifier hits A–B with probability 1/11 per round: you pass all 145 rounds with probability 1 in 1,004,475.
On the verifier’s side, zero knowledge rests on the permutation. Each round on its own reveals only that two neighboring vertices have different colors. But when the prover does not shuffle the colors, or uses the same permutation in every round, all rounds speak the same language: the verifier writes down the opened colors and pieces the whole coloring together — with seven vertices, four edges are enough. A weak commitment ends the same way. Without r the commitment is SHA-256 of one digit, and there are three digits: the verifier recomputes them before picking an edge and reads every color at once (guessing the content in the Commitments station). One r for all vertices does not do either: equal colors give equal C, so the color classes show at once.
The curious verifier’s notebook
The prover renamed the colors once, at the start of the session, and uses the same names in every round. The commitments are fine — each has a fresh r.
Pick an edgeThe prover is shuffling the colors and computing the commitments…
Color 1 — circle, 2 — square, 3 — diamond. “?” — a vertex not opened yet. Circle with ✕ — your notebook has different colors for it. Thick line — the last round’s edge.
- A: — not opened
- B: — not opened
- C: — not opened
- D: — not opened
- E: — not opened
- F: — not opened
- G: — not opened
Commit to everything, open a piece
- Picnic: a signature from the ZKB++ proofThe post-quantum Picnic signature is a non-interactive proof of knowledge of the key. The prover simulates a computation by three parties, commits to their views, and the challenge opens two of the three — like the two ends of an edge. One repetition lets a cheater through with probability 2/3, so the picnic-L1-FS variant runs 219 parallel repetitions: (3/2)²¹⁹ ≥ 2¹²⁸.Source (Picnic: a signature from the ZKB++ proof)
- NIST: third round of additional signatures (2026)In May 2026 NIST picked nine candidates for the third round of its call for additional post-quantum signatures. NIST files three of them — FAEST, MQOM and SDitH — under “MPC-in-the-head” (FAEST is built on its variant, “VOLE-in-the-head”). In MPC-in-the-head the prover commits to the data of simulated parties, and the challenge decides which of them to reveal.Source (NIST: third round of additional signatures (2026))
- Zcash: forged proofs (CVE-2019-7167)On 1 March 2018 a cryptographer at the Zcash Company found that the parameter setup of the BCTV14 proofs produced extra elements that made it possible to forge a proof — and create coins out of nothing. The Sapling upgrade (28 October 2018) quietly removed the flaw, which was disclosed on 5 February 2019; no evidence of exploitation was found.Source (Zcash: forged proofs (CVE-2019-7167))
- Swiss Post and Scytl: commitments with a trapdoor (2019)In March 2019 Lewis, Pereira and Teague showed that in Scytl’s e-voting system for Swiss Post, the Pedersen commitment parameters in the vote-shuffle proof (Bayer–Groth) came from random exponents with no proof of how they arose. Those exponents are a trapdoor that breaks binding: whoever knows them can alter votes and produce a proof that passes verification.Source (Swiss Post and Scytl: commitments with a trapdoor (2019))
Graph coloring is rarely computed directly — its weight lies elsewhere. Every statement in the class NP can be translated into a question about 3-colorability, so GMW showed that, assuming one-way functions exist (commitments are built from them), every such statement has a zero-knowledge proof. Practical systems do not go through graphs, because the graph would be huge and the rounds number in thousands, but the pattern stays: commit to everything, let the verifier choose what to open, and repeat until the cheater’s chance is negligible. The same pattern works for sudoku, which is coloring with nine colors: in the protocol of Gradwohl, Naor, Pinkas and Rothblum the prover permutes the digits, commits to every cell, and the verifier picks a row, a column, a box or the cells given in the puzzle.
A new permutation and a new r every round
Do not design your own protocol — use a described standard and a proven library. If you implement a protocol like this one, draw a new color permutation with a cryptographic generator before every round, give every vertex a new r in every round (at least 128 bits), and draw the edge only after the commitments. Derive the number of rounds from the required security level λ: (1 − 1/|E|)ⁿ ≤ 2−λ. The verifier checks both openings, that the colors belong to the palette, and that they differ.
// number of rounds: (1 − 1/|E|)^n ≤ 2^−λ
const rounds = Math.ceil(lambda / -Math.log2(1 - 1 / edges.length));
// before EVERY round: a new permutation (Fisher–Yates);
// randomInt(k) — crypto.getRandomValues without modulo bias
const perm = [0, 1, 2];
for (let i = 2; i > 0; i--) {
const j = randomInt(i + 1);
[perm[i], perm[j]] = [perm[j], perm[i]];
}
const colors = coloring.map((c) => perm[c]);Do not draw the permutation once per session or skip it — the rounds will add up to the whole coloring. Do not commit without r, or with one r for all vertices. Do not borrow the number of rounds from another protocol: 20 rounds are enough in the cave, where a round catches a cheater with probability 1/2, but with 11 edges they leave the cheater a (10/11)²⁰ ≈ 15% chance.
// ✕ one permutation for the whole session
const perm = shuffle([0, 1, 2]);
for (let round = 0; round < 20; round++) { // ✕ too few rounds
const colors = coloring.map((c) => perm[c]);
// ✕ no r: three hashes give every color away
const sealed = colors.map((m) => sha256(String(m + 1)));
}