LogoLogo
LogoLogo
  • Introduction
    • About Us
    • Notations & Definitions
      • MPC
      • ZK
    • Contribute to this Site!
  • Primitives
    • Multiplication
      • Karatsuba Multiplication
      • Toom-Cook Multiplication
    • NAF (Non-adjacent form)
    • Chinese Remainder Theorem (CRT)
    • Euclidean Algorithm
      • Extended Euclidean Algorithm
      • Binary Euclidean Algorithm
      • Extended Binary Euclidean Algorithm
    • Coding Theory
      • Linear Code
    • Number Theoretic Transform
    • Abstract Algebra
      • Group
        • -Morphisms
        • Batch Inverse
      • Elliptic Curve
        • Weierstrass Curve
          • Coordinate Forms
          • Fast Elliptic Curve Arithmetic and Improved WEIL Pairing Evaluation
        • Edwards Curve
          • Coordinate Forms
          • Twisted Edwards ↔ Short Weierstrass Transformation
        • Batch Inverse for Batch Point Additions
        • Scalar Multiplication
          • Double-and-add
          • GLV Decomposition
        • MSM
          • Pippenger's Algorithm
          • Signed Bucket Index
          • CycloneMSM
          • EdMSM
          • cuZK
        • 2-Chain and 2-Cycle of Elliptic Curves
    • Encryption Scheme
      • ElGamal Encryption
    • Modular Arithmetic
      • Modular Reduction
        • Barrett Reduction
        • Montgomery Reduction
      • Modular Inverse
        • Bernstein-Yang's Inverse
    • Multiset Check
    • Sumcheck
    • Commitment Scheme
      • Fflonk
      • SHPlonk
      • Zeromorph
  • MPC
    • Yao's Garbled Circuits
    • GMW
    • BMR
  • ZK
    • Arithmetization
      • R1CS
      • PLONK
      • AIR
    • Folding
      • LatticeFold
      • Nova
        • Nova over Cycles of Curves
    • Lookup
      • Lasso
      • LogUp-GKR
    • SNARK
      • Groth16
      • HyperPlonk
      • Spartan
        • SPARK
    • STARK
      • Additive NTT
      • Basefold
      • Binius
      • Brakedown
      • CircleSTARK
      • FRI
        • FRI Security Features and Optimizations
      • DEEP FRI
      • STIR
      • WHIR
    • Distributed ZK
      • Ryan's Trick for Distributed Groth16
  • Application
    • zkLogin
    • zkHoldem
    • zkTLS
      • DECO
      • Proxying is enough
  • zkVM
Powered by GitBook
On this page
  • Introduction
  • Background
  • Quardratic Arithmetic Protocol (QAP)
  • Protocol Explanation
  • Key Generation
  • Computing h(X)
  • Proof Generation
  • Jordi's Trick
  • Proof Verification
  • Malleability
  • Conclusion
  • References
Export as PDF
  1. ZK
  2. SNARK

Groth16

Presentation: https://www.youtube.com/watch?v=1upt6GOdYXk

PreviousSNARKNextHyperPlonk

Last updated 26 days ago

Introduction

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 and .

Background

Quardratic Arithmetic Protocol (QAP)

For a system where the number of instance variables is ℓ+1\ell + 1ℓ+1, the number of witness variables is m−ℓm - \ellm−ℓ (thus, the total number of variables is m+1m + 1m+1), and the number of constraints is nnn, can be represented as follows:

This R1CS system can be reduced to a Quadratic Arithmetic Program (QAP):

(∑i=0mai(X)⋅zi)(∑i=0mbi(X)⋅zi)−∑i=0mci(X)⋅zi=0mod  t(X)(\sum_{i = 0}^m a_i(X) \cdot z_i ) (\sum_{i = 0}^m b_i(X) \cdot z_i) - \sum_{i = 0}^m c_i(X) \cdot z_i = 0 \mod t(X)(i=0∑m​ai​(X)⋅zi​)(i=0∑m​bi​(X)⋅zi​)−i=0∑m​ci​(X)⋅zi​=0modt(X)

where

  • ai(X)a_i(X)ai​(X): A polynomial such that ai(xj)=Aj,ia_i(x_j) = A_{j, i} ai​(xj​)=Aj,i​ where 0≤i≤m0 \le i \le m0≤i≤m and 0≤j<n0 \le j < n0≤j<n.

  • bi(X)b_i(X)bi​(X): A polynomial such that bi(xj)=Bj,ib_i(x_j) = B_{j, i} bi​(xj​)=Bj,i​ where 0≤i≤m0 \le i \le m0≤i≤m and 0≤j<n0 \le j < n0≤j<n.

  • ci(X)c_i(X)ci​(X): A polynomial such that ci(xj)=Cj,ic_i(x_j) = C_{j, i} ci​(xj​)=Cj,i​ where 0≤i≤m0 \le i \le m0≤i≤m and 0≤j<n0 \le j < n0≤j<n.

  • t(X)t(X)t(X): Xn−1X^n - 1Xn−1.

  • ziz_izi​: A variable, where 0≤i≤m0 \le i \le m0≤i≤m.

