1 of 23

ZK Circuit Development

@nullity00

2 of 23

Our Main Characters

Bob Alice

3 of 23

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)

4 of 23

Ref : SNARKS = PCS + IOP (Lec 2 from MOOC)

Part 1 (Hashing of alphabets)

  • Message → Polynomial
  • Eg: [1, 3, 4] → x2 + 3x + 4
  • a1 * G + a2 * G2 + a3 * G3 + ..
  • Polynomial Commitment Scheme

Commitment - hide now, reveal later

Part 2 (Interaction with Bob)

  • Hey the hash of 2nd …
  • Hey you just sent me your polynomial commitment,
  • I’m gonna open it at a random point !
  • Made Non Interactive, to avoid collusion

5 of 23

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

6 of 23

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

7 of 23

Our characters

Prover Verifier

8 of 23

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

9 of 23

Circom

  • Signals are immutable, types : Inputs, output, intermediate
  • Variables (var) : used to build up constraints
  • All operations have to be of the form a*b + c
  • Non quadratic constraints are not allowed ( x * x = x2 )
  • ← assignment operator (Not calculated by the verifier)
  • === constraint generator
  • <== Assign & constraint in a single step
  • Constant Computation Graph
  • Endless loops
  • Scalar field is ~ 2254

10 of 23

Security Issues

  • Malicious Provers
  • Do not use <-- unless you know what you are doing
  • Do not leave inputs unassigned
  • If you use an integer of 2255 bits in circom, there would be an overflow
  • Always check bit lengths

11 of 23

Let’s generate a proof & verify it using a Smart contract

  1. Install circom : https://docs.circom.io/getting-started/installation/
  2. Install snark js : https://github.com/iden3/snarkjs
  3. Tutorials : https://www.rareskills.io/post/circom-tutorial , https://medium.com/@yujiangtham/writing-a-zero-knowledge-dapp-fd7f936e2d43
  4. https://github.com/nullity00/demo-circ

12 of 23

ZK Circuit dev ecosystem

Languages

  • Circom
  • Noir
  • Zokrates
  • Leo
  • Cairo
  • Lurk

Libraries

  • Bellman
  • arkworks
  • Halo2 (zcash)
  • Halo2 (pse/axiom)
  • Plonky2
  • Plonky2x(succinct)

Proof systems

  • Groth16(kzg+groth)
  • Plonk(ipa + plonk)
  • Plonk(kzg + plonk)
  • plonky2(fri + plonk)
  • boojum(fri+plonk)

13 of 23

r1cs

14 of 23

15 of 23

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

16 of 23

About the Halo2 Table

  • Column is a polynomial
  • For each column i in the table, construct a Lagrange polynomial Li(x)
  • Rows are roots of unity (1, ω, ω2, ω3, ω4, ω5, ω6, ω7, ….)
  • Cell = Evaluation of a polynomial at the root of unity ..
  • Evaluation of column i at cell j, Lij) = …
  • Selector - gate on / off
  • 2k rows & m columns

17 of 23

Circom resources

18 of 23

Noir Resources

19 of 23

PLONK

20 of 23

More Plonk

21 of 23

Halo2 Resources

22 of 23

We’d be using Axiom’s halo2-lib for circuit development

23 of 23

Plonky2