📜 ⬆️ ⬇️

Explanation of SNARKs. From calculations to polynomials, the Pinocchio protocol and the pairing of elliptic curves (translation)

Hi, Habr! I present to your attention the translation of ZCash blog articles, which describe the mechanism of the evidence system with zero disclosure of SNARKs used in the ZCash cryptocurrency (and not only).

Source: https://z.cash/blog/snark-explain5.html

Previous articles:
')
Part 1: Explaining SNARKs. Homomorphic hiding and blind computation of polynomials (translation)
Part 2: Explaining SNARKs. Knowledge of the adopted coefficient and reliable blind calculation of polynomials (translation)

Introduction from the translator


Starting the final part of the translation, I want to say that we live in a truly amazing time. The time when higher mathematics has the ability to almost immediately be involved in software development and we can observe “in action” the results of the work of mathematicians of technological institutes in advanced things based on blockchains and data exchanges.

Well, I will not detain further your attention, let's move on to the most interesting ...

From calculations to polynomials


In previous articles we have developed a specific mechanism for working with polynomials. In this part, we will learn how to transform the statements we want to prove and verify in the language of polynomials. The idea of ​​using polynomials in this way begins with the pioneering work of 1991 by Lund, Fortwon, Karloff and Nisan (Carsten Lund, Lance Fortnow, Howard Karloff - University of Chicago AND Noam Nisan - Hebrew University).

In 2013, another yet another breakthrough work by Gennaro, Gentry, Parno and Raikova (Rosario Gennaro, Craig Gentry, Bryan Parno, Mariana Raykova) comes out. This work identified extremely convenient transformations of computations into polynomials called the Quadratic Arithmetic Program (QAP). KAP became the basis for modern zk-SNARK constructions, in particular, those used in ZCash cryptocurrency.

In the first part of the article, the transformations of the calculations in the CAP will be explained by example. Even if you focus on a small example, and not on a general definition, you have to spend enough time to understand it to begin with. So be prepared for a certain mental effort :)

Suppose Alice wants to prove to Bob that he knows c1,c2,c3Fpsuch that (c1c2)(c1+c3)=7. The first step is to present the calculation with c1,c2,c3in the form of an arithmetic circuit.

Arithmetic schemes


An arithmetic circuit consists of calculated arithmetic operations, called transitions, such as addition and multiplication, with connections between them. In our case, the scheme looks like this:
image

The bottom connectors are input parameters, and the top output connection is the result of calculating the entire circuit for these input parameters.

As can be seen in the figure, connectors and transitions of the circuit are designated in a certain way. These rules will be necessary for the next step, namely the transfer of the scheme in the CAP:


A valid assignment set for the scheme is the assignment of values ​​for labeled transitions, where the output value of each multiplication transition is the result of the product of the corresponding inputs.

So, for our scheme, the valid assignment set is: (c1,...,c5)Where c4=c1c2and c5=c4(c1+c3)

Following this terminology, Alice wants to prove that she knows a valid assignment set (c1,...,c5)such that c5=7. The next step is to translate this statement into a polynomial using CAP.

CAP


Each transition multiplication must be correlated with the field element: g1will be correlated with 1Fpand g2with 2Fp. We call the points {1, 2} our target points . Now we need to define a set of "left connecting polynomials" L1,...,L5, "Right connective polynomials" R1,...,R5and "output connecting polynomials" O1,...,O5.

The main idea of ​​this action is to ensure that the values ​​of the polynomials are zero at all target points, except the target point of the multiplication transition, in which they are involved.

Speaking specifically, since w1,w2,w4left, right and output connectors respectively g1can define L1=R2=O4=2Xsince the polynomial 2Xequals one at point 1 corresponding g1and is zero at point 2 corresponding g2.

notice, that w1and w3both are right inputs g2. Therefore, similarly, we define L4=R1=R3=O5=X1, because X1equals one at target point 2 corresponding g2and zero at another target point.

Denote all other polynomials as zero polynomials.

With fixed values (c1,...,c5)they are used as coefficients for determining the left, right, and output "total" polynomials. That is, you can determine:

$ inline $ L: = Σ ^ 5_ {i = 1} c_i⋅L_i, R: = Σ ^ 5_ {i = 1} c_i⋅R_i, O: = Σ ^ 5_ {i = 1} c_i⋅O_i $ inline $

Then we define the polynomial P:=LRO

Now, after all these definitions, we can form a central definition: (c1,...,c5)is a valid scheme assignment set if and only if P takes a zero value at all target points.

Let's see this using our example. Suppose that were defined L,R,O,Pas stated above with some c1,...,c5. Let's calculate all these polynomials at target point 1 :

Of all Lionly L1is non-zero at point 1 . So, L(1)=c1L1(1)=c1. Similarly, we get R(1)=c2and O(1)=c4.