Here, deg⁡ai(X)=deg⁡bi(X)=deg⁡ci(X)=n−1\deg a_i(X) = \deg b_i(X) = \deg c_i(X) = n - 1degai​(X)=degbi​(X)=degci​(X)=n−1.

Then we can define h(X)h(X)h(X) as follows:

h(X)=(∑i=0mai(X)⋅zi)(∑i=0mbi(X)⋅zi)−∑i=0mci(X)⋅zit(X)h(X) = \frac{(\sum_{i = 0}^m a_i(X) \cdot z_i) (\sum_{i = 0}^m b_i(X) \cdot z_i) - \sum_{i = 0}^m c_i(X) \cdot z_i}{t(X)}h(X)=t(X)(∑i=0m​ai​(X)⋅zi​)(∑i=0m​bi​(X)⋅zi​)−∑i=0m​ci​(X)⋅zi​​

Where deg⁡h(X)=n−2\deg h(X) = n - 2degh(X)=n−2.

Protocol Explanation

Key Generation

  1. Create a verifying key vk\mathsf{vk}vk.

vk=([α]1,[β]2,[γ]2,[δ]2,{[βai(x)+αbi(x)+ci(x)γ]1}i=0ℓ)\mathsf{vk} = \left([\alpha]_1, [\beta]_2, [\gamma]_2, [\delta]_2, \left\{ \left[ \frac{\beta a_i(x) + \alpha b_i(x) + c_i(x)}{\gamma} \right]_1 \right\}_{i = 0}^{\ell} \right)vk=([α]1​,[β]2​,[γ]2​,[δ]2​,{[γβai​(x)+αbi​(x)+ci​(x)​]1​}i=0ℓ​)
  1. Create a proving key pk\mathsf{pk}pk.

pk=vk+([β]1,[δ]1,{[ai(x)]1}i=0m,{[bi(x)]1}i=0m,{[bi(x)]2}i=0m,{[βai(x)+αbi(x)+ci(x)δ]1}i=ℓ+1m,{[xit(x)δ]1}i=0n−2)\mathsf{pk} = \mathsf{vk} + \left( \begin{align*} & [\beta]_1, [\delta]_1, \{ [a_i(x)]_1\}_{i=0}^{m}, \{ [b_i(x)]_1\}_{i=0}^{m}, \{ [b_i(x)]_2\}_{i=0}^{m}, \\ & \left\{ \left[\frac{\beta a_i(x) + \alpha b_i(x) + c_i(x)}{\delta} \right]_1 \right\}_{i = \ell + 1}^{m}, \left\{ \left[ \frac{x^i t(x)}{\delta} \right]_1 \right\}_{i = 0}^{n - 2} \end{align*} \right)pk=vk+​​[β]1​,[δ]1​,{[ai​(x)]1​}i=0m​,{[bi​(x)]1​}i=0m​,{[bi​(x)]2​}i=0m​,{[δβai​(x)+αbi​(x)+ci​(x)​]1​}i=ℓ+1m​,{[δxit(x)​]1​}i=0n−2​​​

Computing h(X)

  1. Create a(X),b(X),c(X)a(X), b(X), c(X)a(X),b(X),c(X):

