Zero Knowledge proofs explained !

DefiLever
7 min readDec 7, 2021

November 2019

The Ali Baba cave

There is a well-known story presenting the fundamental ideas of zero-knowledge proofs, first published by Jean-Jacques Quisquater and others in their paper “How to Explain Zero-Knowledge Protocols to Your Children”.

It is common practice to label the two parties in a zero-knowledge proof as Peggy (the prover of the statement) and Victor (the verifier of the statement).

In this story, Peggy has uncovered the secret word used to open a magic door in a cave. The cave is shaped like a ring, with the entrance on one side and the magic door blocking the opposite side. Victor wants to know whether Peggy knows the secret word; but Peggy, being a very private person, does not want to reveal her knowledge (the secret word) to Victor or to reveal the fact of her knowledge to the world in general.

They label the left and right paths from the entrance A and B. First, Victor waits outside the cave as Peggy goes in. Peggy takes either path A or B; Victor is not allowed to see which path she takes. Then, Victor enters the cave and shouts the name of the path he wants her to use to return, either A or B, chosen at random. Providing she really does know the magic word, this is easy: she opens the door, if necessary, and returns along the desired path.

However, suppose she did not know the word. Then, she would only be able to return by the named path if Victor were to give the name of the same path by which she had entered. Since Victor would choose A or B at random, she would have a 50% chance of guessing correctly. If they were to repeat this trick many times, say 20 times in a row, her chance of successfully anticipating all of Victor’s requests would become vanishingly small (1 in 220, or very roughly 1 in a million).

Thus, if Peggy repeatedly appears at the exit Victor names, he can conclude that it is extremely probable that Peggy does, in fact, know the secret word.

One side note with respect to third-party observers: even if Victor is wearing a hidden camera that records the whole transaction, the only thing the camera will record is in one case Victor shouting “A!” and Peggy appearing at A or in the other case Victor shouting “B!” and Peggy appearing at B. A recording of this type would be trivial for any two people to fake (requiring only that Peggy and Victor agree beforehand on the sequence of A’s and B’s that Victor will shout). Such a recording will certainly never be convincing to anyone but the original participants. In fact, even a person who was present as an observer at the original experiment would be unconvinced, since Victor and Peggy might have orchestrated the whole “experiment” from start to finish.

Further notice that if Victor chooses his A’s and B’s by flipping a coin on-camera, this protocol loses its zero-knowledge property; the on-camera coin flip would probably be convincing to any person watching the recording later. Thus, although this does not reveal the secret word to Victor, it does make it possible for Victor to convince the world in general that Peggy has that knowledge — counter to Peggy’s stated wishes. However, digital cryptography generally “flips coins” by relying on a pseudo-random number generator, which is akin to a coin with a fixed pattern of heads and tails known only to the coin’s owner. If Victor’s coin behaved this way, then again it would be possible for Victor and Peggy to have faked the “experiment”, so using a pseudo-random number generator would not reveal Peggy’s knowledge to the world in the same way that using a flipped coin would.

Notice that Peggy could prove to Victor that she knows the magic word, without revealing it to him, in a single trial. If both Victor and Peggy go together to the mouth of the cave, Victor can watch Peggy go in through A and come out through B. This would prove with certainty that Peggy knows the magic word, without revealing the magic word to Victor. However, such a proof could be observed by a third party, or recorded by Victor and such a proof would be convincing to anybody. In other words, Peggy could not refute such proof by claiming she colluded with Victor, and she is therefore no longer in control of who is aware of her knowledge.

Two balls and the colour-blind friend

Imagine your friend is red-green colour-blind (while you are not) and you have two balls: one red and one green, but otherwise identical. To your friend they seem completely identical and he is skeptical that they are actually distinguishable. You want to prove to him they are in fact differently-coloured, but nothing else; in particular, you do not want to reveal which one is the red and which is the green ball.

Here is the proof system. You give the two balls to your friend and he puts them behind his back. Next, he takes one of the balls and brings it out from behind his back and displays it. He then places it behind his back again and then chooses to reveal just one of the two balls, picking one of the two at random with equal probability. He will ask you, “Did I switch the ball?” This whole procedure is then repeated as often as necessary.

By looking at their colours, you can, of course, say with certainty whether or not he switched them. On the other hand, if they were the same colour and hence indistinguishable, there is no way you could guess correctly with probability higher than 50%.

Since the probability that you would have randomly succeeded at identifying each switch/non-switch is 50%, the probability of having randomly succeeded at all switch/non-switches approaches zero (“soundness”). If you and your friend repeat this “proof” multiple times (e.g. 100 times), your friend should become convinced (“completeness”) that the balls are indeed differently coloured.

The above proof is zero-knowledge because your friend never learns which ball is green and which is red; indeed, he gains no knowledge about how to distinguish the balls.

Where’s Wally?

Where’s Wally? (titled Where’s Waldo? in North America) is a picture book where the reader is challenged to find a small character called Wally hidden somewhere on a double-spread page that is filled with many other characters. The pictures are designed so that it is hard to find Wally.

Imagine that you are a professional Where’s Wally? solver. A company comes to you with a Where’s Wally? book that they need solved. The company wants you to prove that you are actually a professional Where’s Wally? solver and thus asks you to find Wally in a picture from their book. The problem is that you don’t want to do work for them without being paid.

Both you and the company want to cooperate, but you don’t trust each other. It doesn’t seem like it’s possible to satisfy the company’s demand without doing free work for them, but in fact there is a zero-knowledge proof which allows you to prove to the company that you know where Wally is in the picture without revealing to them how you found him, or where he is.

The proof goes as follows: You ask the company representative to turn around, and then you place a very large piece of cardboard (several times larger than the book) over the picture in the book such that the center of the cardboard is positioned over Wally. You cut out a small window in the center of the cardboard such that Wally is visible. You can now ask the company representative to turn around and view the large piece of cardboard with the hole in the middle, and observe that Wally is visible through the hole. The cardboard is large enough that the company rep cannot determine the position of the book under the cardboard. You then ask the representative to turn back around so that you can remove the cardboard and give back the book.

As described, this proof is an illustration only, and not completely rigorous. The company representative would need to be sure that you didn’t smuggle a picture of Wally into the room. Something like a tamper-proof glovebox might be used in a more rigorous proof. The above proof also results in the body position of Wally being leaked to the company representative, which may help them find Wally if his body position changes in each Where’s Wally? puzzle.

Definition

A zero-knowledge proof must satisfy three properties:

  1. Completeness: if the statement is true, the honest verifier (that is, one following the protocol properly) will be convinced of this fact by an honest prover.
  2. Soundness: if the statement is false, no cheating prover can convince the honest verifier that it is true, except with some small probability.
  3. Zero-knowledge: if the statement is true, no verifier learns anything other than the fact that the statement is true. In other words, just knowing the statement (not the secret) is sufficient to imagine a scenario showing that the prover knows the secret. This is formalized by showing that every verifier has some simulator that, given only the statement to be proved (and no access to the prover), can produce a transcript that “looks like” an interaction between the honest prover and the verifier in question.

The first two of these are properties of more general interactive proof systems. The third is what makes the proof zero-knowledge.

Zero-knowledge proofs are not proofs in the mathematical sense of the term because there is some small probability, the soundness error, that a cheating prover will be able to convince the verifier of a false statement. In other words, zero-knowledge proofs are probabilistic “proofs” rather than deterministic proofs. However, there are techniques to decrease the soundness error to negligibly small values.

A formal definition of zero-knowledge has to use some computational model, the most common one being that of a Turing machine.

--

--

DefiLever

Cross Chain Yield Optimizer | Decentralized Open Financial System