Back to Home

Explanation of SNARKs. Homomorphic hiding and blind polynomial computation (translation)

zk-snarks · translation · cryptocurrency · cryptography · information protection · mathematics

Explanation of SNARKs. Homomorphic hiding and blind polynomial computation (translation)

Original author: Ariel Gabizon
  • Transfer
Hello, Habr! I present to you the translation of ZCash blog articles, which describe the mechanism of operation of the zero-disclosure evidence system SNARKs used in ZCash cryptocurrency (and not only).

My previous translations from this area. I advise you first to familiarize yourself with them in order to better understand what will be discussed:


In this part, we look at homomorphic hiding and blind computation of polynomials. Go…

Homomorphic Hiding


The designs of zk-SNARKs include a harmonious combination of several components. To fully understand how these components work together, it will take enough time.

If I had to choose only one component, the role of which is most noticeable, then I would single out the Homomorphic Hiding (HH). In this part of the article we will explain what a GS is, and then we will give an example of why it is useful and we will analyze how it is arranged.
Homomorphic concealment is not a term formally used in cryptography, and is introduced here for didactic purposes. In terms of properties, it is similar, but weaker than the well-known concept of “ obligation scheme ”. The difference is that the HS is a function that defines the argument, while the obligation takes extra randomness. As a result, homomorphic hides essentially “hide the majority of x”, while obligations “hide every x”.

HS $ E (x) $ numbers x is a function satisfying the following properties:

  • For most x, with a known value $ E (x) $ finding x is a difficult task.
  • Different argument values ​​result in different function values. Therefore, if$ x ≠ y $then $ E (x) ≠ E (y) $
  • If anyone knows $ E (x) $ and $ E (y) $then it can generate HS from arithmetic operations for x and y . For example, it can calculate$ E (x + y) $knowing $ E (x) $ and $ E (y) $.

A simple example of why GS is useful for zero-knowledge proofs: suppose Alice wants to prove to Bob that she knows the numbers x, y such that $ x + y = 7 $(Of course, this is not particularly interesting, to know such x and y , but this is a good example to explain the concept).

  1. Alice sends $ E (x) $ and $ E (y) $ To bob.
  2. Bob is calculating $ E (x + y) $ of these values ​​(he can do this because $ E $ is HS).
  3. Bob also calculates $ E (7) $ and now checks if $ E (x + y) = E (7) $. He accepts Alice's proof only if equality holds.

