๐Ÿ”— Constraint Systems: Prove Any Computation

Learn how to express logic as mathematical constraints

Build zero-knowledge circuits for rollups

Constraint Systems

A **constraint system** is the mathematical framework that encodes circuit logic into equations a prover must satisfy. It's the bridge between your circuit (gates and wires) and the cryptographic proof system. The prover provides values (witness) that satisfy all constraints, and the verifier checks the proof without seeing the witness.

Different constraint systems offer different tradeoffs: proof size, verification cost, setup requirements, and proving time. Modern ZK-Rollups carefully choose their constraint system based on their specific needs and security model.

Interactive: Constraint System Comparison

Compare the three major constraint systems used in production ZK-Rollups.

R1CS (Rank-1 Constraint System)

Rank-1 Constraint System

Classic constraint system used by Groth16 and many SNARKs

Constraint Format
Each constraint: (A ยท w) * (B ยท w) = (C ยท w)
Used By
Groth16Circomlibsnark
Proof Size
128-192 bytes
Verification Gas
~280k gas
Key Features
โœ“Smallest proofs
โœ“Fast verification
โœ“Trusted setup required
โœ“Circuit-specific

๐Ÿ” R1CS Deep Dive

**Rank-1 Constraint System (R1CS)** is the most common format. Each constraint is a rank-1 bilinear equation:

(A ยท w) * (B ยท w) = (C ยท w)
w:Witness vector (all wire values: inputs, outputs, intermediates)
A, B, C:Constraint matrices that encode circuit structure
ยท:Dot product (linear combination of witness values)

Interactive: R1CS Constraint Visualizer

Visualize how a simple multiplication constraint works. Adjust witness values to see constraint satisfaction.

Constraint: a * b = c

R1CS Representation

A ยท w = 3
*
B ยท w = 4
=
C ยท w = 12
โœ“ Constraint Satisfied
How it works:
  • Matrix A selects witness value a (3)
  • Matrix B selects witness value b (4)
  • Matrix C selects the product c (12)
  • Constraint checks: 3 * 4 = 12 โœ“

Setup Ceremonies

๐Ÿ”’ Trusted Setup (Groth16/R1CS)

Requires multi-party ceremony to generate proving/verification keys. If ceremony is compromised, proofs can be forged.

Example: Zcash Powers of Tau (thousands of participants)

๐Ÿ”“ Universal Setup (PLONK)

One-time ceremony for all circuits. Can be updated incrementally. More flexible but larger proofs.

Example: Aztec Ignition ceremony

๐ŸŒ Transparent (STARKs/AIR)

No trusted setup needed. Uses public randomness. Larger proofs but post-quantum secure.

Example: StarkNet uses FRI protocol

๐Ÿ’ก Choosing a Constraint System

๐Ÿ“Š
Minimize L1 costs: Choose R1CS/Groth16 (smallest proofs, ~280k gas)
๐Ÿ”ง
Flexibility matters: Choose PLONK (universal setup, custom gates)
๐Ÿ›ก๏ธ
Security paranoia: Choose STARKs (transparent, post-quantum)
โšก
Proving speed: R1CS generally faster for simple circuits