This is a comprehensive question about zk-SNARKs. Let me break it down into three parts:
- Arithmetic circuit to R1CS transformation
- Proof of knowledge without revealing the witness
- Trusted setup and CRS
Let me explain each part in detail with examples.
Part 1: Arithmetic Circuit to R1CS Transformation
An arithmetic circuit is a representation of a computation as a series of addition and multiplication gates over a finite field. To prove knowledge of a solution to such a circuit, we need to convert it into a form that's suitable for cryptographic protocols - this is R1CS (Rank-1 Constraint System).
Arithmetic Circuits
An arithmetic circuit over a field 𝔽_p consists of:
- Input variables (witnesses and public inputs)
- Addition gates: output = a + b
- Multiplication gates: output = a * b
- Output
Example: Prove knowledge of x such that x³ + x + 5 = 35
This is equivalent to x³ + x = 30, or (x * x * x) + x = 30
Gates:
- y₁ = x * x (output y₁)
- y₂ = y₁ * x (output y₂)
- y₃ = y₂ + x (output y₃)
- Check: y₃ = 30
R1CS (Rank-1 Constraint System)
R1CS converts an arithmetic circuit into a standardized form of "rank-1 constraints". Each constraint has the form:
(A·z) ⊙ (B·z) = C·z
Where:
- z is the vector of all variables (including witness and public inputs, with a constant term 1)
- A, B, C are matrices
- ⊙ is element-wise multiplication (Hadamard product)
- · is vector-dot product
Breaking this down:
- Left side: (A·z) and (B·z) each produce a single value, and their product equals C·z on the right
Let's continue with our example:
Variables: z = [1, x, y₁, y₂, y₃, output]
Constraint 1 (y₁ = x * x):
(A₁·z) ⊙ (B₁·z) = C₁·z
We need:
- A₁·z = x (so A₁ = [0, 1, 0, 0, 0, 0])
- B₁·z = x (so B₁ = [0, 1, 0, 0, 0, 0])
- C₁·z = y₁ (so C₁ = [0, 0, 1, 0, 0, 0])
This gives: x * x = y₁ ✓
For the second constraint (y₂ = y₁ * x), I select y₁ with A₂ = [0, 0, 1, 0, 0, 0], x with B₂ = [0, 1, 0, 0, 0, 0], and output to y₂ with C₂ = [0, 0, 0, 1, 0, 0], yielding y₁ * x = y₂ ✓
The third constraint (y₃ = y₂ + x) requires addition, which I handle by multiplying by 1. I set A₃ to select both x and y₂ with [0, 1, 0, 1, 0, 0], B₃ to select the constant with [1, 0, 0, 0, 0, 0], and C₃ to output to y₃ with [0, 0, 0, 0, 1, 0], giving (x + y₂) * 1 = y₃.
For the final constraint (y₃ = 30), I select y₃ with A₄ = [0, 0, 0, 0, 1, 0], multiply by 1 with B₄ = [1, 0, 0, 0, 0, 0], and set the output to 30 with C₄ = [0, 0, 0, 0, 0, 30], so y₃ * 1 = 30 ✓
The general approach involves flattening the circuit into sequential gates, assigning intermediate variables to each output, constructing one constraint per gate, then combining them into a unified system.
To prove knowledge of the witness without revealing it, I use cryptographic commitments and polynomial commitments. The prover creates a polynomial encoding of the witness rather than disclosing it directly, allowing verification of constraint satisfaction while keeping the actual values hidden.
In the commitment phase, I encode the A, B, and C matrices as polynomials p_A(x), p_B(x), and p_C(x), then send only their commitments C_A, C_B, and C_C using a scheme like KZG.
The constraint (A·z) ⊙ (B·z) = C·z translates into a polynomial identity: A(x) * B(x) - C(x) = Z(x) * H(x), where Z(x) vanishes at all constraint points and H(x) is the quotient proving satisfaction.
The proof itself reveals neither the polynomials nor the witness—instead, the prover demonstrates the polynomial identity holds through evaluation proofs at random points. The prover can't forge a valid proof at a random evaluation point without knowing the witness, making soundness negligible. Zero-knowledge holds because commitments conceal the polynomials themselves, the verifier picks random evaluation points, and discrete log assumptions prevent extracting polynomials from their commitments.
To enable efficient polynomial commitments non-interactively, KZG requires a structured setup. For a polynomial p(x) = p_0 + p_1x + ... + p_dx^d, the commitment COM(p) = p_0*G needs special cryptographic infrastructure to function properly.
The setup phase produces a common reference string containing group elements G^(s^i) and H^(s^i) for i = 0 to d, where s is a secret value sampled uniformly at random during initialization. A trusted entity or multi-party ceremony generates this secret, computes its successive powers, and publishes the resulting group elements as public parameters that enable all provers and verifiers to work with the same polynomial commitment scheme.
The secret s itself must be destroyed immediately after the setup completes—if it were ever recovered, an adversary could forge proofs for any polynomial. The scheme's security depends entirely on this destruction step.
These exponentiated powers enable a specific type of proof: to demonstrate that a committed polynomial p evaluates to some value v at a secret point s without revealing p itself, a prover computes a quotient proof π = [p(s) - v]/(s - a) · G. The verifier then confirms this proof using a pairing equation that checks the relationship between the commitment, the claimed evaluation, and the public parameters.
The setup achieves three critical properties: binding (preventing multiple valid proofs for different evaluations of the same polynomial), hiding (keeping polynomial coefficients secret), and knowledge of exponent (ensuring anyone producing a valid proof actually knows the underlying polynomial). To eliminate the risk of a single trusted party compromising the entire system, practical deployments use multi-party computation ceremonies where multiple parties each contribute their own secret, publish their contribution, and destroy it—the final CRS combines all contributions in a way that remains secure as long as at least one party acted honestly.
Real-world examples like Zcash's 2016 ceremony with 6 participants, the ongoing Perpetual Powers of Tau allowing continuous participation, and Ethereum 2.0's thousands-strong ceremony demonstrate how this approach scales. The security model is elegant: even if some parties collude or fail to destroy their secrets, the system remains secure provided at least one participant properly eliminated theirs.
However, trusted setups introduce practical challenges. They require coordinating a one-time ceremony, and if compromised, the entire system can generate fraudulent proofs. Different circuit sizes typically need separate setups, though Powers of Tau partially addresses this. The community has developed alternatives to mitigate these issues: transparent schemes like STARKs and Halo eliminate the need for trusted setup entirely, while universal CRS approaches like Powers of Tau enable reusing a single setup across multiple circuit sizes, and updatable CRS systems in Plonk and Marlin allow incremental modifications without rerunning the full ceremony.
zk-SNARKs: From Circuits to Proofs
I'll walk through the complete pipeline from computation to cryptographic proof, with practical examples.
1. Arithmetic Circuits → R1CS Transformation
Arithmetic Circuits
An arithmetic circuit expresses computation as gates over a finite field. Example: prove knowledge of x where x³ + x + 5 = 35.
Circuit representation:
y₁ = x * x (multiplication gate)
y₂ = y₁ * x (multiplication gate)
y₃ = y₂ + y₁ + 5 (addition gate)
y₃ = 35 (public output)
R1CS: Standardized Constraint Form
R1CS converts circuits into rank-1 constraints: (A·z) ⊙ (B·z) = C·z
Where:
- z = [1, x, y₁, y₂, y₃, ...] (witness vars + public inputs + constant)
- A, B, C = sparse matrices encoding the circuit
- ⊙ = element-wise multiplication
- · = dot product
For our example:
Constraint 1: x * x = y₁
A₁·z = x B₁·z = x C₁·z = y₁
A₁ = [0,1,0,0,0] B₁ = [0,1,0,0,0] C₁ = [0,0,1,0,0]
Constraint 2: y₁ * x = y₂
A₂ = [0,0,1,0,0] B₂ = [0,1,0,0,0] C₂ = [0,0,0,1,0]
Constraint 3: (y₂ + 5) * 1 = y₃ [addition via multiplication by 1]
A₃ = [5,0,0,1,0] B₃ = [1,0,0,0,0] C₃ = [0,0,0,0,1]
Constraint 4: y₃ * 1 = 35 [public output check]
A₄ = [0,0,0,0,1] B₄ = [1,0,0,0,0] C₄ = [0,0,0,0,35]
Key insight: One constraint per multiplication gate. Additions fold into the matrices.
2. Proving Knowledge Without Revealing the Witness
The Core Idea
Instead of revealing z, the prover commits to polynomial encodings of the constraint system and proves an algebraic identity—without divulging variable values.
The Proof Protocol (Simplified)
Step 1: Polynomial Encoding
The R1CS matrices A, B, C are encoded as polynomials. For each row i:
- A(x) encodes the A matrix
- B(x) encodes the B matrix
- C(x) encodes the C matrix
The constraint becomes a polynomial identity:
A(x) · B(x) - C(x) = Z(x) · H(x)
where:
Z(x) = vanishing polynomial with roots at all constraint points
H(x) = quotient polynomial (only exists if constraints satisfied)
Step 2: Commitment without Revealing
Prover commits to polynomials using KZG polynomial commitments:
[Polynomial Commitment Scheme - KZG]
COM(p(x)) = [p₀·G + p₁·[s]G + p₂·[s²]G + ...]₁
(where [s]G means s·G in the group)
Prover sends:
- C_A = COM(A(x))
- C_B = COM(B(x))
- C_C = COM(C(x))
- π_h = COM(H(x))
These commitments hide all information about the polynomials.
Step 3: Polynomial Evaluation Proof
Verifier picks a random challenge point r (or prover derives via Fiat-Shamir hash).
Prover creates evaluation proofs showing:
A(r) · B(r) - C(r) = Z(r) · H(r)
Without ever revealing A(r), B(r), C(r), or H(r) directly!
This uses pairing-based cryptography:
e(π_h, [r - 1]H) = e(C_A, C_B) - e(C_C, H) - e(Z(r)·G, π_h)
[verification equation]
Step 4: Soundness Without Revealing
- If witness is invalid: No valid H(x) exists, so prover can't satisfy the equation at random r
- Probability of cheating: ≈ 1/|𝔽| for large fields (negligible)
- Zero-knowledge: Commitments are binding but perfectly hiding; random r prevents extracting witness
3. Trusted Setup and Common Reference String (CRS)
Why Trusted Setup is Necessary
KZG commitments require evaluations at a secret point s, published in encrypted form:
CRS (Common Reference String):
[G, [s]G, [s²]G, [s³]G, ..., [s^d]G] (in group 𝔾₁)
[H, [s]H, [s²]H, [s³]H, ..., [s^d]H] (in group 𝔾₂)
Example (for d=2):
Elements: G, s·G, s²·G, H, s·H, s²·H
(s is hidden; only s·G is published)
The secret s allows constructing commitments and evaluation proofs. It must never be known.
The Trusted Setup Ceremony
Single Party (Simplified):
1. Trusted party generates random s ← 𝔽_p
2. Computes: g, g^s, g^(s²), ..., g^(s^d)
3. Publishes CRS
4. **DESTROYS s immediately** (this is critical!)
Multi-Party Computation (Real-world):
Since no single party is trustworthy, use distributed generation:
Party 1:
Generate s₁, compute [s₁^i]G
Publish [s₁^i]G, destroy s₁
Party 2:
Generate s₂, receives [s₁^i]G
Computes [s₁·s₂^i]G (multiplies the exponents)
Destroy s₂
Party 3:
Generate s₃, receives [s₁·s₂^i]G
Computes [s₁·s₂·s₃^i]G
Destroy s₃
Final CRS: [s_final^i]G where s_final = s₁·s₂·s₃·...
Security Property:
As long as at least ONE party honestly destroys their secret, the final s is unknown.
Examples of Real Ceremonies
Zcash (2016):
- 6 participants, elaborate protocol
- Each participant verified others' work
- Resulted in public CRS for Sprout
Perpetual Powers of Tau (2017–present):
Ongoing ceremony allowing unlimited participants
- Anyone can contribute new powers
- Reusable for many circuits up to a maximum degree
- Currently ~90 participants, degree ~2^28
Ethereum 2.0 Ceremony:
- 11,000+ participants
- Largest MPC coordination ever
- Each participant contributed entropy
Potential Vulnerabilities
Worst Case: All parties collude or all destroy records falsely
→ Attacker knows s
→ Can create forged proofs and counterfeit coins/transactions
→ Cryptographic security completely broken
Mitigation:
1. Large, diverse participant set (reduces collusion risk)
2. Public verification of each contribution
3. Independent code audits
4. Participants from different jurisdictions/organizations
Limitations and Modern Alternatives
| Approach | Trusted Setup | TL;DR |
|---|
| zk-SNARKs | ✗ Required | Fast proofs (~288 bytes), but setup ceremony needed |
| STARKs | ✓ None | Larger proofs (~100 KB), post-quantum, setup-free |
| Halo | ✓ Recursive, avoids setup | Can accumulate proofs without new setup |
| Plonk/Marlin | ✗ Universal CRS | One CRS for many circuits; updatable |
| Bulletproofs | ✓ None | No setup, but slower verification |
Complete Example: Proof Flow
PROVER VERIFIER
(has witness x=2 for x³+x+5=35) (has public output 35)
1. Compute witness vars:
y₁=4, y₂=8, y₃=15
z = [1, 2, 4, 8, 15]
2. Encode as polynomials A(x), B(x), C(x)
3. Commit:
C_A = COM(A(x)) ──────────────→
C_B = COM(B(x)) ──────────────→ Verifier stores these
C_C = COM(C(x)) ──────────────→
4. Verifier sends random challenge r
←─── r (random)
5. Prover computes H(x) such that:
A(x)B(x) - C(x) = Z(x)H(x)
6. Creates proof π_h and evaluation proofs
π_h, proofs ──────────────────→
7. Verifier checks pairing equation:
Passes only if witness
satisfies all constraints!
AND proof is valid!
What verifier learns:
- ✓ Constraints are satisfied
- ✗ Nothing about x, y₁, y₂, y₃ (zero-knowledge)
This is the magic of zk-SNARKs: cryptographic proof of correct computation without revealing data.