[Work in Progress] Demistifying zero-knowledge: introduction to zero-knowledge proofs of knowledge
17 min read
It's a Tuesday, and you meet with your rival Viktor for your usual Tuesday Sudoku Challenge. You extract a sudoku from the stash and you both start solving it.
One hour passes... Two hours pass... At the three hours mark you're done, and you want to claim your prize! In order to do so, you have to convince your rival that you have indeed completed the sudoku. However, you have worked hard for the solution and you don't want Viktor to obtain it for free. Any digit revealed to them might be the crucial digit that unfolds the whole sudoku.
How can you convince Viktor beyond reasonable doubt that you have indeed completed the sudoku, while revealing not even a single digit of the solution?
You have state-assigned credentials or password paired to your identity (like a social security number). "You" gets defined as anyone who can prove that they know the credentials. You want to prove to some service provider that you are "you". However, if you do so by revealing your credentials, then an employee of the service provider could impersonate you and steal your identity.
How can you prove beyound reasonable doubt that you know the credentials, without revealing them?
These two examples are particular cases of a more general problem. In both examples there is a prover which wants to convince a verifier of something.
In the sudoku example, both you and Viktor know the public empty sudoku, which we can call . You want to prove that you know a sudoku solution (called witness) such that the statement
" is the solution to the sudoku "
is true, while keeping secret.
Similarly in the second example, both you and the service provider know the name of the claimed identity, which we will call . You want to prove that you know the correct credentials such that the statement
" are the correct credentials for the identity "
is true, while keeping secret.
A zero-knowledge proof of knowledge (ZKP, sometimes ZKPoK) is a tool which can be used to solve problems like the two above. More precisely:
Definition
Let and be two parties respectively called "prover" and "verifier".
Let be some value known by both and , and suppose that additionally knows a witness such that some statement is true.
A ZKP allows to prove beyond reasonable doubt to that they know a valid without revealing anything about it.
This initial definition is definitely lacking some details, and reasonable questions to be having in your mind after reading it are the following:
- what does it mean to prove beyond reasonable doubt?
- how can I prove something that needs , without revealing absolutely nothing about it? What does it even mean to reveal absolutely nothing about ?
- how can we mathematically formalize the idea of knowing something, if we are forbidden from exhibiting it?
Thankfully, we "only" have to prove beyond reasonable doubt
While commonly the phrase "proving beyond reasonable doubt" implies a thoroguh, difficult and time consuming proof, in this context it is actually a blessing. Here it means that instead of having to produce an actual mathematical proof, we only have to produce a proof that is convincing up to some reasonable threshold, whatever that means.
This means that we can use probabilistic proofs. A probabilistic proof for some statement is a proof with some (small) false-positive probability, meaning that if the statement is actually false, there is still a (small) probability that the proof gets accepted as true.
In particular, we will be considering interactive probabilistic proofs, meaning that the proof consists of an interaction between the prover and the verifier, where the verifier poses challenges which should be very hard to pass if the prover doesn't actually have a valid witness (hence, a passed challenge gives some guarantees on the validity of the statement ).
To give a practical example of an interactive probabilistic proof, suppose that you live in a world where everyone except you is colorblind, and you want to prove that you can tell red from green. You could do so with the following interactive probabilistic proof:
You prepare two cards, one red and one green, with the respective color written under them. To a colorblind person they look identical.
You give them to the (colorblind) verifier, who shuffles without you looking and then peeks under them to know which is which. They then challenge you to tell which is red and which is green.
If you are indeed not-colorblind, you would always pass this challenge. If you instead are colorblind, you have a 50% chance of passing and 50% chance of failing.
If you repeat this twice, the probability of a false-positive drops from 50% to 25%. Thrice, it goes to 12.5%, and so on...
We have to be careful with the wording, and stick to talking about the probability of a false-positive, which is "the probability of passing the challenges, if you're actually colorblind". We cannot say anything about "the probability of actually being colorblind, if you pass the challenges"
For example, take the proof above and suppose the prover passes the challenge repeated thrice. As we said, the triple-challenge has a false-positive rate of 12.5%. It would be tempting then to say that a prover who passes the three checks has only a 12.5% chance of actually being colorblind.
However, this is not exactly how this works. The explanation uses conditional probability, which you might want to read about if you're not familiar with the concept.
Consider the following events:
- = you are colorblind
- = you pass the three challenges
Then, our correct claim is that the false-positive rate is
Viceversa, saying that "if you pass the checks then you have a 12.5% chance of being colorblind" would be saying
Note that by Bayes' theorem, to know from we would somehow need to know . However, there is no meaningful way of getting the probability of "being or not being colorblind in a world where everyone is colorblind".
So, we are stuck with talking about false-positive rates.
By repeating this proof a sufficient number of times, we can get the probability of a false-positive arbitrarily low.
Then, we just need to decide what "reasonable doubt" is, and create a proof according to this threshold. For example, the verifier could decide that they would be satisfied with a probabilistic proof with a false-positive rate of 0.0000001%; then the prover would only need to create a proof with a false-positive rate equal or smaller than the threshold, and submit it to the verifier.
This solves the first piece of the puzzle: a ZKP is a type of interactive probabilistic proof, meaning a series of challenges posed by the verifier to the prover, with a false-positive rate which can be made arbitrarily low.
To keep things simple, we will focus on "3-round ZKP"[1], that is interactive proofs where only three messages are exchanged, after which the verifier either accepts or rejects the validity of the response to the challenge (and the validity of the proof in general):
Prover Verifier
─┬─ ─┬─
│ │
├-------m1----->│
│ │
│<------m2------┤
│ │
└-------m3----->│
│
V
accept or reject
Of these messages, the second and third are easy to understand: they are respectively the random challenge chosen by the verifier and the response to the challenge.
The first message is a bit more delicate: it usually called the commitment, and it is a way to fix some state that makes it harder for the prover to respond to the challenge. We can make its purpose clearer with a silly example: a magician guessing a number you are thinking.
A magician writes a number on a piece of paper and puts it down, without showing the written number.
They ask you to choose a random number and saying it out loud.
The magician turns the paper revealing the correct guess.
In this example, writing the guess on the piece of paper is the commitment, , you saying the number outloud is the challenge, , and the magician revealing the written number is .
The commitment is fixing a state ("the number is written on this piece of paper that will not change after the challenge is issued"), and this is what makes it hard to respond succesfully to the challenge: if the magician were allowed to write the number down after you said it out loud, the trick would be far less impressive.
In a 3-round ZKP, the first message has the same functionality: it fixes a state before the challenge is even chosen, making it actually hard to respond to the challenge without (in the silly example, what allows to respond to the challenge is not knowledge of a witness, but the supposed ability to read minds or predict the future).
We can start building a working example of interactive probabilistic proof for the sudoku example. Consider the following protocol (which in fairness has a very high false-positive rate):
Interactive probabilistic proof for sudoku
Initial state: You (prover, ) and Viktor (verifier, ) both start with the unsolved sudoku, which we will cal .
You additionally have the solved sudoku, which we will call .
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── puzzle (x) + │ solution (w) │ puzzle (x) ╔═══╤═══╦═══╤═══╗ │ ╔═══╤═══╦═══╤═══╗ ║ 4 │ 3 ║ 2 │ 1 ║ │ ║ │ ║ │ ║ ╟───┼───╫───┼───╢ │ ╟───┼───╫───┼───╢ ║ 2 │ 1 ║ 4 │ 3 ║ │ ║ 2 │ ║ 4 │ 3 ║ ╠═══╪═══╬═══╪═══╣ │ ╠═══╪═══╬═══╪═══╣ ║ 3 │ 4 ║ 1 │ 2 ║ │ ║ 3 │ 4 ║ │ 2 ║ ╟───┼───╫───┼───╢ │ ╟───┼───╫───┼───╢ ║ 1 │ 2 ║ 3 │ 4 ║ │ ║ │ ║ │ ║ ╚═══╧═══╩═══╧═══╝ │ ╚═══╧═══╩═══╧═══╝
Step 1, setup:
You hide each digit of the sudoku behind distinct locks of which only you possess the keys[2].
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── x + w + │ x locked solution │ & keys │ ╔═══╤═══╦═══╤═══╗ │ ║ 🔐│ 🔐║ 🔐│ 🔐║ │ ╟───┼───╫───┼───╢ │ ║ 🔐│ 🔐║ 🔐│ 🔐║ │ ╠═══╪═══╬═══╪═══╣ │ ║ 🔐│ 🔐║ 🔐│ 🔐║ │ ╟───┼───╫───┼───╢ │ ║ 🔐│ 🔐║ 🔐│ 🔐║ │ ╚═══╧═══╩═══╧═══╝ │
Step 2, commitment:
You send to the locked solution, but not the keys. This is the commitment message .
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── x + w + keys │ x + alleged │ locked solution │ │ ╔═══╤═══╦═══╤═══╗ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╟───┼───╫───┼───╢ locked solution │ ║ 🔒│ 🔒║ 🔒│ 🔒║ ------(m1)-----------> ╠═══╪═══╬═══╪═══╣ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╟───┼───╫───┼───╢ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╚═══╧═══╩═══╧═══╝
Step 3, challenge:
challenges you to open two of the locked digits, and sends you a message stating which entries they would like to be opened. This is the challenge message .
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── x + w + keys │ x + alleged │ locked solution │ │ row 2 col 2 │ & row 2 col 4 <-----------(m2)------- │
Step 4, response:
You send the corresponding keys. This is the response message .
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── x + w + keys │ x + alleged │ locked solution + │ alleged keys 🔑 r2c2's key │ 🔑 r2c4's key │ -------(m3)----------> │
Step 5, verification:
opens the corresponding locks and does the following checks:
- if the two opened digits are on the same row, same column or same box, check that they must be different;
- if any of the opened digits were already present in the unsolved sudoku, check that they correspond.
🥸 Prover │ 🤔 Verifier ─────────────────────┼───────────────────── x + w + keys │ x + alleged │ locked solution + │ keys │ │ ╔═══╤═══╦═══╤═══╗ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╟───┼───╫───┼───╢ │ ║ 🔒│ 1 ║ 🔒│ 3 ║ │ ╠═══╪═══╬═══╪═══╣ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╟───┼───╫───┼───╢ │ ║ 🔒│ 🔒║ 🔒│ 🔒║ │ ╚═══╧═══╩═══╧═══╝
🤔 Verifier's check ─────────────────────────────────────────── partially unlocked x alleged solution ╔═══╤═══╦═══╤═══╗ ╔═══╤═══╦═══╤═══╗ ║ │ ║ │ ║ ║ 🔒│ 🔒║ 🔒│ 🔒║ ╟───┼───╫───┼───╢ ╟───┼───╫───┼───╢ ║ 2 │ ║ 4 │ 3 ║ ║ 🔒│ 1 ║ 🔒│ 3 ║ ╠═══╪═══╬═══╪═══╣ <---> ╠═══╪═══╬═══╪═══╣ ║ 3 │ 4 ║ │ 2 ║ ║ 🔒│ 🔒║ 🔒│ 🔒║ ╟───┼───╫───┼───╢ ╟───┼───╫───┼───╢ ║ │ ║ │ ║ ║ 🔒│ 🔒║ 🔒│ 🔒║ ╚═══╧═══╩═══╧═══╝ ╚═══╧═══╩═══╧═══╝
This example is a valid interactive probabilistic proof for the correctness of the sudoku solution. Some key points of the protocol:
- the verifier's check must also confront the uncovered digit are consistent both within the solution (e.g: digit in the same row/column/box do not repeat) and consistent with the unsolved sudoku (e.g: a digit appearing in the unsolved sudoku must remain the same in the solution). Otherwise, the prover could submit a valid solution to an unrelated sudoku and it would get accepted as valid;
- the false-positive rate is gigantic: for example, if the solution was all correct except for one digit, it's very likely that the verifier's challenge doesn't uncover that specific digit, meaning that the solution gets accepted as valid. To avoid this, we could repeat the challenge-response multiple times. This, in turn, would reveal more and more information about the solution, which means that...
- ... this protocol is not zero-knowledge , as the response actively leaks digits from the solution, revealing information about the witness.
We tackle the information leakage issue in the next section.
Achieving "zero-knowledge"
Ready for the next question: how is it possible to prove something that requires , without revealing absolutely nothing about it? This apparent paradox resolves once we make it more clear what does it even mean to reveal nothing about .
First, let's start by making clear "what" should not reveal information about . Take an interactive probabilistic proof between a prover and a verifier:
Prover Verifier
─┬─ ─┬─
│ │
├-------m1----->│
│ │
│<------m2------┤
│ │
└-------m3----->│
│
V
accept or reject
The messages are called the transcript of the protocol. We usually suppose[3] that this is public, meaning that anyone can read any message of the transcript. This is precisely "what" should not be revealing information. We want to somehow mathematically guarantee that anyone obtaining the transcript learns nothing about .
Next, we formalize what does it mean to "not leak information".
There is an interesting and natural way to formalize the meaning of "information" through objects called "predicates". This is, however, not the approach that we will actually be using, we will instead use a different approach described in the next section. Nevertheless...
In order to understand what a predicate is, we give the following intuition of what "information about a witness " is. Recall that the witness was the secret part of the claim. For example, in the identity certification examples, the witness was the credentials or password associated to the identity. We can say that
"having information about " means being able to respond to some true-or-false questions about .
If we use the convention that 0 = false, 1 = true, we can formalize a true-or-false question about as some function which takes some witness as its input and outputs either 0 or 1. Here are some examples of possible true-or-false questions about credentials .
A predicate is precisely a true-or-false question on , that is a function which takes a witness as input and outputs either 0 or 1.
It would be tempting to say that "having information about " means that there exist a predicate p for which we know the answer. Howerver this quickly runs into issues: for example, if we take the predicate from before, we are always able to know its answer for any input, even when we know absolutely nothing about its input.
Some predicates are naturally harder to guess without knowing , some predicates are naturally easier to guess without knowing , and there's nothing we can do about it. What we would like to capture as "information" is the ability of being able to answer to predicates better than at random: if we can guess the answer of a predicate on the witness better than we can guess the answer of the same predicate on a random input, then must not appear completely random to us, hence we must know something about .
Hence, we define "having information about " as follows: an individual has information about if there exist predicates to which they can guess the answer better than at random.
This makes it pretty easy to prove that a transcript does leak information: just exhibit a predicate for which the probability of guessing correctly is , and show that by inspecting the messages one can guess the answer with probability is greater than .
However, this makes it a bit more complicated to show that a transcript does not leak information: we should somehow show that for any predicate, no matter the information we extract from , the probability of guessing correctly remains unchanged.
For this reason, we don't actually use predicates to formalize the leakage of information. Instead, we use a property called "indistinguishability": we will first exhibit something that logically cannot leak any information, and then show that the transcript can be indistinguishable from it.
If it quacks like a leak...
The duck test is an expression that goes:
"if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck."
We take inspiration from this old adage to solve our definition issue: since our goal is to give a useful definition for what does not leak information, we start by exhibiting something that does not leak information, and then we say that if the transcript is indistinguishable from it, then the transcript too does not leak information.
First, we make an important observation on what we are asking. It is possible that whatever is already publicly known prior to the protocol (for example ) already leaks information about . For example, in the identity credentials case, if the credentials were chosen to be the initials of the person, then would be completely obtainable from (which is public) without even needing any transcript of any proof. This means that by "not leaking information" we actually mean not leaking more information than what is already publicly available. We can't do anything about any prior leakage (which would be a credentials design failure rather than a proof failure), we can only make sure that the transcript of the proof doesn't make things worse.
This gives a natural candidate for something that does not leak information: anything that is obtained only from what is already public leaks no (additional) information on . To be more precise, if is a publicly known algorithm and is the public value of the claim, then cannot possibly leak any additional information on no matter what does, hence we say that doesn't leak any information.
Now that we have defined what a duck "not-leaking" looks like, we would like to show that the transcript of the proof looks like something that doesn't leak information. One way of doing this is to exhibit a public algorithm , which we'll call "simulator", that can produce fake but identical-to-the-real-ones transcripts. Then we can argue that the real transcript does not leak any information, in the following way:
Suppose that a malicious actor reads the transcript. Since the simulated transcripts are indistinguishable from the real ones, the malicious actor has no way to know if the transcript is real or simulated. However, by design, the simulated transcript cannot possibly leak any information about , because it is generated without knowing . Since the simulated transcript does not leak information, and the simulated transcript are indistinguishable from the real ones, then the real ones must also not leak any information (otherwise the malicious actor would have a way to distinguish them). Since the malicious actor can't tell them apart and can also not learn anything from the simulated one, it must also be unable to learn anything about from the real one.
We can now give a definition for the zero-knowledge property
Definition (zero-knowledge)
An interactive probabilistic proof is zero-knowledge (i.e: doesn't leak any information about the secret values) if its transcript can be perfectly simulated by a public simulator algorithm
Again, if you're paying close attention, you might be wondering:
- how can a simulator produce a valid response to the challenge, if we supposed that the challenge was hard-to-respond-to without knowing the witness ?
- how can a simulator generate a transcript that requires the witness , without knowing ? (for example in the sudoku case, producing both the locked solution and the keys to unlock two digits, which in turns reveals two of the solution's digits)
The first issue is easily solved: the challenge is difficult to respond to only once the commitment is fixed. However, since the simulator is the one producing the transcript, it can decide the content of the messages in any order: first, it decides the challenge and a response, then it decides some commitment which makes the response correct. This is the exact same trick that made the magic show less impressive if the number was written after the challenge was issued.
The second issue is solved with a bit more care. The standard solution is to disguise or camouflage the contents of the messages with some random noise.
Achieving "- of knowledge"
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua