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 ss is true. Suppose that Bob does not yet know that ss is true. How can Alice “prove” to Bob that ss is true?

Well, in many cases, Alice can write down a logical explanation of how she knows that ss is true. Bob can then read this explanation, and also be convinced that ss is true.

For example, suppose ss to be the statement “289289 is a square” (or in mathematical notation: “wN\exists w \in \mathbb{N} such that w2=289w^2 = 289”). A simple proof that Alice could write down and send to Bob is the following:

  • Let w=17w = 17
  • Then w2=172=(10+7)(10+7)=(102)+2(107)+(72)=100+140+49=289w^2 = 17^2 = (10 + 7) * (10 + 7) = (10^2) + 2 (10 * 7 ) + (7^2) = 100 + 140 + 49 = 289

There are two important aspects of the above proof to point out:

  1. [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.
  2. [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 ww satisfies the property w2=289w^2 = 289, namely w=17w =17.
      • Such a ww is generally referred to as a “witness for ss” – it’s a piece of information which makes the statement ss easy (efficient) to verify.

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, ss 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 11: 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 1/21/2: 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 kk times for some arbitrarily-large kk in order to amplify Bob’s confidence. In order for Alice to convince Bob of her discerning palate, she must win all kk rounds. If she loses even a single round, Bob will conclude that she has an ordinary tongue. With kk 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 kk rounds: 2k2^{-k}.1

Let’s note two important aspects of the above proof:

  1. [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.
  2. [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):

  1. 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.
  2. 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 {interactive, non-interactive}×{zk, non-zk}\{\text{interactive, non-interactive} \} \times \{\text{zk, non-zk} \} 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 PP, and a verifier VV. The prover PP aims to convince the verifier VV of some statement “xLx \in L.” The proof should be quick and easy to verify, and we will therefore stipulate that the verifier VV runs in probabilistic-polynomial-time (PPT). On the other hand, we place no restrictions on running time of the prover PP.

An interactive proof system for LL is a PPT algorithm VV and a function PP such that for all xx:

  • Completeness: if xLx \in L, then Pr[(P,V)\Pr[(P,V) accepts x]23x] \geq \frac{2}{3}
  • Soundness: if xLx \notin L, then for all P,Pr[(P,V)P^*, \Pr[(P^*,V) accepts x]13x] \leq \frac{1}{3}

A few notes about this definition:

  • The notation PP^* represents a “cheating prover” – a prover that does not necessarily behave the same as the PP 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 2/32/3 and 1/31/3 are just arbitrary constants that are used for convenience.
    • In general, the completeness and soundness probabilities can be bounded by any functions c(x):N[0,1]c(\lvert x \rvert): \mathbb{N} \rightarrow [0,1] and s(x):N[0,1]s(\lvert x \rvert): \mathbb{N} \rightarrow [0,1] such that:
      • c(x)12+1/poly(x)c(\lvert x \rvert) \geq \frac{1}{2} + 1/\mathrm{poly}(\lvert x \rvert)
      • s(x)121/poly(x)s(\lvert x \rvert) \leq \frac{1}{2} - 1/\mathrm{poly}(\lvert x \rvert)
    • Using such functions would yield an equivalent definition as the one above.
      • One definition can be transformed into another by amplification (next bullet point).
  • By repeating the proof system poly(x)\mathrm{poly}(\lvert x \rvert) independent times, the completeness and soundness can be amplified to have negligible error: c(x)s(x)12poly(x)c(\lvert x \rvert) - s(\lvert x \rvert) \geq 1 - 2^{- \mathrm{poly}(\lvert x \rvert)}.

Example: IP for quadratic non-residuosity

We define the language of “quadratic residues in ZN\mathbb{Z}_N^*”:

QRN={xZNwZN s.t. x=w2(mod N)}\mathsf{QR}_N = \{ x \in \mathbb{Z}_N^* \lvert \exists w \in \mathbb{Z}_N^* \text{ s.t. } x = w^2 (\text{mod } N)\}

Note that there’s an obvious way to prove that some quadratic residue xx is indeed a quadratic residue. One can simply reveal the witness ww which satisfies x=w2(mod N)x = w^2 (\text{mod } N).

Now we can define its complement,2 the language of “quadratic non-residues in ZN\mathbb{Z}_N^*”:

QRN={xZNwZN s.t. x=w2(mod N)}\overline{\mathsf{QR}_N} = \{ x \in \mathbb{Z}_N^* \lvert \nexists w \in \mathbb{Z}_N^* \text{ s.t. } x = w^2 (\text{mod } N)\}

How can one prove that some quadratic non-residue xx 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:

Interactive proof system for quadratic non-residuosity
[Source: Lecture 1, Slide 19[1]Introduction to zero knowledge [link]
Alon Rosen. YouTube. 2019.
]
  • The verifier VV first randomly draws a bit b{0,1}b \in \{ 0,1\}, and an element yZNy \in \mathbb{Z}_N^*.
    • If b=0b = 0, then VV sends z=y2z = y^2 to PP
    • If b=1b = 1, then VV sends z=xy2z = x y^2 to PP
  • The prover PP receives zz and checks if zQRNz \in \mathsf{QR}_N
    • If zQRNz \in \mathsf{QR}_N, PP sends b=0b'=0 to VV
    • If zQRNz \notin \mathsf{QR}_N, PP sends b=1b'=1 to VV
  • The verifier VV checks if b=bb' = b
    • If b=bb' = b, then VV accepts
    • If bbb' \neq b, then VV rejects

Completeness:

  • Suppose xQRNx \notin \mathsf{QR}_N
    • When b=0b=0, z=y2QRN    Pz = y^2 \in \mathsf{QR}_N \implies P sends b=0    Vb'=0 \implies V accepts
    • When b=1b=1, z=xy2QRN    Pz = xy^2 \notin \mathsf{QR}_N \implies P sends b=1    Vb'=1 \implies V accepts
      • To see why xy2QRNxy^2 \notin \mathsf{QR}_N:
        xy2QRN    r s.t. xy2=r2(mod N)    x=(r/y)2(mod N)    xQRNxy^2 \in \mathsf{QR}_N \implies \exists r \text{ s.t. } xy^2 = r^2 (\text{mod } N) \implies x = (r/y)^2 (\text{mod } N) \implies x \in \mathsf{QR}_N
    • Therefore, Pr[(P,V) accepts x]=1\Pr[(P,V) \text{ accepts } x] = 1

Soundness:

  • Suppose xQRNx \in \mathsf{QR}_N
    • Both z=y2QRNz = y^2 \in \mathsf{QR}_N and z=xy2QRNz = xy^2 \in \mathsf{QR}_N
    • zz in both cases is effectively uniformly randomly drawn from QRN\mathsf{QR}_N, and reveals no information about bb
    • Therefore, the best a malicious prover can do is try to guess b=bb'=b randomly:
      • P,Pr[(P,V) accepts x]=Prb[P(z)=b]=1/2\forall P^*, \Pr[(P^*,V) \text{ accepts } x] = \Pr_b[P^*(z)= b] = 1/2

In a single round, the soundness error is 1/21/2. 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 1/31/3.

The soundness of the protocol can be improved using a process called amplification: we can repeat the protocol for kk rounds, each with independent randomness, and have VV accept only if all rounds succeed. In this extended protocol, the probability of a cheating prover fooling VV (i.e. guessing VV’s random bit) in all kk rounds is 2k2^{-k}. Since VV runs in polynomial time, we can afford to run the protocol with k=poly(x)k = \mathrm{poly}(\lvert x \rvert) rounds, and therefore achieve soundness error 2poly(x)2^{-\mathrm{poly}(\lvert x \rvert)}.

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 ss to Bob. As mentioned in the introduction, a zero-knowledge proof should reveal no additional information to Bob, other than the fact that ss is true. In particular, Bob should not learn how ss 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 ss 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 SS known as the “simulator”, which simulates the interaction between the prover and verifier, and outputs a transcript of this interaction.

Notation:

  • S(x):=S(x) := the distribution of transcripts output by the simulator SS when run on input xx
  • (P,V)(x):=(P,V)(x) := the distribution of transcripts (ordered sequences of messages sent between PP and VV) when the protocol (P,V)(P,V) is run on input xx
  • S(x)(P,V)(x)S(x) \cong (P,V)(x) means that the distribution S(x)S(x) is the same as the distribution (P,V)(x)(P,V)(x)

An interactive proof system P,VP, V for LL is honest-verifier zero-knowledge if there exists a probabilistic simulator SS, running in expected polynomial time,3 such that xL\forall x \in L, S(x)(P,V)(x)S(x) \cong (P,V)(x).

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 VV^*) as well:

An interactive proof system P,VP, V for LL is perfect zero-knowledge if for all PPT VV^*, there exists a probabilistic simulator SS, running in expected polynomial time, such that xL\forall x \in L, S(x)(P,V)(x)S(x) \cong (P,V^*)(x).

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 ZN\mathbb{Z}_N^*”:

QRN={xZNwZN s.t. x=w2(mod N)}\mathsf{QR}_N = \{ x \in \mathbb{Z}_N^* \lvert \exists w \in \mathbb{Z}_N^* \text{ s.t. } x = w^2 (\text{mod } N)\}

The following interactive proof system satisfies the definition of perfect ZK (and therefore honest-verifier ZK, since perfect ZK is a stronger definition):

Zero-knowledge interactive proof system for quadratic residuosity
[Source: Lecture 1, Slide 31[1]Introduction to zero knowledge [link]
Alon Rosen. YouTube. 2019.
]
  • PP randomly draws an element rZNr \in \mathbb{Z}_N^*, and sends y=r2y = r^2 to VV
  • VV randomly draws a bit b{0,1}b \in \{ 0,1\}, and sends it to PP
  • If b=0b = 0:
    • PP sends z=rz = r
    • VV accepts if z2=yz^2 = y
  • If b=1b = 1:
    • PP sends z=wrz = wr
    • VV accepts if z2=xyz^2 = xy

Completeness:

  • Suppose xQRNx \in \mathsf{QR}_N. Then w\exists w s.t. x=w2(mod N)x = w^2 (\text{mod } N)
    • If b=0b = 0, then PP sends z=rz = r
      • Clearly z2=r2=yz^2 = r^2 = y, and so VV accepts
    • If b=1b = 1, then PP sends z=wrz = wr
      • Then z2=(wr)2=w2r2=xyz^2 = (wr)^2 = w^2 r^2 = xy, and so VV accepts

Soundness:

  • Suppose xQRNx \notin \mathsf{QR}_N
    • Claim: yZN\nexists y \in \mathbb{Z}_N^* such that both yQRNy \in \mathsf{QR}_N and xyQRNxy \in \mathsf{QR}_N
      • To see this, suppose that both y,xyQRNy, xy \in \mathsf{QR}_N. Then r,kZN\exists r, k \in \mathbb{Z}_N^* with y=r2,xy=k2y = r^2 , xy = k^2 (both equalities mod NN). Then we could write x=xy/y=k2/r2=(k/r)2x = xy / y = k^2 / r^2 = (k/r)^2, but this contradicts our assumption that xQRNx \notin \mathsf{QR}_N.
    • Thus, no matter what a dishonest prover PP^* does, at least one of yy or xyxy must not be a quadratic residue.
      • If yQRNy \notin \mathsf{QR}_N, then VV will reject when b=0b=0 (which happens w.p. 1/2)
      • If xyQRNxy \notin \mathsf{QR}_N, then VV will reject when b=1b=1 (which happens w.p. 1/2)
      • In other words, no matter what value of yy VV^* commits to, there is at least a probability of 1/2 that VV will reject
      • Therefore, we conclude that P,Prb[(P,V) accepts x]1/2\forall P^*, \Pr_b[(P^*,V) \text{ accepts } x] \leq 1/2

Ok, we’ve proved that the protocol is an interactive proof system for QRN\mathsf{QR}_N. Next, we need to prove that it is perfect zero-knowledge. To do this, we need to define a simulator SS that runs in expected polynomial time, and for all xQRNx \in \mathsf{QR}_N, the output of the simulator running on xx is the “same” as the protocol (P,V)(P, V) running on xx. The key idea is that the simulator can “reverse” the order of the protocol: it can sample the challenge bit bb first, and can then craft yy to satisfy the challenge corresponding to bb.

Consider the following simulator SS:

  1. Sample zZNz \leftarrow \mathbb{Z}_N^*
  2. Sample b{0,1}b \leftarrow \{ 0, 1\}
  3. Set y=z2/xby = z^2 / x^b
  4. Output (y,b,z)(y, b, z)

The simulator’s output is randomly distributed over (y,b,z)(y, b, z) such that y=z2/xby = z^2 / x^b. The protocol’s output is randomly distributed over (y,b,z)(y, b, z) such that z2=xbyz^2 = x^b y. 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 VV^* 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 VV^*. The only part of the protocol that VV^* controls is the distribution of b:b\text{:} instead of drawing bb at random, VV^* may set bb according to some function b=V(y)b = V^*(y). We can adjust our simulator definition so that its distribution over bb matches that of the rogue verifier VV^*.

Consider the following adjusted simulator SS':

  1. Sample zZNz \leftarrow \mathbb{Z}_N^*
  2. Sample b{0,1}b \leftarrow \{ 0, 1\}
  3. Set y=z2/xby = z^2 / x^b
  4. If b=V(y)b = V^*(y), then output (y,b,z)(y, b, z)
  5. Otherwise, repeat

Now our simulator’s output is randomly distributed over (y,b,z)(y, b, z) such that y=z2/xby = z^2 / x^b and b=V(y)b = V^*(y), which is the same distribution as the protocol running on xx: (P,V)(x)(P, V^*)(x). So now we’re done! Right?

No, not yet. We still need to argue that SS' runs in expected polynomial time. This is not immediately clear, since if bV(y)b \neq V^*(y) 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 yy is independent of bb: yy is always a random, uniformly distributed element from QRN\mathsf{QR}_N. When b=0b=0, this is obvious, since z2z^2 represents a random element in QRN\mathsf{QR}_N. When b=1b=1, z2x1z^2 x^{-1} is also a random element in QRN\mathsf{QR}_N, since multiplying a group element by a random group element yields a random group element. Since yy is independent of bb, V(y)V^*(y) must also be independent of bb, and so we have that on each iteration, Pr[b=V(y)]=1/2\Pr[b = V^*(y)] = 1/2. Thus, the expected number of iterations for SS' is 2, and therefore the expected running time of SS' is 2 times the expected running time of VV^*. Since VV^* runs in polynomial time, SS' satisfies the definitional requirement of running in expected polynomial time. Done!

We have shown that the above protocol is an interactive proof for QRN\mathsf{QR}_N with soundness error 1/21/2, and that it satisfies perfect zero-knowledge. However, in the real world, we want to get soundness error down to a small value, like 2poly(x)2^{-\mathrm{poly}(\lvert x \rvert)}. Recall that we can use sequential repetition to amplify the soundness error: we can repeat the protocol for k=poly(x)k = \mathrm{poly}(\lvert x \rvert) 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 kk-round protocol.

Consider the following simulator SkS_k:

  • For round i{1,2,...,k}i \in \{1, 2, ..., k\}:
    1. Sample ziZNz_i \leftarrow \mathbb{Z}_N^*
    2. Sample bi{0,1}b_i \leftarrow \{ 0, 1\}
    3. Set yi=zi2/xibiy_i = z_i^2 / x_i^{b_i}
    4. If bi=V(yi,ti1)b_i = V^*(y_i, t_{i-1}), then save (yi,bi,zi)(y_i, b_i, z_i) and move on to the next round
      • Where ti1t_{i-1} represents all the previous message transcripts before round ii
    5. Otherwise, repeat the current round ii
  • Output (y1,b1,z1,y2,b2,z2,...,yk,bk,zk)(y_1, b_1, z_1, y_2, b_2, z_2, ..., y_k, b_k, z_k)

Similar analysis4 yields that the expected running time of SkS_k is 2 times the expected running time of VV^*, and that SkS_k therefore runs in expected polynomial time.

Cool! We’ve shown that the language QRN\mathsf{QR}_N has a perfect zero-knowledge interactive proof system, with soundness error 2poly(x)2^{-\mathrm{poly} (\lvert x \rvert)}.

References

References cited in the text are listed first, in order of citation; additional references follow, ordered alphabetically.

  1. Introduction to zero knowledge [link]
    Alon Rosen. YouTube. 2019.
  2. The knowledge complexity of interactive proof systems [link]
    Shafi Goldwasser, Silvio Micali, and Charles Rackoff. SIAM Journal on Computing. 1989.
  3. Lecture 15 - zero knowledge proofs [link]
    Boaz Barak. 2007.

Footnotes

  1. Plugging in some concrete numbers: if there are k=20k=20 rounds, then this probability is reduced to less than one-in-a-million: 220=110485762^{-20} = \frac{1}{1048576}. Bob can of course specify the successful-cheating probability pp to be arbitrarily small, and then repeat the game k=logpk = -\log{p} rounds to achieve such confidence. 

  2. This is slightly imprecise. The complement of QRN\mathsf{QR}_N contains not only {xZNwZN s.t. x=w2(mod N)}\{ x \in \mathbb{Z}_N^* \lvert \nexists w \in \mathbb{Z}_N^* \text{ s.t. } x = w^2 (\text{mod } N)\}, but also {xZN}\{ x \notin \mathbb{Z}_N^*\}. Let’s just assume we’re only considering input xx values from ZN\mathbb{Z}_N^*

  3. We allow SS 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. 

  4. One needs to argue that bib_i is independent of yiy_i and ti1t_{i-1}. We already showed how to argue that bib_i is independent of yiy_i. bib_i is independent of ti1t_{i-1} since it is drawn fresh at each new round (i.e. knowing the transcripts of previous rounds cannot help VV^* predict bib_i).