Zero-knowledge: theoretical foundations I
This summer, I’ve been studying the field of zero-knowledge. Zero-knowledge (ZK) is a subject that’s picked up a lot of hype lately, as its practical applications keep being discovered all over the web3 landscape. However, before diving into these recent applications of ZK, I wanted to first understand the theoretical foundations of ZK. The theory behind ZK is itself very beautiful, and worthy of study even independent of its applications in the real world.
The vast majority of this post (and subsequent ones) is my summarization of the amazing lectures from Bar Ilan’s 2019 Winter School. These lectures are presented by ZK gods, and are amazingly clear and well organized. I highly recommend watching them for anyone interested in understanding ZK theory, and full credit for the content of this post goes to the organizers of the course.
Thanks to my professor Tal Malkin for helping me understand this material, and thanks to my buddies Arnold and Raghav for proofreading this post.
What’s a proof?
Suppose Alice knows that some statement is true. Suppose that Bob does not yet know that is true. How can Alice “prove” to Bob that is true?
Well, in many cases, Alice can write down a logical explanation of how she knows that is true. Bob can then read this explanation, and also be convinced that is true.
For example, suppose to be the statement “ is a square” (or in mathematical notation: “ such that ”). A simple proof that Alice could write down and send to Bob is the following:
- Let
- Then
There are two important aspects of the above proof to point out:
- [non-interactive] The proof does not require interaction between Alice and Bob.
- Alice can simply write her argument on a piece of paper, hand it to someone, and then walk away. The proof does not require Bob to ask questions or interact with Alice in any way. All he has to do is read Alice’s monologue to be convinced.
- [non-zero-knowledge] Alice reveals to Bob not only that the statement is true, but also how the statement is true.
- Alice shows Bob exactly which element satisfies the property , namely .
- Such a is generally referred to as a “witness for ” – it’s a piece of information which makes the statement easy (efficient) to verify.
- Alice shows Bob exactly which element satisfies the property , namely .
Ok, cool. Basically all proofs in mathematics are of this expository, non-interactive flavor. But this flavor of proof can’t be used to prove all statements – there are some statements for which it’s hard (or impossible) to explain exactly how they are true.
For example, suppose that Alice has a very sophisticated palate and can distinguish between the tastes of Coke and Pepsi. Bob cannot distinguish between them, and is not convinced that Alice can either. In this scenario, is the statement “Alice can distinguish between the tastes of Coke and Pepsi.” How can Alice prove this statement to Bob? She can’t simply explain to Bob how she distinguishes them, as language is insufficient to describe the sensation of taste precisely, especially when the two communicating parties have different palates!
While Alice can’t convince Bob of her sophisticated palate through direct explanation, she can convince him through the following game:
- Alice sets up two cups on a table.
- Alice pours Coke into the left cup, and Pepsi into the right cup. She then puts on a blindfold.
- Bob flips a coin:
- If heads, Bob swaps the left and right cups.
- If tails, Bob leaves the cups in their original configuration.
- Alice then tastes both cups, and says whether she thinks the cups were swapped or not.
If Alice can truly distinguish between Coke and Pepsi, the probability of her winning the game is : she will always be able to tell whether the drink on the left is Coke or Pepsi, and therefore is always able to tell whether the cups were swapped or not.
On the other hand, if Alice cannot distinguish between Coke and Pepsi, then the probability of her winning the game is : she cannot leverage taste to distinguish between the unswapped vs swapped scenario, and so her success probability is equivalent to correctly guessing the outcome of Bob’s coin flip.
If this game is played once and Alice wins, Bob may still not be convinced: even if Alice guessed randomly, she could have won with a 50% chance.
However, Alice and Bob can repeat the game times for some arbitrarily-large in order to amplify Bob’s confidence. In order for Alice to convince Bob of her discerning palate, she must win all rounds. If she loses even a single round, Bob will conclude that she has an ordinary tongue. With rounds of play, the probability of Alice deceiving Bob (in the case where Alice actually cannot distinguish between Coke and Pepsi) is equal to the probability of her randomly guessing Bob’s coin flip in all rounds: .1
Let’s note two important aspects of the above proof:
- [interactive] The proof requires interaction between Alice and Bob.
- Bob introduces randomness to the protocol in the form of a coin flip. This coin flip determines the correct answer of the challenge (swap or not) that Alice must complete.
- [zero-knowledge] Alice convinces Bob only that the statement is true, and does not reveal how the statement is true.
- In this case, it’s not clear how the statement is true (there’s no obvious witness). But we will see examples where Alice does know some witness for the statement, and is yet still able to prove the statement without revealing the witness.
Summarizing proof types
From the two examples above, we’ve seen that there are two axes on which a proof can vary (the following statements are not precise and intended just to build up intuition – we’ll define the terms more formally in a bit):
- Interactive vs non-interactive
- In an interactive proof, Alice and Bob communicate with each other, and the protocol is usually non-deterministic (involves randomness).
- In a non-interactive proof, Alice can complete her proof without any communication from Bob.
- Zero-knowledge vs non-zero-knowledge
- In a zero-knowledge proof, Alice convinces Bob that the statement is true, but does not reveal how the statement is true.
- In a non-zero-knowledge proof, Alice convinces Bob that the statement is true by revealing how the statement is true.
We’ll see that there exist proofs which satisfy each of the combinations. We’ll start by formally defining interactive proof systems, which will then enable us to define and understand zero-knowledge.
Interactive proof systems
An interactive proof system has two parties: a prover , and a verifier . The prover aims to convince the verifier of some statement “.” The proof should be quick and easy to verify, and we will therefore stipulate that the verifier runs in probabilistic-polynomial-time (PPT). On the other hand, we place no restrictions on running time of the prover .
An interactive proof system for is a PPT algorithm and a function such that for all :
- Completeness: if , then accepts
- Soundness: if , then for all accepts
A few notes about this definition:
- The notation represents a “cheating prover” – a prover that does not necessarily behave the same as the specified by the proof system.
- The soundness condition requires that, for all provers (even malicious ones), the probability of the verifier being convinced of a false statement is small.
- The completeness and soundness probabilities of and are just arbitrary constants that are used for convenience.
- In general, the completeness and soundness probabilities can be bounded by any functions and such that:
-
-
- Using such functions would yield an equivalent definition as the one above.
- One definition can be transformed into another by amplification (next bullet point).
- In general, the completeness and soundness probabilities can be bounded by any functions and such that:
- By repeating the proof system independent times, the completeness and soundness can be amplified to have negligible error: .
Example: IP for quadratic non-residuosity
We define the language of “quadratic residues in ”:
Note that there’s an obvious way to prove that some quadratic residue is indeed a quadratic residue. One can simply reveal the witness which satisfies .
Now we can define its complement,2 the language of “quadratic non-residues in ”:
How can one prove that some quadratic non-residue is indeed a quadratic non-residue? It’s not as obvious or simple as in the case of quadratic residues.
Turns out there’s a very simple and elegant interactive proof system for quadratic non-residuosity:
Alon Rosen. YouTube. 2019.]
- The verifier first randomly draws a bit , and an element .
- If , then sends to
- If , then sends to
- The prover receives and checks if
- If , sends to
- If , sends to
- The verifier checks if
- If , then accepts
- If , then rejects
Completeness:
- Suppose
- When , sends accepts
- When , sends accepts
- To see why :
- To see why :
- Therefore,
Soundness:
- Suppose
- Both and
- in both cases is effectively uniformly randomly drawn from , and reveals no information about
- Therefore, the best a malicious prover can do is try to guess randomly:
-
In a single round, the soundness error is . Note that this does not actually satisfy the definition of soundness that we gave above, as the definition requires soundness error to be at most .
The soundness of the protocol can be improved using a process called amplification: we can repeat the protocol for rounds, each with independent randomness, and have accept only if all rounds succeed. In this extended protocol, the probability of a cheating prover fooling (i.e. guessing ’s random bit) in all rounds is . Since runs in polynomial time, we can afford to run the protocol with rounds, and therefore achieve soundness error .
This example demonstrates the potential power of interactive proofs: for some languages, a simple non-interactive proof may not exist, while a simple interactive proof does.
Zero-knowledge
Finally, the time is upon us to define one of the coolest ideas in all of theoretical computer science: zero-knowledge.
Suppose Alice is trying to prove some statement to Bob. As mentioned in the introduction, a zero-knowledge proof should reveal no additional information to Bob, other than the fact that is true. In particular, Bob should not learn how is true – only that it is true.
Now, how do we formally define what it means for Bob not have learned any “additional information” from his interaction with Alice? Well, we could say that Bob doesn’t learn any new “additional information” if he could have known that information himself, without his interaction with Alice.
But now, how do we formally define what it means for Bob to have “known it himself” without the interaction? Well, we can say that Bob could output (“write down”) the information himself.
So, this means that, if the statement is true, Bob should be able to output, or “simulate”, his interaction with Alice, without actually interacting with Alice. For if Bob could not himself produce the information provided by Alice, then that information should be considered “additional knowledge” revealed by Alice.
This is the gist of the definition. In place of Bob, we use a randomized algorithm known as the “simulator”, which simulates the interaction between the prover and verifier, and outputs a transcript of this interaction.
Notation:
- the distribution of transcripts output by the simulator when run on input
- the distribution of transcripts (ordered sequences of messages sent between and ) when the protocol is run on input
- means that the distribution is the same as the distribution
An interactive proof system for is honest-verifier zero-knowledge if there exists a probabilistic simulator , running in expected polynomial time,3 such that , .
Note that this definition has a bit of a caveat: it only considers an honest verifier, i.e. a verifier who obeys the behavior specified in the protocol. In the real world, this is not really useful, as some verifier could be malicious and try to extract extra information from the prover by deviating from the specified protocol. We want to have a stronger definition that protects against this rogue-verifier (denoted as ) as well:
An interactive proof system for is perfect zero-knowledge if for all PPT , there exists a probabilistic simulator , running in expected polynomial time, such that , .
This definition is honestly super weird and hard to wrap your head around when you first learn about it (it was for me, at least), but the more you play around with it, the clearer and more beautiful it becomes. So let’s see it in action through an example.
Example: ZK IP for quadratic residuosity
Recall the language of “quadratic residues in ”:
The following interactive proof system satisfies the definition of perfect ZK (and therefore honest-verifier ZK, since perfect ZK is a stronger definition):
Alon Rosen. YouTube. 2019.]
- randomly draws an element , and sends to
- randomly draws a bit , and sends it to
- If :
- sends
- accepts if
- If :
- sends
- accepts if
Completeness:
- Suppose . Then s.t.
- If , then sends
- Clearly , and so accepts
- If , then sends
- Then , and so accepts
- If , then sends
Soundness:
- Suppose
- Claim: such that both and
- To see this, suppose that both . Then with (both equalities mod ). Then we could write , but this contradicts our assumption that .
- Thus, no matter what a dishonest prover does, at least one of or must not be a quadratic residue.
- If , then will reject when (which happens w.p. 1/2)
- If , then will reject when (which happens w.p. 1/2)
- In other words, no matter what value of commits to, there is at least a probability of 1/2 that will reject
- Therefore, we conclude that
- Claim: such that both and
Ok, we’ve proved that the protocol is an interactive proof system for . Next, we need to prove that it is perfect zero-knowledge. To do this, we need to define a simulator that runs in expected polynomial time, and for all , the output of the simulator running on is the “same” as the protocol running on . The key idea is that the simulator can “reverse” the order of the protocol: it can sample the challenge bit first, and can then craft to satisfy the challenge corresponding to .
Consider the following simulator :
- Sample
- Sample
- Set
- Output
The simulator’s output is randomly distributed over such that . The protocol’s output is randomly distributed over such that . These distributions are the same, and so we’re done!
Hang on – not so fast. We forgot to consider what happens when there’s a rogue verifier that doesn’t follow the protocol! The above simulator is a proof for honest-verifier zero-knowledge, but we can also prove that the interactive proof system is perfect zero-knowledge.
Fix a malicious verifier . The only part of the protocol that controls is the distribution of instead of drawing at random, may set according to some function . We can adjust our simulator definition so that its distribution over matches that of the rogue verifier .
Consider the following adjusted simulator :
- Sample
- Sample
- Set
- If , then output
- Otherwise, repeat
Now our simulator’s output is randomly distributed over such that and , which is the same distribution as the protocol running on : . So now we’re done! Right?
No, not yet. We still need to argue that runs in expected polynomial time. This is not immediately clear, since if repeatedly, the code we wrote might run forever. We can argue that this is extremely unlikely though, and that the simulator actually only repeats a constant number of times in expectation.
The main idea is that the simulated distribution of is independent of : is always a random, uniformly distributed element from . When , this is obvious, since represents a random element in . When , is also a random element in , since multiplying a group element by a random group element yields a random group element. Since is independent of , must also be independent of , and so we have that on each iteration, . Thus, the expected number of iterations for is 2, and therefore the expected running time of is 2 times the expected running time of . Since runs in polynomial time, satisfies the definitional requirement of running in expected polynomial time. Done!
We have shown that the above protocol is an interactive proof for with soundness error , and that it satisfies perfect zero-knowledge. However, in the real world, we want to get soundness error down to a small value, like . Recall that we can use sequential repetition to amplify the soundness error: we can repeat the protocol for rounds. However, we need to be careful, and argue that this protocol with multiple repetitions preserves zero-knowledge. It is sufficient to build a simulator for the -round protocol.
Consider the following simulator :
- For round :
- Sample
- Sample
- Set
- If , then save and move on to the next round
- Where represents all the previous message transcripts before round
- Otherwise, repeat the current round
- Output
Similar analysis4 yields that the expected running time of is 2 times the expected running time of , and that therefore runs in expected polynomial time.
Cool! We’ve shown that the language has a perfect zero-knowledge interactive proof system, with soundness error .
References
References cited in the text are listed first, in order of citation; additional references follow, ordered alphabetically.
- Introduction to zero knowledge [link]
Alon Rosen. YouTube. 2019. - The knowledge complexity of interactive proof systems [link]
Shafi Goldwasser, Silvio Micali, and Charles Rackoff. SIAM Journal on Computing. 1989. - Lecture 15 - zero knowledge proofs [link]
Boaz Barak. 2007.
Footnotes
-
Plugging in some concrete numbers: if there are rounds, then this probability is reduced to less than one-in-a-million: . Bob can of course specify the successful-cheating probability to be arbitrarily small, and then repeat the game rounds to achieve such confidence. ↩
-
This is slightly imprecise. The complement of contains not only , but also . Let’s just assume we’re only considering input values from . ↩
-
We allow to run in expected polynomial time, rather than strict polynomial time. This is how the original GMR paper[2]The knowledge complexity of interactive proof systems [link]
Shafi Goldwasser, Silvio Micali, and Charles Rackoff. SIAM Journal on Computing. 1989. defines it (see the last paragraph on page 10). We will revisit this part of the definition at a later stage, and see whether it’s possible to require the simulator to run in strict polynomial time. ↩ -
One needs to argue that is independent of and . We already showed how to argue that is independent of . is independent of since it is drawn fresh at each new round (i.e. knowing the transcripts of previous rounds cannot help predict ). ↩