This project is a zkSNARK Sudoku verifier using Circom for circuit compilation and Sindri for proof generation. It's structured as a monorepo with separate packages for the circuit and the application.
-
Install Rust (required for Circom):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install Circom (zkSNARK circuit compiler):
cargo install --locked --git https://github.com/iden3/circom.git circom
-
Download the Powers of Tau file (required for circuit setup):
curl -o powersOfTau28_hez_final_16.ptau https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_16.ptau
If updating snarkjs also run
terser packages/app/node_modules/snarkjs/build/snarkjs.js -o packages/app/public/snarkjs.min.js
-
Install dependencies (use legacy peer deps due to potential compatibility issues):
npm install --legacy-peer-deps
-
If using a locally built zkverifyjs, you may need to clean and reinstall:
npm cache clean --force rm -rf node_modules package-lock.json npm install --legacy-peer-deps
-
If needed, manually install zkverifyjs from a local .tgz file:
npm install ./packages/zkverifyjs/zkverifyjs-1.0.0.tgz
- Make sure snarkjs version is the latest
- Use the Rust version of Circom v2 +
circom --version
and not a js package implementation. - Import zkverifyjs latest version.
- Can often require
rm -rf node_modules package-lock.json
&npm cache clean --force
before doing an npm install or manually add from a tgz withnpm install ./packages/zkverifyjs/zkverifyjs-1.0.0.tgz
-
The main circuit is located in
packages/circuit/circuits/sudoku.circom
. If you need to modify the circuit, edit this file. -
After modifying the circuit (or when setting up for the first time), navigate to the circuit directory:
cd packages/circuit
-
Run the compilation script:
./compile_circuit.sh
This script performs the following steps:
- Compiles the circuit using Circom
- Generates the witness
- Sets up the proving key
- Exports the verification key
-
After compilation, you need to create the circuit on Sindri.
-
Run the circuit creation script:
npx tsx compile.ts
Ensure you have the necessary dependencies installed:
npm install sindri tsx
Set your Sindri API key as an environment variable:export SINDRI_API_KEY=<your-api-key>
-
Note the
circuitId
andcircuitName
returned by the script. You'll need to update this in your application code.
Sindri is used for proof generation. To set it up:
-
Sign up at Sindri.app
-
Add your Sindri API key to
packages/app/.env
:SINDRI_API_KEY=<your-api-key> NEXT_PUBLIC_USE_SINDRI=true
-
The Sindri configuration is in
packages/circuit/sindri.json
: -
Update the
circuitIdentifier
in sindri.ts with thecircuitName
orcircuitId
you received when creating the circuit. -
To test proof generation with Sindri, run:
cd packages/circuit npx sindri@latest proof create --input input.json
-
If you encounter issues after updating dependencies, try clearing the cache and reinstalling:
npm cache clean --force rm -rf node_modules package-lock.json npm install --legacy-peer-deps
-
Ensure all dependencies are up to date, including snarkjs, sindri, and circom.
-
After deploying a new version or changing the zkverify .tgz file, force refresh the browser.
- The main Sudoku circuit is in
packages/circuit/circuits/sudoku.circom
. - Proof generation is handled in
packages/app/pages/api/sindri.ts
. - The React hook for interacting with Sindri is in
packages/app/src/hooks/useSindri.ts
.