Consequently, P(1)=c1c2c4. Similar can be obtained P(2)=c4(c1+c3)c5.

In other words, P vanishes at target points if and only if (s1,...,c5)is a valid assignment set.

Now we will use the following algebraic fact: for the polynomial P and the point aFpwe have P(a)=0if and only if the polynomial Xadivides P without remainder, i.e. P=(Xa)Hfor some polynomial H.

Having determined the target polynomial in this way: T(x):=(x1)(x2), we obtain that T divides P if and only if (s1,...,c5)is a valid assignment set.

Based on the foregoing, we define the CAP as follows:

The quadratic arithmetic program Q of order d and size m consists of polynomials L1,...,Lm,R1,...,Rm,O1,...,Omand the target polynomial T of order d .

Assignment Set (c1,...,cm)satisfies Q if, defining $ inline $ L: = Σ ^ m_ {i = 1} c_i ⋅ L_i, R: = Σ ^ m_ {i = 1} c_i⋅ R_i, O: = Σ ^ m_ {i = 1} c_i⋅ O_i $ inline $ and P:=LRO, there exists T , which divides without remainder P.

Following this terminology, Alice wants to prove that she knows the set of assignments (c1,...,c5)satisfying the CAP defined above, where c5=7,

Let's summarize this part. We saw a statement like "I know c1,c2,c3such that (c1c2)(c1+c3)=7»Can be translated into an equivalent statement about polynomials using CAP. Next, we will look at an efficient protocol for confirming knowledge of a valid set of CAP assignments.
Above, we tried to give a fairly short example of the cast in the CAP. We also recommend an excellent post by Vitalik Buterin for more detailed information on the program conversion to CAP.

Pinocchio Protocol


Earlier, we showed that the statement that Alice wants to prove to Bob can be transformed into an equivalent form in the "language of polynomials," called the Quadratic Arithmetic Program (CAP).

In this section, we describe how Alice can send a fairly short proof to Bob, showing that she has a valid assignment set for CAP. We will use the Pinocchio Protocol developed by Parno, Howell, Gentry and Raykova (Bryan Parno, Jon Howell, Craig Gentry, Mariana Raykova).

As given above, Alice wants to prove that she has a valid assignment set, which has some additional restrictions, for example cm=7. But we will not take this into account here and, for simplicity, we will show how easy it is to prove knowledge of some admissible assignment set.

If Alice has a valid assignment set, it means that if you define L,R,O,Pas described above, then there exists a certain polynomial H such that P=HT. In particular, for any sFpwe have P(s)=H(s)T(s).

Suppose now that Alice has no valid assignment set, but she also defines L,R,O,Pfrom some invalid set (c1,...,cm). Then you can be sure that T does not divide P. This means that for any polynomial H in the order not higher than d , P and HTwill be different polynomials. Note that P and HTthere are no higher order 2d.

For the proof, we use the well-known Schwarz-Zippel lemma, which states that two different polynomials of degree not higher than 2dmay intersect at most 2dpoints sFp. Thus, if p is much larger 2dthe probability that P(s)=H(s)T(s)for a random selection sFpinsignificant.

Based on this, you can create the following protocol sketch to check whether Alice has a valid assignment set:

  1. Alice selects polynomials L,R,O,Horder not higher than d .
  2. Bob picks a random point sFpand calculates the hiding E(T(s)).
  3. Alice sends Bob a hide for these polynomials at point s , namely E(L(s)),E(R(s)),E(O(s)),E(H(s)).
  4. Bob checks whether the required equality holds at s . That is, he checks E(L(s)R(s)O(s))=E(T(s)H(s))

Repeating again, if Alice does not have a valid assignment set, she will eventually use polynomials with which the required equality for the majority of randomly chosen s will not hold. Therefore, Bob is more likely to reject Alice’s answer, regardless of the chosen s .

Let's think, do we have the tools to implement this sketch? An important point is the choice of Alice polynomials, which she will use, while not knowing s . But this is exactly the problem that we solved in a reliable blind calculation of polynomials described in the previous article .

Given this, there are still four main points that need to be resolved in order to turn this sketch into a zk-SNARK. The first two we will look at in this article, and the other two in the final article.

The confidence that Alice selects her polynomials according to the assignment set


Important point: if Alice does not have a valid assignment set, this does not mean that she cannot find any polynomials. L,R,O,Horder not higher than d , for which LRO=TH. It simply means that it cannot find such polynomials where L,Rand Owere “derived from an assignment set”; namely, that $ inline $ L: = Σ ^ m_ {i = 1} c_i⋅ L_i, R: = Σ ^ m_ {i = 1} c_i⋅ R_i, O: = Σ ^ m_ {i = 1} c_i⋅ O_i $ inline $ for recruitment (c1,...,cm).

