This study focuses on zk-SNARK, which stands for Zero-Knowledge Succinct Non-Interactive Argument of Knowledge. zk-SNARK has three properties: completeness, soundness, and zero-knowledge. The study also discusses arithmetic circuits, rank-1 constraints, quadratic arithmetic programs, homomorphic encoding, and pairing functions. It explains the general reduction from arithmetic circuits to quadratic arithmetic programs. Overall, zk-SNARK allows for the verification of computations without revealing any information about the prover's witness.
A study notes on zk-SNARK, mainly focusing on the equations in zk-SNARK.
ZK-SNARK stands for Zero-Knowledge Succinct Non-Interactive Argument of Knowledge.
Three properties of zk-SNARK
Completeness: Every statement with a valid witness has a proof that convinces the verifier.
Soundness: A statement with an invalid witness does not have a proof that convinces the verifier.
Zero-knowledge: The proof only conveys information about the validity of the statement and nothing about the prover’s witness.
Arithmetic circuits is a model for computing polynomials. For a finite field F={0,⋯,p−1} (prime p>2), arithmetic circuitsC:Fn→F is a direct acyclic graph (DAG) where nodes are addition and multiplication gates and edges are wires. Each node in DAG has two input and output. The DAG has one final output.
In a m-gate, n-wire arithmetic circuit, a witness is defined as s=(s1,s2,⋯,sn), where si is the value of i-th wires.
Rank-1 constraints (R1CS) is defined as follows: for some constants {ui,q,vi,q,wi,q}1≤i≤n,1≤q≤m, ∑i=1nsiui,q⋅∑i=1nsivi,q=∑i=1nsiwi,q. For example, in Figure 1, s1⋅s2=s4 is a R1CS, where u1,1=1,v2,1=1,w4,1=1, others =0.
First, we define the target points as r1,r2,⋯,tm∈Fp. Each target point corresponds to a gate in the arithmetic circuit. Then, we define the vanishing function t(x)=Πq=1m(x−rq) such that t(x)=0 at targets points r1,r2,⋯,tm.
A quadratic arithmetic program is a relation over s=(s1,s2,⋯,sn) such that ∑i=1nsiui(x)⋅∑i=1nsivi(x)−∑i=1nsiwi(x)≡0(modt(x)), where ui(x),vi(x),wi(x) is degree m−1 polynomials such that for 1≤i≤n,1≤q≤m, ui(rq)=ui,q, vi(rq)=vi,q and wi(rq)=wi,q.
When x=rq, this equation is the qth gate’s R1CS. Thus, checking this equation is equivalent to checking the m rank-1 constraints simultaneously
Homemorphic encoding is an injective homomorphism E:Fp→G such that it’s hard to find x given E(x).
For example, given a cyclic group G of prime order p, with g as generator and multiplication as group operation, a homomorphic encoding is E(a)=ga. It’s homomorphic and injective. Also, by the hardness of the discrete logarithm problem, it is also hard to find x given E(x).
For any NP-computation that a prover and a verifier both agree on beforehand, they can construct an arithmetic circuit for thie computation such that a witness for this circuit is a witness for the original computation. An arithmetic circuit can be reduced to a QAP such that verifying a witness for the QAP is equivalent to a witness for the arithmetic circuit. Thus, verifying a witness for the QAP equals to verifying a witness for original computation.
For a arithmetic circuit with m-gates and n-wires, a witness is defined as s=(s1,s2,⋯,sn)∈Rn. A R1CS (ai,bi,ci) for s is defined as (s⋅ai)×(s⋅bi)−s⋅ci=0, where 1≤i≤m and ai,bi,ci∈Rn.
A general reduction consists of three steps:
stack the m constraints vectors to obtain matrices A,B,C∈Rm×n, where
Thus, checking (∑i=1nsiui(x))⋅(∑i=1nsivi(x))−(∑i=1nsiwi(x))=h(x)t(x) is equivalent to checking the the R1CS relations in the arithmetic circuit. That is, the witness can satisfy all R1CS relation in each node.
Pinocchio protocol is an implementation for zk-SNARK.
The protocol is built on a group G of prime order p with a generator g. Define the homomorphic encoding as E:Fp→G, E(x)=gx. Define a elliptic curve bilinear map as e:G×G→GT. The prover knows a witness {si}i=1n and he can get the following equation by reduction: (∑i=1nsiui(x))⋅(∑i=1nsivi(x))−(∑i=1nsiwi(x))=h(x)t(x).
The main idea are as follows:
V tests P at a random point z∈Fp for the polynomials
P computes u(z)=∑i=1nsiui(z),v(z)=∑i=1nsivi(z),w(z)=∑i=1nsiwi(z) and h(z) and homomorphically encodes these values and send them to V
V can verify that the homomorphically encoded values satisfy the same equation without learning the witness itself.
The Pinocchio protocol consists of three steps: (1) Trusted third party generates a common reference string (CRS); (2)Prover generates proofs; (3)Verifier checks proofs and decides to accept or reject.
In the CRS generation process, the trusted third party picks random α,βu,βv,βw,γ,z∈Fp∗ and publishs the CRS. Then, the trusted third party discards all of the sampled group elements used in its generation (the toxic waste). The CRS consists of evaluation key for the prover and verification key for the verifier.
In the proof generation process, since the prover knows the polynomials (∑i=1nsiui(x))⋅(∑i=1nsivi(x))−(∑i=1nsiwi(x))=h(x)t(x), he will first computes h(x). Then, the prover generates proof using the evaluation key as follows:
In the proof verification process, the verifier will conduct three verifications.
First, the verifier checks that the terms u(z),v(z),w(z),h(z) were constructed as linear combinations of terms in the CRS by checking the following equations:
e(E(u(z)),E(αu1(z)))=e(E(αu(z)),E(u1(z)))
e(E(v(z)),E(αv1(z)))=e(E(αv(z)),E(v1(z)))
e(E(w(z)),E(αw1(z)))=e(E(αw(z)),E(w1(z)))
e(E(h(z)),E(α))=e(E(αh(z)),E(1))
Then, the verifier checks that each term u(z),v(z),w(z) were generated using the same linear coefficients, {si}i=1n, that is check whether u(z)=∑i=1nsiui(z),v(z)=∑i=1nsivi(z),w(z)=∑i=1nsiwi(z)
i.e. e(E(u(z)),E(v(z)))/e(E(w(z)),E(1))=e(E(t(z)),E(h(z)))
i.e. checks (∑i=1nsiui(x))⋅(∑i=1nsivi(x))−(∑i=1nsiwi(x))=h(x)t(x)
The verifier will accept if all checks hold.
Since now, the process is not zero-knowledge. If V comes up with their own witness s′=(s1′,s2′,⋯,sn′), they can compute E(u′(z)),E(v′(z)),E(w′(z)),E(h′(z)). If these values are different from E(u(z)),E(v(z)),E(w(z)),E(h(z)), then the verifier concludes that the prover’s witness is not s′
Zero knowledge can be achieved by adding a random shift to the polynomials u,v,w. The random shift will be a multiple of t(x), so that everything is still the same modt(x). For random δ1,δ2,δ3∈Fp, the shifted polynomials is defined as
uz(x)=u(x)+δ1t(x)
vz(x)=v(x)+δ2t(x)
wz(x)=w(x)+δ3t(x)
Then, P will replace the unshifted terms with the shifted terms in its proof. For example, E(uz(x))=E(u(x)+δ1t(x))=E(u(x))E(δ1t(x))
Groth-16 protocol is a more succinct implementation for zk-SNARK. Both the proof size and the verifier complexity is significantly lower than Pinocchno in Groth-16.
In Growth-16, since the prover knows the polynomial (∑i=1nsiui(x))⋅(∑i=1nsivi(x))−(∑i=1nsiwi(x))=h(x)t(x), the proof is defined as follows:
E(α+u(z))
E(β+v(z))
E(∑si×(βui(z)+αvi(z)+wi(z))+h(z)t(z))
The verifier will checks: e(E(α+u(z)),E(β+v(z)))=e(E(∑si×(βui(z)+αvi(z)+wi(z))+h(z)t(z)),E(1))e(E(α),E(β))