Groth16
Presentation: https://www.youtube.com/watch?v=1upt6GOdYXk
Introduction
Groth16 is a zk-SNARK construction introduced in 2016 by Jens Groth, characterized by its compact proof size of just 3 group elements and exceptionally fast verification speed. It is widely used in frameworks like circom and RISC0.
Background
Quardratic Arithmetic Protocol (QAP)
For a system where the number of instance variables is ℓ+1, the number of witness variables is m−ℓ (thus, the total number of variables is m+1), and the number of constraints is n, R1CS can be represented as follows:

This R1CS system can be reduced to a Quadratic Arithmetic Program (QAP):
where
ai(X): A polynomial such that ai(xj)=Aj,i where 0≤i≤m and 0≤j<n.
bi(X): A polynomial such that bi(xj)=Bj,i where 0≤i≤m and 0≤j<n.
ci(X): A polynomial such that ci(xj)=Cj,i where 0≤i≤m and 0≤j<n.
t(X): Xn−1.
zi: A variable, where 0≤i≤m.
Here, degai(X)=degbi(X)=degci(X)=n−1.
Then we can define h(X) as follows:
Where degh(X)=n−2.
In BKSV20 and GR22 it is shown that for Groth16 there exists potential malleability on the public input unless certain linear independence requirements are met. An easy way to meet these requirements is to add additional constraints zi⋅0=0 for all public inputs. This is done implicitly by the Arkworks and SnarkJS implementations. (it's taken from https://xn--2-umb.com/22/groth16/.) See also https://geometry.xyz/notebook/groth16-malleability!
Protocol Explanation
Key Generation
Sample the toxic wastes α,β,γ,δ,x←$F . They are called toxic wastes which can be used to create fake proofs which will be accepted by the verifier. So they should be discarded right after key generation, or generated through MPC(or Trusted Setup).
Create a verifying key vk.
Create a proving key pk.
Computing h(X)
Create a(X),b(X),c(X):
where Lj(X) are lagrange basis polynomials.
Evaluate a(X),b(X),c(X) on a coset domain:
where gi=(ηω)i. The reason why we compute on a coset domain is avoiding division by zero since t(ωj)=0.
Evaluate h:
Compute h(X):
where L′i(X) are lagrange basis polynomials on a coset domain.
To compute h(X), the costs are:
3 IFFT operations of length n
3 FFT on a coset domain operation of length n
1 evaluations of length n
IFFT on a coset domain operations of length n−2 (This step can be removed by using Jordi's Trick.)
NOTE: (I)FFT operations on a coset domain implicitly include additional linear operations proportional to the domain size. The (I)FFT operations on a coset domain can be removed by using Jordi's Trick.
Proof Generation
Sample r,s←$F and generate the proof π=([A]1,[B]2,[C]1).
where hi are the coefficients of the h(X).
To generate a proof π, the costs are:
For computing [A]1:
1 MSM operation of length m+1 in G1
For computing [B]2:
1 MSM operation of length m+1 in G2
For computing [C]1:
1 MSM operation of length m−ℓ in G1
1 MSM operation of length n−1 in G1
1 MSM operation of length m+1 in G1 (for [B]1)
Jordi's Trick
To compute ∑i=0n−2hi[δxit(x)]1 of the proof efficiently, consider the following setup:
Where ω′ be a 2n-th root of unity and ω an n-th root of unity. These satisfy:
and L′i(X) are lagrange basis polynomials.
Properties of a(X)b(X)−c(X)
∑i=02n−2(a(ω′i)b(ω′i)−c(ω′i))[δL′i(x)]1 can be divided into evaluations at even powers and odd powers.
Evaluation at even powers of ω′: For 0≤j<n, evaluates to zero at even powers of ω′:
This implies:
Evaluation at odd powers of ω′: For 0≤j<n, given p(X)=p0+p1X+⋯+pn−1Xn−1, we can compute the evaluations at odd powers of ω′:
Where p′(X)=p0+p1ω′X+⋯+pn−1ω′n−1Xn−1.
This implies:
Thus, the evaluations of a(X)b(X)−c(X) at odd powers of ω′ can be efficiently computed by combining FFT results of a′(X),b′(X),c′(X).
Optimizing h(X) in the Proving Key
To eliminate the IFFT of h(X), the term {[δxit(x)]1}i=0n−2 in the proving key (pk) is replaced with {[δL′2i+1(x)]}i=0n−2:
Then computing h(X) is performed as follows:
Create a(X),b(X),c(X):
where Lj(X) are lagrange basis polynomials.
Create a′(X),b′(X),c′(X):
where ω′ is 2n-th root of unity.
Evaluate a′(X),b′(X),c′(X):
where ω is n-th root of unity.
Evaluate h:
To compute h, the costs are:
3 IFFT operations of length n
3 FFT operation of length n
1 evaluations of length n
Proof Verification
The verifier checks the proof using the pairing equation: (Note that the right hand side will be precomputed.)
Proof. Considering only the exponent part, the equation simplifies as follows:
To verify a proof, the costs are:
1 MSM operation of length ℓ in G1
3 pairing operations
Batch Proof Verification
Assume there are n proofs. We denote each proof πi for 0≤i<n as follows:
Using the random linear combination trick with θi←$F, you can verify proofs in a batch:
Proof.
From the single verification case, for 0≤i<n, we know that the following equation holds:
Multiplying both sides by θi gives:
Summing over i=0 to n−1, we obtain:
These are precisely the exponent parts in the batch verification equation.
To verify n proofs, the costs are:
n MSM operations of length ℓ in G1
3n+1 scalar multiplications in G1
n−1 field multiplications
n+2 pairing operations
If each proof were verified individually, the process would require 3n expensive pairing operations. However, batch verification significantly reduces this cost.
Malleability
Malleability is a property of cryptographic systems or protocols where an attacker can modify a valid message or ciphertext into another valid message or ciphertext without needing to know the original plaintext. The modified message still appears valid under the cryptographic scheme, which can lead to vulnerabilities and unintended consequences.
Attack 1
An attacker selects y←$F and modifies the proof π′=([A′]1,[B′]2,[C′]1) as follows:
Even though the modified proof π′ differs from the original, it remains valid because A′B′=AB.
Attack 2
An attacker selects y←$F and modifies π′=([A′]1,[B′]2,[C′]1) as folows:
Proof. The validity of the modified proof π′ can be shown as:
Combining Attacks
By combining the two attacks above, a fresh proof for the same statement can be constructed, which is indistinguishable from the existing proofs. (The attacks above contains the same part of the proof.) The modified proof π′=([A′]1,[B′]2,[C′]1) is computed as follows (see GM17, BKSV20 and the Tachyon implementation):
Proof. The modified proof π′ remains valid:
Conclusion
Groth16 is a highly efficient zk-SNARK protocol that combines succinctness, fast verification, and strong zero-knowledge guarantees. Its compact proof size of just 3 group elements and (almost) constant-time verification make it a preferred choice for various privacy-preserving applications or proof compressions(STARK to SNARK).
References
Written by Ryan Kim of Fractalyze
Last updated