Use the Circom compiler to generate the circuit artifacts with the following flags:
circom <circuit>.circom --r1cs --c --no<-asm -O0 # or -O1 / -O2
Try different optimization levels (O0
, O1
, O2
) and select the one that yields the fewest constraints.
This compilation is done once per circuit and is not included in the node's runtime.
Use snarkjs
with the compiled .r1cs
file and a trusted Common Reference String (CRS) to generate:
.zkey
file (proving key)verification_key.json
file (verifying key)Example command:
snarkjs groth16 setup <circuit>.r1cs <ptau_file>.ptau <circuit>.zkey
snarkjs zkey export verificationkey <circuit>.zkey verification_key.json
The .zkey
is passed to the prover, and the verification key is hardcoded in the node.
Verification can be performed using Arkworks, implementing a Groth16 verifier with the verification key values embedded.
Use Rapidsnark to generate a Groth16 proof.
Input:
.zkey
proving key.wtns
file (witness) generated from the circuit + input valuesOutput:
proof.json
: the zero-knowledge proofpublic.json
: the public inputs and outputsExample command:
rapidsnark <circuit>.zkey <witness>.wtns