a(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)b(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)c(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)a(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\ b(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\ c(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\a(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)b(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)c(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)

where Lj(X)L_j(X)Lj​(X) are lagrange basis polynomials.

  1. Evaluate a(X),b(X),c(X)a(X), b(X), c(X)a(X),b(X),c(X) on a coset domain:

a=(a(g0),…,a(gn−1))b=(b(g0),…,b(gn−1))c=(c(g0),…,c(gn−1))\bm{a} = (a(g^0), \dots, a(g^{n-1})) \\ \bm{b} = (b(g^0), \dots, b(g^{n-1})) \\ \bm{c} = (c(g^0), \dots, c(g^{n-1}))a=(a(g0),…,a(gn−1))b=(b(g0),…,b(gn−1))c=(c(g0),…,c(gn−1))

where gi=(ηω)ig^i = (\eta \omega)^igi=(ηω)i. The reason why we compute on a coset domain is avoiding division by zero since t(ωj)=0t(\omega^j) = 0t(ωj)=0.

  1. Evaluate h\bm{h}h:

h=(a(g0)b(g0)−c(g0)t(g0),…,a(gn−1)b(gn−1)−c(gn−1)t(gn−1))\bm{h} = \left(\frac{a(g^0)b(g^0) - c(g^0)}{t(g^0)}, \dots, \frac{a(g^{n - 1})b(g^{n - 1}) - c(g^{n - 1})}{t(g^{n-1})}\right)h=(t(g0)a(g0)b(g0)−c(g0)​,…,t(gn−1)a(gn−1)b(gn−1)−c(gn−1)​)
  1. Compute h(X)h(X)h(X):

h(X)=∑i=0n−1L′i(X)a(gi)b(gi)−c(gi)t(gi)h(X) = \sum_{i = 0}^{n-1} {L'}_i(X) \frac{a(g^i)b(g^i) - c(g^i)}{t(g^i)} h(X)=i=0∑n−1​L′i​(X)t(gi)a(gi)b(gi)−c(gi)​

where L′i(X){L'}_i(X)L′i​(X) are lagrange basis polynomials on a coset domain.

To compute h(X)h(X)h(X), the costs are:

  • 3 IFFT operations of length nnn

  • 3 FFT on a coset domain operation of length nnn

  • 1 evaluations of length nnn

Proof Generation

Sample r,s←$Fr, s \stackrel{\$}{\leftarrow} \mathbb{F}r,s←$F and generate the proof π=([A]1,[B]2,[C]1)\pi = ([A]_1, [B]_2, [C]_1)π=([A]1​,[B]2​,[C]1​).

[A]1=[α]1+∑i=0mzi[ai(x)]1+r[δ]1[B]2=[β]2+∑i=0mzi[bi(x)]2+s[δ]2[C]1=∑i=ℓ+1mzi[βai(x)+αbi(x)+ci(x)δ]1+∑i=0n−2hi[xit(x)δ]1+s[A]1+r[B]1−rs[δ]1[A]_1 = [\alpha]_1 + \sum_{i=0}^m z_i [a_i(x)]_1 + r [\delta]_1 \\ [B]_2 = [\beta]_2 + \sum_{i=0}^m z_i [b_i(x)]_2 + s [\delta]_2 \\ [C]_1 = \sum_{i = \ell + 1}^{m} z_i \left[ \frac{\beta a_i(x) + \alpha b_i(x) + c_i(x)}{\delta} \right]_1 + \sum_{i = 0}^{n - 2} h_i \left[ \frac{x^i t(x)}{\delta} \right]_1 + s[A]_1 + r[B]_1 - rs[\delta]_1 [A]1​=[α]1​+i=0∑m​zi​[ai​(x)]1​+r[δ]1​[B]2​=[β]2​+i=0∑m​zi​[bi​(x)]2​+s[δ]2​[C]1​=i=ℓ+1∑m​zi​[δβai​(x)+αbi​(x)+ci​(x)​]1​+i=0∑n−2​hi​[δxit(x)​]1​+s[A]1​+r[B]1​−rs[δ]1​

where hih_ihi​ are the coefficients of the h(X)h(X)h(X).

To generate a proof π\piπ, the costs are:

  • For computing [A]1[\mathbb{A}]_1[A]1​:

    • 1 MSM operation of length m+1m + 1m+1 in G1\mathbb{G}_1G1​

  • For computing [B]2[\mathbb{B}]_2[B]2​:

    • 1 MSM operation of length m+1m + 1m+1 in G2\mathbb{G}_2G2​

  • For computing [C]1[\mathbb{C}]_1[C]1​:

    • 1 MSM operation of length m−ℓm - \ellm−ℓ in G1\mathbb{G}_1G1​

    • 1 MSM operation of length n−1n − 1n−1 in G1\mathbb{G}_1G1​

    • 1 MSM operation of length m+1m + 1m+1 in G1\mathbb{G}_1G1​ (for [B]1[B]_1[B]1​)

To compute ∑i=0n−2hi[xit(x)δ]1\sum_{i = 0}^{n - 2} h_i \left[ \frac{x^i t(x)}{\delta} \right]_1∑i=0n−2​hi​[δxit(x)​]1​ of the proof efficiently, consider the following setup:

∑i=0n−2hi[xit(x)δ]1=[h(x)t(x)δ]1=[a(x)b(x)−c(x)δ]1=∑i=02n−2(a(ω′i)b(ω′i)−c(ω′i))[L′i(x)δ]1\begin{align*} \sum_{i = 0}^{n - 2} h_i \left[ \frac{x^i t(x)}{\delta} \right]_1 &= \left[ \frac{h(x)t(x)}{\delta} \right]_1 \\ &= \left[ \frac{a(x)b(x) - c(x)}{\delta} \right]_1 \\ &= \sum_{i = 0}^{2n - 2} (a({\omega'}^i)b({\omega'}^i) - c({\omega'}^i)) \left[ \frac{{L'}_i(x)}{\delta} \right]_1 \end{align*}i=0∑n−2​hi​[δxit(x)​]1​​=[δh(x)t(x)​]1​=[δa(x)b(x)−c(x)​]1​=i=0∑2n−2​(a(ω′i)b(ω′i)−c(ω′i))[δL′i​(x)​]1​​

Where ω′\omega'ω′ be a 2n2n2n-th root of unity and ω\omegaω an nnn-th root of unity. These satisfy:

(ω′i)2n=(ω′2i)n=(ωi)n=1({\omega'}^i)^{2n} = ({\omega'}^{2i})^n = (\omega^i)^n= 1(ω′i)2n=(ω′2i)n=(ωi)n=1

and L′i(X){L'}_i(X)L′i​(X) are lagrange basis polynomials.

Properties of a(X)b(X)−c(X)a(X)b(X) - c(X)a(X)b(X)−c(X)

∑i=02n−2(a(ω′i)b(ω′i)−c(ω′i))[L′i(x)δ]1\sum_{i = 0}^{2n - 2} (a({\omega'}^i)b({\omega'}^i) - c({\omega'}^i)) \left[ \frac{{L'}_i(x)}{\delta} \right]_1∑i=02n−2​(a(ω′i)b(ω′i)−c(ω′i))[δL′i​(x)​]1​ can be divided into evaluations at even powers and odd powers.

∑i=02n−2(a(ω′i)b(ω′i)−c(ω′i))[L′i(x)δ]1=∑i=0n−1(a(ω′2i)b(ω′2i)−c(ω′2i))[L′2i(x)δ]1+∑i=0n−2(a(ω′2i+1)b(ω′2i+1)−c(ω′2i+1))[L′2i+1(x)δ]1\begin{align*} \sum_{i = 0}^{2n - 2} (a({\omega'}^i)b({\omega'}^i) - c({\omega'}^i)) \left[ \frac{{L'}_i(x)}{\delta} \right]_1 &= \sum_{i = 0}^{n - 1} (a({\omega'}^{2i})b({\omega'}^{2i}) - c({\omega'}^{2i})) \left[ \frac{{L'}_{2i}(x)}{\delta} \right]_1 \\ & + \sum_{i = 0}^{n - 2} (a({\omega'}^{2i + 1})b({\omega'}^{2i + 1}) - c({\omega'}^{2i + 1})) \left[ \frac{{L'}_{2i + 1}(x)}{\delta} \right]_1 \end{align*}i=0∑2n−2​(a(ω′i)b(ω′i)−c(ω′i))[δL′i​(x)​]1​​=i=0∑n−1​(a(ω′2i)b(ω′2i)−c(ω′2i))[δL′2i​(x)​]1​+i=0∑n−2​(a(ω′2i+1)b(ω′2i+1)−c(ω′2i+1))[δL′2i+1​(x)​]1​​
  1. Evaluation at even powers of ω′\omega'ω′: For 0≤j<n0 \le j < n0≤j<n, evaluates to zero at even powers of ω′\omega'ω′:

a(ω′2j)b(ω′2j)−c(ω′2j)=a(ωj)b(ωj)−c(ωj)=0a({\omega'}^{2j})b({\omega'}^{2j}) - c({\omega'}^{2j}) = a({\omega}^{j})b({\omega}^{j}) - c({\omega}^{j}) = 0a(ω′2j)b(ω′2j)−c(ω′2j)=a(ωj)b(ωj)−c(ωj)=0

This implies:

∑i=0n−1(a(ω′2i)b(ω′2i)−c(ω′2i))[L′2i(x)δ]1=0\sum_{i = 0}^{n - 1} (a({\omega'}^{2i})b({\omega'}^{2i}) - c({\omega'}^{2i})) \left[ \frac{{L'}_{2i}(x)}{\delta} \right]_1 = 0i=0∑n−1​(a(ω′2i)b(ω′2i)−c(ω′2i))[δL′2i​(x)​]1​=0
  1. Evaluation at odd powers of ω′\omega'ω′: For 0≤j<n0 \le j < n0≤j<n, given p(X)=p0+p1X+⋯+pn−1Xn−1p(X) = p_0 + p_1X + \cdots + p_{n-1}X^{n-1}p(X)=p0​+p1​X+⋯+pn−1​Xn−1, we can compute the evaluations at odd powers of ω′\omega'ω′:

p(ω′2j+1)=∑i=0n−1pi(ω′2j+1)i=∑i=0n−1piω′i(ω′2j)i=∑i=0n−1piω′i(ωj)i=p′(ωj)p({\omega'}^{2j + 1}) = \sum_{i =0}^{n-1} p_i ({\omega'}^{2j + 1})^i = \sum_{i=0}^{n-1} p_i {\omega'}^i ({\omega'}^{2j})^i = \sum_{i=0}^{n-1} p_i {\omega'}^i ({\omega}^{j})^i = p'({\omega}^{j})p(ω′2j+1)=i=0∑n−1​pi​(ω′2j+1)i=i=0∑n−1​pi​ω′i(ω′2j)i=i=0∑n−1​pi​ω′i(ωj)i=p′(ωj)

Where p′(X)=p0+p1ω′X+⋯+pn−1ω′n−1Xn−1p'(X) = p_0 + p_1{\omega'}X + \cdots + p_{n-1}{\omega'}^{n-1}X^{n-1}p′(X)=p0​+p1​ω′X+⋯+pn−1​ω′n−1Xn−1.

This implies:

∑i=0n−2(a(ω′2i+1)b(ω′2i+1)−c(ω′2i+1))[L′2i+1(x)δ]1=∑i=0n−2(a′(ωi)b′(ωi)−c′(ωi))[L′2i+1(x)δ]1\sum_{i = 0}^{n - 2} (a({\omega'}^{2i + 1})b({\omega'}^{2i + 1}) - c({\omega'}^{2i + 1})) \left[ \frac{{L'}_{2i + 1}(x)}{\delta} \right]_1 = \sum_{i = 0}^{n - 2} (a'({\omega}^{i})b'({\omega}^{i}) - c'({\omega}^{i})) \left[ \frac{{L'}_{2i + 1}(x)}{\delta} \right]_1 i=0∑n−2​(a(ω′2i+1)b(ω′2i+1)−c(ω′2i+1))[δL′2i+1​(x)​]1​=i=0∑n−2​(a′(ωi)b′(ωi)−c′(ωi))[δL′2i+1​(x)​]1​

Thus, the evaluations of a(X)b(X)−c(X)a(X)b(X) - c(X)a(X)b(X)−c(X) at odd powers of ω′\omega'ω′ can be efficiently computed by combining FFT results of a′(X),b′(X),c′(X)a'(X), b'(X), c'(X)a′(X),b′(X),c′(X).

Optimizing h(X)h(X)h(X) in the Proving Key

To eliminate the IFFT of h(X)h(X)h(X), the term {[xit(x)δ]1}i=0n−2\left\{ \left[ \frac{x^i t(x)}{\delta} \right]_1 \right\}_{i = 0}^{n - 2} {[δxit(x)​]1​}i=0n−2​ in the proving key (pk) is replaced with {[L′2i+1(x)δ]}i=0n−2\left\{ \left[ \frac{{L'}_{2i + 1}(x)}{\delta} \right] \right\}_{i = 0}^{n - 2} {[δL′2i+1​(x)​]}i=0n−2​:

∑i=0n−2hi[xit(x)δ]1→∑i=0n−2(a′(ωi)b′(ωi)−c′(ωi))[L′2i+1(x)δ]1\sum_{i = 0}^{n - 2} h_i \left[ \frac{x^i t(x)}{\delta} \right]_1 \rightarrow \sum_{i = 0}^{n - 2} (a'({\omega}^i)b'({\omega}^i) - c'({\omega}^i)) \left[ \frac{{L'}_{2i + 1}(x)}{\delta} \right]_1i=0∑n−2​hi​[δxit(x)​]1​→i=0∑n−2​(a′(ωi)b′(ωi)−c′(ωi))[δL′2i+1​(x)​]1​

Then computing h(X)h(X)h(X) is performed as follows:

  1. Create a(X),b(X),c(X)a(X),b(X),c(X)a(X),b(X),c(X):

a(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)b(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)c(X)=∑j=0n−1Lj(X)(∑i=0mAj,i⋅zi)a(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\ b(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\ c(X) = \sum_{j = 0}^{n-1} L_j(X) (\sum_{i = 0}^{m} A_{j, i} \cdot z_i) \\a(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)b(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)c(X)=j=0∑n−1​Lj​(X)(i=0∑m​Aj,i​⋅zi​)

where Lj(X)L_j(X)Lj​(X) are lagrange basis polynomials.

  1. Create a′(X),b′(X),c′(X)a'(X),b'(X),c'(X)a′(X),b′(X),c′(X):

a′(X)=∑i=0n−1aiω′iXib′(X)=∑i=0n−1biω′iXic′(X)=∑i=0n−1ciω′iXia'(X) = \sum_{i =0}^{n-1} a_i {\omega'}^i X^i \\ b'(X) = \sum_{i =0}^{n-1} b_i {\omega'}^i X^i \\ c'(X) = \sum_{i =0}^{n-1} c_i {\omega'}^i X^ia′(X)=i=0∑n−1​ai​ω′iXib′(X)=i=0∑n−1​bi​ω′iXic′(X)=i=0∑n−1​ci​ω′iXi

where ω′\omega'ω′ is 2n2n2n-th root of unity.

  1. Evaluate a′(X),b′(X),c′(X)a'(X), b'(X), c'(X)a′(X),b′(X),c′(X):

a′=(a′(ω0),…,a′(ωn−1))b′=(b′(ω0),…,b′(ωn−1))c′=(c′(ω0),…,c′(ωn−1))\bm{a'} = (a'({\omega}^0), \dots, a'({\omega}^{n-1})) \\\bm{b'} = (b'({\omega}^0), \dots, b'({\omega}^{n-1})) \\\bm{c'} = (c'({\omega}^0), \dots, c'({\omega}^{n-1}))a′=(a′(ω0),…,a′(ωn−1))b′=(b′(ω0),…,b′(ωn−1))c′=(c′(ω0),…,c′(ωn−1))

where ω\omegaω is nnn-th root of unity.

  1. Evaluate h\bm{h}h:

h=(a′(ω0)b′(ω0)−c′(ω0),…,a′(ωn−1)b′(ωn−1)−c′(ωn−1))\bm{h} = (a'({\omega}^0)b'({\omega}^0) - c'({\omega}^0), \dots, a'({\omega}^{n - 1})b'({\omega}^{n - 1}) - c'({\omega}^{n - 1}))h=(a′(ω0)b′(ω0)−c′(ω0),…,a′(ωn−1)b′(ωn−1)−c′(ωn−1))

To compute h\bm{h}h, the costs are:

  • 3 IFFT operations of length nnn

  • 3 FFT operation of length nnn

  • 1 evaluations of length nnn

Proof Verification

The verifier checks the proof using the pairing equation: (Note that the right hand side will be precomputed.)

e([A]1,[B]2)⋅e(∑i=0ℓzi[βai(x)+αbi(x)+ci(x)γ]1,[−γ]2)⋅e([C]1,[−δ]2)=?e([α]1,[β]2)e([A]_1, [B]_2) \cdot e(\sum_{i=0}^\ell z_i \left[ \frac{\beta a_i(x) + \alpha b_i(x) + c_i(x)}{\gamma} \right]_1, [-\gamma]_2) \cdot e([C]_1, [-\delta]_2) \stackrel{?}=e([\alpha]_1, [\beta]_2) e([A]1​,[B]2​)⋅e(i=0∑ℓ​zi​[γβai​(x)+αbi​(x)+ci​(x)​]1​,[−γ]2​)⋅e([C]1​,[−δ]2​)=?e([α]1​,[β]2​)

Proof. Considering only the exponent part, the equation simplifies as follows:

AB=(α+∑i=0mziai(x)+rδ)(β+∑i=0mzibi(x)+sδ)=αβ+∑i=0mzi(βai(x)+αbi(x))+(∑i=0mziai(x))(∑i=0mzibi(x))⏟∑i=0mzici(x)+h(x)t(x)+sδA+rδB−rsδ2=αβ+∑i=0mzi(βai(x)+αbi(x)+ci(x))+h(x)t(x)+sδA+rδB−rsδ2=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+∑i=l+1mzi(βai(x)+αbi(x)+ci(x))+h(x)t(x)+sδA+rδB−rsδ2=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+δ(∑i=l+1mzi(βai(x)+αbi(x)+ci(x))δ+h(x)t(x)δ+sA+rB−rsδ)⏟C\begin{align*} AB &= (\alpha + \sum_{i = 0}^m z_i a_i(x) + r \delta) (\beta + \sum_{i = 0}^m z_i b_i(x) + s \delta) \\ &= \alpha \beta + \sum_{i = 0}^m z_i (\beta a_i(x) + \alpha b_i(x) ) + \underbrace{(\sum_{i = 0}^m z_i a_i(x))(\sum_{i = 0}^m z_i b_i(x))}_{\sum_{i=0}^m z_i c_i(x) + h(x) t(x)} + s \delta A + r \delta B - rs\delta^2 \\ &= \alpha \beta + \sum_{i = 0}^m z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + h(x)t(x) + s \delta A + r \delta B - rs\delta^2 \\ &= \alpha \beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \sum_{i = l + 1}^m z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + h(x) t(x) + s \delta A + r \delta B - rs\delta^2 \\ &= \alpha \beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \delta \underbrace{\left( \frac{\sum_{i = l + 1}^{m} z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x))}{\delta} + \frac{h(x)t(x)}{\delta} + s A + r B - rs\delta \right)}_{C} \end{align*}AB​=(α+i=0∑m​zi​ai​(x)+rδ)(β+i=0∑m​zi​bi​(x)+sδ)=αβ+i=0∑m​zi​(βai​(x)+αbi​(x))+∑i=0m​zi​ci​(x)+h(x)t(x)(i=0∑m​zi​ai​(x))(i=0∑m​zi​bi​(x))​​+sδA+rδB−rsδ2=αβ+i=0∑m​zi​(βai​(x)+αbi​(x)+ci​(x))+h(x)t(x)+sδA+rδB−rsδ2=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+i=l+1∑m​zi​(βai​(x)+αbi​(x)+ci​(x))+h(x)t(x)+sδA+rδB−rsδ2=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+δC(δ∑i=l+1m​zi​(βai​(x)+αbi​(x)+ci​(x))​+δh(x)t(x)​+sA+rB−rsδ)​​​

To verify a proof, the costs are:

  • 1 MSM operation of length ℓ\ellℓ in G1\mathbb{G}_1G1​

  • 3 pairing operations

Batch Proof Verification

Assume there are nnn proofs. We denote each proof πi\pi_iπi​ for 0≤i<n0 \leq i < n0≤i<n as follows:

πi=([Ai]1,[Bi]2,[Ci]1)\pi_i = ([A_i]_1, [B_i]_2, [C_i]_1)πi​=([Ai​]1​,[Bi​]2​,[Ci​]1​)

Using the random linear combination trick with θi←$F\theta_i \stackrel{\$}\leftarrow \mathbb{F}θi​←$F, you can verify proofs in a batch:

∏i=0n−1(e(θi[Ai]1,[Bi]2))⋅e(∑i=0n−1θi(∑j=0ℓzj[βaj(x)+αbj(x)+cj(x)γ]1),[γ]2)⋅e(∑i=0n−1θi[Ci]1,[−δ]2)=?(∏i=0n−1θi)e([α]1,[β]2)\prod_{i=0}^{n-1} \left(e(\theta_i[A_i]_1, [B_i]_2) \right) \cdot e(\sum_{i=0}^{n-1} \theta_i \left(\sum_{j=0}^{\ell}z_j \left[ \frac{\beta a_j(x) + \alpha b_j(x) + c_j(x)}{\gamma} \right]_1\right), [\gamma]_2) \cdot e(\sum_{i=0}^{n-1}\theta_i[C_i]_1, [-\delta]_2) \stackrel{?}= \left(\prod_{i=0}^{n-1}\theta_i\right) e([\alpha]_1, [\beta]_2)i=0∏n−1​(e(θi​[Ai​]1​,[Bi​]2​))⋅e(i=0∑n−1​θi​(j=0∑ℓ​zj​[γβaj​(x)+αbj​(x)+cj​(x)​]1​),[γ]2​)⋅e(i=0∑n−1​θi​[Ci​]1​,[−δ]2​)=?(i=0∏n−1​θi​)e([α]1​,[β]2​)

Proof.

From the single verification case, for 0≤i<n0 \leq i < n0≤i<n, we know that the following equation holds:

AiBi=αβ+∑j=0lzj(βaj(x)+αbj(x)+cj(x))+δCiA_iB_i = \alpha \beta + \sum_{j = 0}^l z_j (\beta a_j(x) + \alpha b_j(x) + c_j(x)) + \delta C_iAi​Bi​=αβ+j=0∑l​zj​(βaj​(x)+αbj​(x)+cj​(x))+δCi​

Multiplying both sides by θi\theta_iθi​ gives:

θiAiBi=θiαβ+θi(∑j=0lzj(βaj(x)+αbj(x)+cj(x)))+θiδCi\theta_iA_iB_i = \theta_i \alpha \beta + \theta_i \left(\sum_{j = 0}^l z_j (\beta a_j(x) + \alpha b_j(x) + c_j(x))\right) + \theta_i \delta C_iθi​Ai​Bi​=θi​αβ+θi​(j=0∑l​zj​(βaj​(x)+αbj​(x)+cj​(x)))+θi​δCi​

Summing over i=0i = 0i=0 to n−1n - 1n−1, we obtain:

∑i=0n−1θiAiBi=(∑i=0n−1θi)αβ+∑i=0n−1θi(∑j=0lzj(βaj(x)+αbj(x)+cj(x)))+∑i=0n−1θiδCi\sum_{i=0}^{n-1}\theta_i A_iB_i = \left(\sum_{i=0}^{n-1}\theta_i\right) \alpha \beta + \sum_{i=0}^{n-1}\theta_i \left(\sum_{j = 0}^l z_j (\beta a_j(x) + \alpha b_j(x) + c_j(x))\right) + \sum_{i=0}^{n-1}\theta_i \delta C_ii=0∑n−1​θi​Ai​Bi​=(i=0∑n−1​θi​)αβ+i=0∑n−1​θi​(j=0∑l​zj​(βaj​(x)+αbj​(x)+cj​(x)))+i=0∑n−1​θi​δCi​

These are precisely the exponent parts in the batch verification equation.

To verify nnn proofs, the costs are:

  • nnn MSM operations of length ℓ\ellℓ in G1\mathbb{G}_1G1​

  • 3n+13n + 13n+1 scalar multiplications in G1\mathbb{G}_1G1​

  • n−1n - 1n−1 field multiplications

  • n+2n + 2n+2 pairing operations

If each proof were verified individually, the process would require 3n3n3n 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←$Fy \stackrel{\$}{\leftarrow} \mathbb{F}y←$F and modifies the proof π′=([A′]1,[B′]2,[C′]1)\pi' = ([A']_1, [B']_2, [C']_1)π′=([A′]1​,[B′]2​,[C′]1​) as follows:

[A′]1=y[A]1[B′]2=y−1[B]2[C′]1=[C]1[A']_1 = y[A]_1 \\ [B']_2 = y^{-1}[B]_2 \\ [C']_1 = [C]_1[A′]1​=y[A]1​[B′]2​=y−1[B]2​[C′]1​=[C]1​

Even though the modified proof π′\pi'π′ differs from the original, it remains valid because A′B′=ABA'B' = ABA′B′=AB.

Attack 2

An attacker selects y←$Fy \stackrel{\$}{\leftarrow} \mathbb{F}y←$F and modifies π′=([A′]1,[B′]2,[C′]1)\pi' = ([A']_1, [B']_2, [C']_1)π′=([A′]1​,[B′]2​,[C′]1​) as folows:

[A′]1=[A]1[B′]2=[B]2+yδ[C′]1=[C]1+y[A]1[A']_1 = [A]_1 \\ [B']_2 = [B]_2 + y \delta \\ [C']_1 = [C]_1 + y [A]_1[A′]1​=[A]1​[B′]2​=[B]2​+yδ[C′]1​=[C]1​+y[A]1​

Proof. The validity of the modified proof π′\pi'π′ can be shown as:

A′B′=A(B+yδ)=AB+yδA=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+δC+yδA=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+δ(C+yA)⏟C′\begin{align*} A'B' &= A(B + y\delta) \\ &= AB + y\delta A \\ &= \alpha\beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \delta C + y \delta A \\ &= \alpha\beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \delta \underbrace{(C + y A)}_{C'} \end{align*}A′B′​=A(B+yδ)=AB+yδA=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+δC+yδA=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+δC′(C+yA)​​​

Combining Attacks

[A′]1=1r1[A]1[B′]2=r1[B]2+r1r2[δ]2[C′]1=[C]1+r2[A]1[A']_1 = \frac{1}{r_1}[A]_1 \\ [B']_2 = r_1 [B]_2 + r_1r_2[\delta]_2 \\ [C']_1 = [C]_1 +r_2 [A]_1[A′]1​=r1​1​[A]1​[B′]2​=r1​[B]2​+r1​r2​[δ]2​[C′]1​=[C]1​+r2​[A]1​

Proof. The modified proof π′\pi'π′ remains valid:

A′B′=1r1A(r1B+r1r2δ)=AB+r2δA=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+δC+r2δA=αβ+∑i=0lzi(βai(x)+αbi(x)+ci(x))+δ(C+r2A)⏟C′\begin{align*} A'B' &= \frac{1}{r_1}A(r_1B + r_1r_2\delta) \\ &= AB + r_2 \delta A \\ &= \alpha\beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \delta C + r_2 \delta A \\ &= \alpha\beta + \sum_{i = 0}^l z_i (\beta a_i(x) + \alpha b_i(x) + c_i(x)) + \delta \underbrace{(C + r_2 A)}_{C'} \end{align*} A′B′​=r1​1​A(r1​B+r1​r2​δ)=AB+r2​δA=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+δC+r2​δA=αβ+i=0∑l​zi​(βai​(x)+αbi​(x)+ci​(x))+δC′(C+r2​A)​​​

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

In and 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=0z_i​⋅0=0zi​​⋅0=0 for all public inputs. This is done implicitly by the Arkworks and SnarkJS implementations. (it's taken from .) See also !

Sample the toxic wastes α,β,γ,δ,x←$F\alpha, \beta, \gamma, \delta, x \stackrel{\$}{\leftarrow} \mathbb{F}α,β,γ,δ,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 (or ).

IFFT on a coset domain operations of length n−2n - 2n−2 (This step can be removed by using .)

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 .

's Trick

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)\pi' = ([A']_1, [B']_2, [C']_1)π′=([A′]1​,[B′]2​,[C′]1​) is computed as follows (see , and the ):

Written by from

BKSV20
GR22
https://xn--2-umb.com/22/groth16/
https://geometry.xyz/notebook/groth16-malleability
MPC
Trusted Setup
Jordi
GM17
BKSV20
Tachyon implementation
https://ethresear.ch/t/transaction-malleability-attack-of-groth16-proof/15881
https://xn--2-umb.com/22/groth16/
https://geometry.xyz/notebook/the-hidden-little-secret-in-snarkjs
Jordi's Trick
Jordi's Trick
A41
ryan Kim
Groth16
circom
RISC0
R1CS