🛠️ Circuit Fundamentals: R1CS & QAP
Understand the mathematical foundation of ZK circuits
Your Progress
0 / 5 completedCircuit Fundamentals
At their core, ZK circuits are **arithmetic circuits** composed of gates that perform addition and multiplication operations over a finite field. Unlike traditional logic circuits with AND/OR/NOT gates, ZK circuits work with finite field elements and algebraic constraints.
Every computation in a ZK-Rollup—from balance updates to signature verification—must be expressed as a circuit of these algebraic operations. The prover demonstrates they know inputs that satisfy all circuit constraints without revealing the inputs themselves.
🔢 Core Circuit Components
Interactive: Circuit Builder
Build your own arithmetic circuit by adding gates. Each gate type has different properties and constraint costs.
Select Gate Type
Your Circuit
Finite Field Arithmetic
All operations happen in a **finite field** (typically the BN254 curve's scalar field with prime p ≈ 2^254). This means all arithmetic is modular—results "wrap around" at the field size.
Circuit Optimization Techniques
🎯 Linear Combination
Multiple additions can be combined into one constraint:
⚡ Minimize Multiplications
Each multiplication gate creates a constraint. Prefer additions when possible:
🔄 Reuse Intermediate Values
Store and reuse computed values instead of recomputing:
out1 = temp + c
out2 = temp + d
💡 Key Insights
- ✓ZK circuits are arithmetic circuits over finite fields (not boolean logic)
- ✓Multiplication gates are expensive—they create R1CS/Plonk constraints
- ✓Addition gates are cheap—multiple can be combined linearly
- ✓Circuit size determines proving time: fewer gates = faster proofs