
Zero-Knowledge Proofs: Proving a Secret Without Revealing It
Imagine you know a secret. Not just any secret, but one that opens a very special door. Now someone challenges you: "Prove that you can open this door."
Of course, you could simply tell them the secret and let them try it themselves. But what if you want to keep it to yourself? Could you convince them that you know it without ever revealing what it is?
This is exactly the problem that zero-knowledge proofs (ZKPs) solve. To see how, let's forget about cryptography for a moment and run a simple thought experiment.
The Hallway with the Locked Door
Picture a hallway that splits into two paths, one to the left and one to the right. At the far end, the two paths are connected by a locked door. The only way to get from one path to the other is to open that door with a secret password. (This story is a variant of the famous "Ali Baba cave" from [2].)
Meet our two participants:
The Prover (P) claims to know the password that opens the door.
The Verifier (V) wants to be convinced of this, without learning the password himself.
Here is how a single round works. First, the verifier waits out of sight, around the corner, while the prover secretly picks one of the two paths and walks in.
Once the prover is inside, the verifier steps back into the hallway, from where he can see both exits but not which path the prover took. He then calls out, at random, which side the prover must come out of: left or right.
If the prover really knows the password, this is easy. She opens the door, switches paths if necessary, and emerges from the requested side.
But what if she is bluffing? Without the password she cannot open the door, so she is stuck on the side she originally chose. If the verifier happens to call that same side, she gets lucky. Otherwise her bluff is exposed. In other words, someone who doesn't know the password has only a 50% chance of surviving a single round.
That is hardly convincing; a lucky guess proves nothing. But now repeat the experiment, not once or twice, but ten times, with fresh random choices each time. A bluffing prover survives all ten rounds with probability (1/2)10 = 1/1024 ≈ 0.098%. With every successful round the verifier's confidence grows, yet the password itself never leaves the prover's mouth.
Why does the verifier learn nothing?
Imagine the verifier films the whole experiment. Would the video convince a third person? No. A cheating pair could produce an identical film: they agree in advance which side will be called, the "prover" simply walks in on that side and walks out again, and they discard every take that doesn't match. Since an honest run and a staged run look exactly the same, the recording contains no information about the password. This "you could have faked the transcript yourself" argument is the heart of how zero-knowledge is defined in cryptography, and we will meet it again at the end of this post.
The three properties
Every zero-knowledge proof has to satisfy three properties. The hallway experiment shows each of them:
Soundness. A false claim is accepted only with very small probability. (A bluffer survives n rounds with probability 2-n.)
Zero-knowledge. The verifier learns nothing beyond the fact that the statement is true. (The staged video looks the same as the real one.)
Of course, real zero-knowledge proofs don't involve hallways or locked doors; they use mathematics instead. Let's look at a concrete example.
A ZKP for the Number of Prime Factors
Cryptography knows many zero-knowledge proofs. Below I describe a simple one that builds on two further zero-knowledge proofs as subroutines.
Suppose the prover picks $k$ random, distinct, large odd primes $p_1, \dots, p_k$ and computes $N = \prod_{j=1}^{k} p_j$. The primes are so large that factoring $N$ is infeasible. The prover wants to convince a verifier that $N$ has exactly $k$ prime factors, while keeping the factors themselves secret. How can she do this?
Before we start, one important point. A zero-knowledge protocol must ensure that the verifier learns only the statement being proven and nothing else. Everything he learns must be either the statement itself or something he could have computed on his own. That sounds trivial, but as we will see it is surprisingly easy to violate by accident.
The mathematical idea: counting square roots
The idea works via square roots. Start with a single prime $p$. Among the $p-1$ non-zero residues modulo $p$, exactly half are quadratic residues (QR), that is, squares. A QR $h$ has exactly two square roots, $s$ and $-s$, satisfying $s^2 \equiv (-s)^2 \equiv h \pmod{p}$. A non-square (a quadratic non-residue, QNR) has no square root. So a random non-zero residue modulo $p$ is a QR with probability $1/2$.
Now take two primes and set $N = p_1 p_2$. A number coprime to $N$ is a square modulo $N$ only if it is a square modulo both primes at the same time. That happens for just a quarter of all such numbers, and every square then has $2^2 = 4$ square roots. For $k$ primes the pattern continues:
The fraction of squares therefore reveals the number of prime factors. Let's make this concrete with $N = 15 = 3 \cdot 5$ ($k=2$). Of the 8 residues coprime to 15, only $1$ and $4$ are squares, which is a quarter. For example, $1$ has the four square roots $1, 4, 11, 14$, and $4$ has the four square roots $2, 7, 8, 13$.
There is a subtlety worth knowing about. The Jacobi symbol $\left(\frac{a}{N}\right)$ can be computed efficiently without knowing the factorisation of $N$. Half of all residues have Jacobi symbol $+1$, but only half of those are real squares. In our example, $1, 2, 4, 8$ all have Jacobi symbol $+1$, yet only $1$ and $4$ are squares. Numbers like $2$ and $8$ look like squares but aren't, and telling the two apart is believed to be hard without the factorisation of $N$. This is the quadratic residuosity assumption, and it is exactly what the protocols below must protect.
A naive protocol (do not use)
Armed with this, one could naively build the following protocol:
Naive Protocol 1 (not secure)
Step 1. The verifier sends randomly chosen integers $a_1, \dots, a_m$ to the prover.
Step 2. Whenever possible, the prover returns a square root of $a_i$ modulo $N$.
Step 3. The verifier counts the successful answers and estimates the number of prime factors.
It looks reasonable, but all three steps are broken. Don't use it.
Step 1: the verifier must not choose the numbers. He could smuggle in numbers of his own choosing and learn from the prover's answers whether each one is a real square or only has Jacobi symbol $+1$. That information is believed to be inaccessible without the factorisation of $N$, so the verifier would learn more than the protocol is allowed to reveal.
Step 2: returning square roots leaks the factorisation. The verifier picks a number $s$, computes $a = s^2 \bmod N$ and sends $a$ to the prover. The prover returns some square root $t$ of $a$. Since $a$ has $2^k$ roots, $t$ differs from $\pm s$ with probability $1 - 2/2^k$, which is at least $1/2$ for every $k \ge 2$. In that case $N$ divides $(s-t)(s+t)$ without dividing either factor, so $\gcd(s-t,\,N)$ is a non-trivial factor of $N$. The secret is gone.
Step 3: a dishonest prover can lie by omission. A malicious prover can stay silent on some squares, so that $N$ appears to have more prime factors than it really has. The verifier has no way to tell the difference between "no square root exists" and "the prover refuses to answer".
A repaired protocol
Each of the three flaws can be fixed:
Protocol 2
Step 1. The verifier picks a fresh random seed $S$ (after $N$ has been fixed), and both parties agree on a hash function $H$ whose output is considerably longer than $N$.
The test numbers are $m_i = H(S \,\|\, i) \bmod N$ for $i = 1, \dots, n$.
Step 2. For each $m_i$, the prover gives a zero-knowledge proof that $m_i$ is a quadratic residue, if it is one, or a zero-knowledge proof that $m_i$ is a quadratic non-residue, if it is not (both proofs are described in [1]).
Step 3. The verifier computes the fraction $f$ of numbers that were proven to be squares and concludes that $N$ has $k \approx -\log_2 f$ prime factors.
Why Step 1 works. The numbers are now determined by a hash function, so both sides can recompute them and nobody can slip in specially prepared values. The seed must come from the verifier (or from a public randomness beacon) and not from the prover: the prover knows the factorisation, so she could simply try seeds until the pattern of squares matches whatever number of factors she wants to claim.
Why Step 2 works. The verifier only learns that a number is a square, not what its roots are, so he cannot use the answers to factor $N$. And since the prover must produce a proof in both cases, she can no longer hide squares: claiming that a real square is a non-residue would require a false proof of non-residuosity, which soundness rules out.
Why Step 3 works. The fraction of squares among the $m_i$ is now one the prover cannot manipulate, so it honestly reflects the number of prime factors. The verifier learns the count $k$ and, ideally, nothing else (this has to be proven separately, see below).
Technical note: is Protocol 2 really zero-knowledge?
One could object that the verifier learns whether each $m_i$ is a square, and that this is something he cannot compute himself. Whether that is a problem depends on the formal definition. To prove zero-knowledge one constructs a simulator: an algorithm that, without knowing the factorisation, produces transcripts that are indistinguishable from real conversations between prover and verifier. It is exactly the film trick from the hallway, made mathematical. Here the simulator can use the random oracle model: it "programs" the hash function so that a fraction $1/2^k$ of the $m_i$ are squares of numbers it picked itself, and the rest are random. Since the transcript distribution is the same, the verifier learns nothing he could not have simulated himself, apart from the number of prime factors, which is the statement being proven.
Limitations
- The conclusion is statistical. To tell $k$ from $k+1$ the verifier needs on the order of $2^k$ test numbers (times a constant for the desired confidence), so this protocol is only practical for small $k$. (Since the verifier can compute Jacobi symbols himself, he can discard numbers with Jacobi symbol $-1$ and speed things up a bit; among the rest the fraction of squares is $2^{1-k}$.)
- It counts distinct odd primes. Repeated factors are invisible: $315 = 3^2 \cdot 5 \cdot 7$ has the same fraction of squares as $105 = 3 \cdot 5 \cdot 7$. Proving that $N$ is squarefree needs a separate argument.
- It is interactive. The sub-proofs from [1] need several rounds of communication, just like the hallway experiment.
The underlying idea stays the same as in the hallway: you can prove that you know something, or that something is true, without handing over the secret itself.
References:
[1] Goldwasser, S., Micali, S., Rackoff, C. (1989). The Knowledge Complexity of Interactive Proof Systems. SIAM Journal on Computing, 18(1), 186–208.
[2] Quisquater, J.-J., Guillou, L., Berson, T. (1990). How to Explain Zero-Knowledge Protocols to Your Children. CRYPTO '89, LNCS 435, 628–631.
Comments
Post a Comment