A Visual Journey from Computation to Cryptographic Proof
To prove you ran a computation correctly without revealing the inputs (zk), we transform a computer program into a mathematical object that can be probabilistically checked.
Computers use boolean logic (AND, XOR). SNARKs work over Fields (numbers modulo a prime \(p\)). We must flatten code into steps that only use Addition (+) and Multiplication (*).
Suppose we want to prove we know an \(x\) such that \(x^3 + x + 5 = 35\). (Witness \(x=3\)).
We break this down into elementary operations (gates):
This is a circuit! To represent this mathematically, we move to R1CS.
R1CS is a system of equations where each equation looks like:
Here \(\mathbf{s}\) is our Solution Vector comprising all variables: \([1, out, x, sym_1, y]\).
Note: The 1 is necessary for constant additions.
Let's map our witness \(x=3\) to the vector \(\mathbf{s}\).
\(x = 3\)
\(sym_1 = x \cdot x = 9\)
\(y = sym_1 \cdot x = 27\)
\(out = 35\)
Vector s: [1, 35, 3, 9, 27]
For the first gate \(x \cdot x = sym_1\):
Check: \((x) * (x) = (sym_1)\) -> \(3 * 3 = 9\). Correct.
Checking thousands of constraints (R1CS) is slow. We want to check Polynomials instead.
Using Lagrange Interpolation, we convert the matrices \(A, B, C\) into polynomials \(A(z), B(z), C(z)\).
where \(Z(z)\) is the "Vanishing Polynomial" \((z-1)(z-2)...(z-n)\), which is zero at every logic gate step. If the equation divides cleanly by \(Z(z)\), it means all constraints are satisfied simultaneously.
The verifier picks a secret random point \(\tau\) (tau). The prover must evaluate the polynomials at \(\tau\). To prevent the prover from cheating or learning \(\tau\), we compute everything inside Elliptic Curve points.
We use a generator \(G\) on an Elliptic Curve. We encrypt values as \(G^x\).
The Prover computes \(G^{A(\tau)}, G^{B(\tau)}, G^{C(\tau)}\) and sends them to the Verifier.
The Verifier checks the QAP equation using a Bilinear Pairing \(e(g, g)\):
Because \(e(G^a, G^b) = e(G, G)^{ab}\), this checks multiplication in the exponent!