Path: blob/main/frontier/10-snarks-starks/sage/10d-groth16-overview.ipynb
483 views
Notebook 10d: Groth16 Overview
Module 10. SNARKs and STARKs
Motivating Question. We have the QAP equation . But the verifier can't check this directly without learning the witness. How do we evaluate polynomials "in the exponent", hiding the witness inside elliptic curve points while still allowing verification? Groth16 does this using pairings and a trusted setup, producing a proof that's just 3 curve points (< 200 bytes) no matter how big the circuit.
Prerequisites. You should be comfortable with:
QAP construction: polynomials, vanishing polynomial, (Notebook 10c)
Bilinear pairings: (Module 07)
Elliptic curve scalar multiplication (Module 06)
Learning objectives. By the end of this notebook you will be able to:
Understand the trusted setup ceremony and the "toxic waste" problem.
See how polynomial evaluations are encoded as elliptic curve points.
Walk through a simplified Groth16-style proof and verification.
Appreciate why the proof is constant-size and why the trusted setup is necessary.
1. The Idea: Evaluate in the Exponent
Bridge from Notebook 10c. The QAP check is: does for a secret ? Recall from 10c that the Schwartz-Zippel lemma guarantees this check at a single random point catches any cheating prover with overwhelming probability, so we only need one evaluation point. The problem: if the verifier learns as a field element, the witness leaks. The solution: encode as a curve point and use a pairing (Module 07) to check the multiplication without revealing the scalar:
This is exactly what Groth16 does. The secret is generated during a trusted setup and then destroyed (the "toxic waste").
| Component | Plain QAP (10c) | Groth16 |
|---|---|---|
| Evaluation point | Random known to verifier | hidden in CRS, then destroyed |
| Polynomial values | Field elements | Curve points |
| Checking | Field multiplication | Pairing: |
| Proof size | All polynomial values | 3 curve points (constant!) |
| Zero-knowledge | None (witness is visible) | Yes (randomized proof) |
2. The Trusted Setup ("Ceremony")
A trusted party (or a multi-party computation) generates a secret and publishes curve points encoding powers of :
Then is destroyed, this is the toxic waste. If anyone learns , they can forge proofs.
Misconception alert. "The trusted setup means you have to trust one person." Not in practice, multi-party computation (MPC) ceremonies ensure that as long as any single participant destroys their share, the toxic waste is unrecoverable. Zcash's Powers of Tau ceremony had hundreds of participants.
Checkpoint 1. The CRS encodes "in the exponent", as curve points. Given , you can compute for any polynomial by taking linear combinations: . But you can never learn itself.
3. Evaluating Polynomials on Curve Points
Given a polynomial and the CRS, anyone can compute without knowing :
4. Simplified Groth16 Proof
Let's build a simplified SNARK for our running example .
Setup: We have the QAP from Notebook 10c. Now the prover computes:
, encoding of the "left" polynomial evaluation
, encoding on
, encoding of the quotient polynomial
Verification: The verifier checks:
This is the pairing-based version of .
5. Pairing-Based Verification
The verifier checks:
Why does this work?
LHS:
RHS:
Equal when , which is exactly the QAP equation!
Checkpoint 2. The pairing translates the polynomial identity check into an elliptic curve equation. The verifier computes a constant number of pairings (3 in real Groth16), regardless of the circuit size. This is why Groth16 verification is so fast, it takes ~5ms even for circuits with millions of gates.
6. The Toxic Waste Problem
If an attacker knows , they can forge proofs for any statement.
7. Real Groth16: The Full Picture
The actual Groth16 protocol is more complex. Here's the high-level structure:
| Phase | What Happens | Output |
|---|---|---|
| Setup | Generate CRS from | Proving key, Verification key |
| Prove | Prover computes using witness | 3 curve points |
| Verify | Verifier checks pairing equation | Accept/Reject |
Groth16 Pairing Equation (Simplified)
Where:
are additional toxic waste parameters
encode the QAP polynomials for public inputs
The proof randomization uses blinding factors for zero-knowledge
Proof Size and Verification Cost
| Metric | Groth16 |
|---|---|
| Proof size | 2 points + 1 point = 192 bytes (BLS12-381) |
| Verification | 3 pairings + 1 multi-scalar multiplication |
| Verification time | ~5 ms |
| Proving time | where = circuit size |
8. SNARK Properties
Groth16 is a zk-SNARK, let's unpack the acronym:
| Letter | Property | Meaning |
|---|---|---|
| zk | Zero-Knowledge | Proof reveals nothing about the witness |
| S | Succinct | Proof is constant-size (192 bytes) |
| N | Non-interactive | Prover sends one message to verifier |
| AR | ARgument | Computationally sound (not information-theoretically) |
| K | Knowledge | Prover must "know" a valid witness (extractability) |
Checkpoint 3. Groth16 achieves the smallest proof size of any known SNARK (192 bytes on BLS12-381). The trade-off is the trusted setup, if the toxic waste is compromised, soundness breaks. This trade-off motivates transparent proof systems like STARKs (next notebooks).
9. Groth16 in the Wild
| Application | What's proved | Circuit size |
|---|---|---|
| Zcash | Transaction validity (spend authority, value balance) | ~100K gates |
| Filecoin | Storage proofs (PoRep) | ~150M gates |
| Tornado Cash | Merkle tree membership (deposit/withdrawal) | ~30K gates |
| zkSync (v1) | Batch of transfer validity | ~100K gates |
Crypto foreshadowing. Groth16 needs a circuit-specific trusted setup, changing the circuit requires a new ceremony. Universal SNARKs (PLONK, Marlin) require only a single "universal" setup. STARKs (next notebooks) eliminate the trusted setup entirely.
10. Exercises
Exercise 1 (Worked): CRS Polynomial Evaluation
Problem. Given the CRS, compute for without knowing . Then verify by comparing with the direct computation.
Solution:
Exercise 2 (Guided): Pairing Verification
Problem. Create curve points and for . Verify that using the Weil pairing.
Fill in the TODOs:
Exercise 3 (Independent): Forge with Toxic Waste
Problem.
Suppose you know . Create a valid-looking proof for the statement (which is false mod 13, since ... wait, that's actually true!).
Instead, prove (which IS false mod 13). Can you make the pairing check pass if you know ?
Explain why not knowing prevents this forgery.
Summary
| Concept | Key Fact |
|---|---|
| Trusted setup | Generate CRS from toxic waste ; must be destroyed |
| CRS | Curve points , encode powers of |
| Polynomial evaluation | , no need to know |
| Pairing check | , multiplicative check |
| Proof size | 3 curve points = 192 bytes (constant!) |
| Toxic waste risk | Knowing allows forging any proof |
Groth16 is the gold standard for compact zk-SNARKs: tiny proofs, fast verification, but requires a trusted setup. In the next notebook, we'll explore FRI, the key ingredient of STARKs, which eliminate the trusted setup entirely.
Next: 10e: FRI Protocol