Since the different values ​​of the arguments $ E $ correspond to different hides (function values $ E $. Note translator), Bob really only accepts proof if Alice sent the hide for$ x, y $such that $ x + y = 7 $. Bob, on the other hand, gets no value$ x, y $, since he only has access to their hides.
Yet Bob got some information about $ x $ and $ y $. For example, he may choose random$ x '$ and check if equality holds $ x = x '$ calculation $ E (x ') $. For this reason, the above protocol is not really a Zero-Knowledge protocol, and is used here only to explain the scheme. In fact, as we will see later, the HS is ultimately used in SNARKs to mask the verifier’s requests, not the evidential secrets.

Now let's look at an example of how such hides are arranged. In fact, we cannot construct them for regular integers with regular additions; instead, we need to consider finite groups :

Let n be some integer. When is it written$ A \ mod \ n $for an integer A , it means taking the remainder of dividing A by n . For instance,$ 9 \ mod \ 7 = 2 $ and $ 13 \ mod \ 12 = 1 $. You can also use$ mod \ n $to determine the addition operation on the set {0, ..., n - 1} . Normal addition is done first, but then applied$ (mod \ n) $to the result to get the number in the set {0, ..., n - 1} . Sometimes$ (mod \ n) $is written to the right of the expression, specifying that this type of addition is used. For instance,$ 2 + 3 = 1 \ (mod \ 4) $. We will call the set of elements {0, ..., n - 1} together with the addition operation the group$ Z_n $.

For prime p , you can use$ mod \ n $to determine the operation of multiplication on the set {1, ..., p - 1} , so that the result of the multiplication also always enters the set {1, ..., p - 1} . This is achieved by the usual multiplication of integers, and then applying to the result$ mod \ p $. For instance,$ 2 ⋅ 4 = 1 \ (mod \ 7) $.
When p is not simple, it is problematic to determine the multiplication in this way. One of the problems is that the result of the multiplication can be equal to zero, even if both arguments are not equal to zero. For example, when p = 4 , we can get$ 2 * 2 = 0 \ (mod \ 4) $.

A set of elements along with this operation is called a group. $ Z ^ * _ p $. This group has the following useful properties:

  1. This is a cyclic group. This means that there exists some element g in$ Z ^ * _ p $called a generator such that all elements $ Z ^ * _ p $ can be written as $ g ^ a $for some a from the set {0, ..., p - 2} , where$ g ^ 0 = 1 $
  2. Discrete logarithms must be hard to do for $ Z ^ * _ p $. This means that when p is large enough and an element h from$ Z ^ * _ p $, then it is difficult to find an integer a from the set {0, ..., p - 2} such that$ g ^ a = h \ (mod \ p) $
  3. Since the degrees add up when multiplying elements with the same base, we get for a, b from the set {0, ..., p - 2} :$ g ^ a * g ^ b = g ^ {a + b \ (mod \ p-1)} $

Using these properties, we now construct a homomorphic hiding that “supports addition”, which means that it can be calculated $ E (x + y) $ knowing $ E (x) $ and $ E (y) $. Suppose the argument x for$ E $ belongs to the group $ Z_ {p-1} $therefore it is in the range {0, ..., p - 2} . Define$ E (x) = g ^ x $for each such x , and prove that$ E $ is a GS: from the first property it follows that different $ x '$ of $ Z_ {p-1} $different function values ​​will correspond. From the second property it follows that for$ E (x) = g ^ x $it is difficult to find x . Finally, using the third property, for given$ E (x) $ and $ E (y) $we can calculate $ E (x + y) $ as $ E (x + y) = g ^ {x + y \ mod \ p-1} = E (x) ⋅ E (y) $.

Blind polynomial computation


Now let's recall what the concept of a polynomial is, introduce the concept of “blind computation” of a polynomial, and how it is realized using homomorphic concealment (HS). We will see later that blind computing is the central tool in SNARK constructs.

Denote by$ F_p $field of size p , i.e., elements$ F_p $belong to the set {0, ..., p - 1} , where the operations of addition and multiplication are performed with$ mod \ n $ as explained above.

Polynomials and linear combinations


Recall that a polynomial P of order d on a field$ F_p $ is an expression of the form:

$ P (X) = a_0 + a_1 * X + a_2⋅ X ^ 2 + ... + a_d⋅ X ^ d $

for some $ a_0, ..., a_d ∈ F_p $,

We can calculate the value of P point$ s ∈ F_p $substituting s as X , and calculating the resulting amount:

$ P (s) = a_0 + a_1⋅ s + a_2⋅ s ^ 2 + ... + a_d⋅ s ^ d $

For one who knows what $ P $, value $ P (s) $ is a linear combination of values $ 1, s, ..., s ^ ​​d $ where the linear combination is understood as the "weighted sum", in the case $ P (s) $ “Weights” are $ a_0, ..., a_d $

Above we determined the HS from $ E $ as $ E (x) = g ^ x $, where g is the generator of a group with a difficultly performed discrete logarithm problem. We mentioned that this GS “supports addition” in the sense that$ E (x + y) $ can be calculated knowing $ E (x) $ and $ E (y) $. We also note that it “supports linear combinations”. This means that for given$ a, b, E (x), E (y) $we can calculate $ E (ax + by) $This can be easily shown:
$ E (ax + by) = g ^ {ax + by} = g ^ {ax} * g ^ {by} = (g ^ x) ^ a * (g ^ y) ^ b = E (x) ^ a * E (y) ^ b $

Blind polynomial computation


Suppose Alice has a polynomial P of order d , and Bob has a value$ s ∈ F_p $which he randomly selected. Bob wants to know$ E (P (s)) $, i.e. value of HS P at point s . There are two easy ways to do this:

  • Alice sends P to Bob and he calculates$ E (P (s)) $ myself.
  • Bob sends s to Alice and she figures$ E (P (s)) $ and sends it to Bob.

However, in the case of blind computing, we want Bob to find out $ E (P (s)) $ without receiving $ P $- which excludes the first option. And most importantly, we don’t want Alice to recognize s , which excludes the second option.
The main reason we don’t want to send $ P $ Bob, just consists in the fact that he is big - he contains $ (d + 1) $elements where d ~ 2,000,000 in the current Zcash protocol. In essence, this is due to the "limited" part of SNARK.

Using the GS, we can perform a blind calculation as follows:

  1. Bob sends hiding to Alice $ E (1), E (s), ..., E (s ^ d) $
  2. Alice calculates $ E (P (s)) $ of the items sent in the first step and sends $ E (P (s)) $To bob. (Alice can do this because$ E $ supports linear combinations, and $ P (s) $ is a linear combination $ 1, s, ..., s ^ ​​d $)

Of course, it is true that the sequence of concealments that Bob sends to Alice is as long as the polynomial itself, but it turns out that this sequence can be “hard-coded” in the system parameters, and Alice’s messages will differ for each SNARK proof

Please note that only hide were sent, while Alice did not recognize s , and Bob did not recognize P .
In fact, the hiding property only guarantees that s cannot be obtained, with knowledge$ E (s) $. Moreover, we also need that s cannot be obtained, knowing the sequence$ E (s), ..., E (s ^ d) $, which potentially contains much more information about s . The solution to this problem follows from the Diffie-Hellman d-order solution, which is used in several SNARK security proofs. (the complexity of discrete logarithms. Note translator)

Why is this useful?


The following sections will examine in more detail how blind computing is used in SNARK. Speaking roughly, the verifier has the idea of ​​a “correct” polynomial and wants to verify that the prover knows it. When the prover performs blind calculations at a random point not known to both of them, this ensures that the prover will give the wrong answer with a high probability if their polynomial is incorrect. This, in turn, is based on the Schwarz-Zippel lemma that “different polynomials are different at most points”.

Part 2. Explanation of SNARKs. Knowledge of the adopted coefficient and reliable blind calculation of polynomials

Read Next