The protocol above only ensures that it uses some polynomials. L,R,Oproper order, but does not guarantee that they were created from a valid assignment set. The formal proof is somewhat complicated, so we will give an approximate solution.

Let's combine polynomials L,R,Oin one polynomial F as follows:

F=L+Xd+1R+X2(d+1)O

The meaning of multiplying R by Xd+1and o on X2(d+1)in "not mixing" coefficients L,R,Oin f . Coefficients 1,X,...,Xdin F correspond to L , the following d+1coefficients Xd+1,...,X2(d+1)correspond to R , and the last d+1coefficients correspond to O.

Combine the polynomials in the definition of the CAP in a similar way, defining for each i1,...,mpolynomial Fiwhose first d+1coefficients are coefficients Liand then the coefficients Riand then Oi. That is for everyone i1,...,mwe define a polynomial:

Fi=Li+Xd+1Ri+X2(d+1)Oi

Note that when we sum two Fithen Li,Riand Oi"Summed separately." For example, F1+F2=(L1+L2)+Xd+1(R1+R2)+X2(d+1)(O1+O2).

More generally, suppose we have F=Σi=1mciFifor some set (c1,...,cm). Then we also get $ inline $ L = Σ ^ m_ {i = 1} c_i⋅ L_i, R = Σ ^ m_ {i = 1} c_i⋅ R_i, O = Σ ^ m_ {i = 1} c_i⋅ O_i $ inline $ for the same coefficients (c1,...,cm). In other words, if F is a linear combination Fiit means that L,R,Owere really created from the set.

Therefore, Bob will ask Alice to prove to him that F is a linear combination from Fi. This is done similarly to the protocol for reliable calculation:

Bob chooses random βFpand sends Alice to hide $ inline $ E (β⋅ F_1 (s)), ..., E (β⋅ F_m (s)) $ inline $ . He then asks Alice to send him a hide. E(βF(s)). If she succeeds, the expanded version of Accepted Coefficient knowledge suggests that she knows how to create F , which is a linear combination of Fi.

Adding the “Zero Disclosure” Part - Hiding the Assignment Set


In zk-SNARK, Alice wants to hide all the information about her set assignment. However hide E(L(s)),E(R(s)),E(O(s)),E(H(s)provide some information about recruiting.

For example, given some other satisfying assignment set (c1,...,cm)Bob can calculate the corresponding L,R,O,Hand hide E(L(s)),E(R(s)),E(O(s)),E(H(s)). If they are different from Alice’s answer, he can understand that (c1,...,cm)not Alice's assignment set.

To avoid such leakage of information about its set, Alice hides her set by adding a “random T- offset” for each polynomial, i.e. chooses random $ inline $ δ_1, δ_2, δ_3∈ F ^ * _ p $ inline $ and determines $ inline $ L_z: = L + δ_1⋅ T, R_z: = R + δ_2 T, O_z: = O + δ_3⋅ T $ inline $ .

Let's pretend that L,R,Owere obtained from a satisfying set of assignments. Consequently LRO=THfor some polynomial H. Since we just added a multiple of T everywhere, T also divides LzRzOz. Let's see this:

$ inline $ L_z⋅ R_z- O_z = (L + δ_1⋅ T) (R + δ_2⋅ T) - (O + δ_3 T) $ inline $ $ inline $ = (L ⋅ R - O) + L ⋅ δ_2⋅ T + δ_1⋅ T⋅ R + δ_1δ_2⋅ T ^ 2- δ_3⋅ T $ inline $ $ inline $ = T⋅ (H + L ⋅ δ_2 + δ_1⋅ R + δ_1δ_2⋅ T- δ_3) $ inline $

Thus, defining $ inline $ H_z = H + L ⋅ δ_2 + δ_1⋅ R + δ_1δ_2⋅ T- δ_3 $ inline $ get LzRzOz=THz. Therefore, if Alice uses polynomials Lz,Rz,Oz,Hzinstead L,R,O,H, Bob will always accept her answer.

On the other hand, these polynomials, calculated at sFpprovided that T(s)0(which is almost always for all d and s ), do not contain any information about the valid assignment set. For example, T(s)non-zero and δ1is random. Then δ1T(s)is a random value, so Lz(s)=L(s)+δ1T(s)will not contain any information about L(s)because it is “masked” by this random value.

What is left to consider in the final part?


We approximately showed the Pinocchio protocol scheme, in which Alice can convince Bob that she has a valid assignment set for the CAP, without disclosing information about this set. But there are still two important issues that need to be addressed to get the zk-SNARK:


Both of these issues can be solved using pairs of elliptic curves, which we will discuss in the final part.

Next article: Explaining SNARKs. Mating elliptic curves (translation)

Source: https://habr.com/ru/post/343954/


All Articles