all commands mentioned below have been added the package.json
's scripts section, making them easily accessible:
yarn run verify
or
yarn run all
1a. if not installed yet, follow the installation instructions for rustup
, circom
and snarkjs
here: https://docs.circom.io/getting-started/installation/
1b. create the (temp) directories needed for the next steps:
mkdir outputs witnesses ceremonies keys verifiers proofs contracts
- generate the
.wasm
file needed to calculate the witness, and the.r1cs
file with the circuit's constraints:
circom circuit.circom --wasm --r1cs -o outputs/
- calculate the witness using the input from
inputs/circuit.json
:
node outputs/circuit_js/generate_witness.js outputs/circuit_js/circuit.wasm inputs/circuit.json witnesses/circuit.wtns
- start ceremony:
snarkjs powersoftau new bn128 12 ceremonies/pot12_0000.ptau -v
- contribute to ceremony:
snarkjs powersoftau contribute ceremonies/pot12_0000.ptau ceremonies/pot12_0001.ptau --name="First contribution" -v
- start generation of phase 2:
snarkjs powersoftau prepare phase2 ceremonies/pot12_0001.ptau ceremonies/pot12_final.ptau -v
- generate
.zkey
file:
snarkjs groth16 setup outputs/circuit.r1cs ceremonies/pot12_final.ptau keys/circuit_0000.zkey
- contribute to phase 2:
snarkjs zkey contribute keys/circuit_0000.zkey keys/circuit_0001.zkey --name="1st Contributor Name" -v
- export the verification key:
snarkjs zkey export verificationkey keys/circuit_0001.zkey verifiers/verification_key.json
- generate proof:
snarkjs groth16 prove keys/circuit_0001.zkey witnesses/circuit.wtns proofs/circuit.json proofs/circuit_public.json
- verify the proof:
snarkjs groth16 verify verifiers/verification_key.json proofs/circuit_public.json proofs/circuit.json
should show the follwing output:
[INFO] snarkJS: OK!
generate a deployable solidity contract that can verify a proof:
snarkjs zkey export solidityverifier keys/circuit_0001.zkey contracts/circuit_verifier.sol