ZK Circuit Development
@nullity00
Our Main Characters
Bob Alice
The problem :
Alice has a secret array of 8 alphabets.
Secret = [ e, t, h, e, r, e, u, m ]
Alice wants to check if Bob has the same secret.
#1 : Hey Bob, is the second letter of the secret t ?
#2 : Hey Bob, send me hash of the 2nd alphabet.
Secrets aren’t leaked.
Ref : Justin Thaler’s Proofs & Arguments (Chapter 1)
Ref : SNARKS = PCS + IOP (Lec 2 from MOOC)
Part 1 (Hashing of alphabets)
Commitment - hide now, reveal later
Part 2 (Interaction with Bob)
Zk SNARK
ZK - Zero Knowledge (Doesn’t reveal anything)
S - Succinct (Short)
N - Non Interactive
ARK - ARguments of Knowledge (Proof that prover possesses info)
When ZK ?
hiding - reveals nothing about the committed polynomial
Binding - cannot produce two valid openings for a commitment
A bigger problem
Verify if all the txns done so far in the EVM Network is right
Circuit
(A ZK Program)
Proof System
(zkSNARK)
Proof
Our characters
Prover Verifier
Circom | https://zkrepl.dev/ | https://circomscribe.dev/
pragma circom 2.1.6;
template Circuit() {
signal input a;
signal input b;
signal output c;
c <== a + b ;
c === 77;
}
component main = Circuit();
/* INPUT = {
"a": "5",
"b": "71"
} */
Prove that you know two numbers a & b which when added equate to 77
Circuit.a + Circuit.b - Circuit.c = 0
77 - Circuit.c = 0
Circom
Security Issues
Let’s generate a proof & verify it using a Smart contract
ZK Circuit dev ecosystem
Languages
Libraries
Proof systems
r1cs
Column types in Halo 2
advice columns
private inputs & other witness
instance columns
public inputs
fixed columns
constants &
lookup tables
selector columns
control gates
Vary over each proof
Circuit configuration
a0 | a1 | a2 | a3 | a4 | i0 | i1 | i2 | f0 | f1 | s0 | s1 | s2 |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
About the Halo2 Table
Circom resources
Noir Resources
PLONK
https://github.com/nullity00/plonkathon
https://youtu.be/NqrVcDuQ8hM?si=BZDVcWKT_Uj-yF9g
https://youtu.be/A0oZVEXav24?si=p5tv4tWbJrC7bEgN
Plonk by David Wong : https://www.youtube.com/playlist?list=PLBJMt6zV1c7Gh9Utg-Vng2V6EYVidTFCC
https://github.com/dusk-network/plonk
https://github.com/EspressoSystems/jellyfish
More Plonk
Halo2 Resources
We’d be using Axiom’s halo2-lib for circuit development
Plonky2