Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sudoku demo to Quantum's Groth16 showcase #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,55 @@
# Build & binary files
build/
dist/
bin/
target/
*.exe
*.dll
*.so
*.dylib
*.test
*.out
*.elf

# Circuit artifacts
*.r1cs
*.sym
*.wasm
*.wtns
*.zkey
*.ptau
circuit_js/
circuit_cpp/
circuit_data/
proof.json
public.json
verification_key.json
witness.wtns

# Dependencies
node_modules/
package-lock.json
Cargo.lock
**/*.rs.bk

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# Logs & debug
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# OS files
.DS_Store
Thumbs.db

# Environment variables
.env
target/
params/
.env.local
.env.*.local
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.PHONY: all clean gnark_groth16 snarkjs_groth16 risc0 sp1 plonky2 gnark_plonk halo2_kzg halo2_kzg_evm sudoku_groth16 setup

setup:
@bash setup.sh && npm install && node test_credentials.js

all: setup gnark_groth16 snarkjs_groth16 risc0 sp1 plonky2 gnark_plonk halo2_kzg halo2_kzg_evm sudoku_groth16

gnark_groth16:
cd circuits/gnark_groth16 && go run circuit.go
node quantum_test.js --scheme gnark_groth16

snarkjs_groth16:
cd circuits/snarkjs_groth16 && ./build.sh
node quantum_test.js --scheme snarkjs_groth16

risc0:
cd circuits/risc0 && cargo run -r --package risc0 --bin risc0
node quantum_test.js --scheme risc0

sp1:
cd circuits/sp1/program && cargo prove build --output-directory ../elf
cd circuits/sp1 && cargo run -r --package sp1 --bin sp1
node quantum_test.js --scheme sp1

plonky2:
cd circuits/plonky2 && cargo run -r --package plonky2:0.1.0 --bin plonky2
node quantum_test.js --scheme plonky2

gnark_plonk:
cd circuits/gnark_plonk && go run circuit.go
node quantum_test.js --scheme gnark_plonk

halo2_kzg:
cd circuits/halo2_kzg && cargo run -r --package halo2_kzg --bin halo2_kzg
node quantum_test.js --scheme halo2_kzg

halo2_kzg_evm:
cd circuits/halo2_kzg_evm && cargo run -r --package halo2_kzg_evm --bin halo2_kzg_evm
node quantum_test.js --scheme halo2_kzg_evm

sudoku_groth16:
cd circuits/sudoku_groth16 && ./build.sh
node quantum_test.js --scheme sudoku_groth16

clean:
cd circuits/risc0 && cargo clean
cd circuits/sp1 && cargo clean
cd circuits/plonky2 && cargo clean
cd circuits/halo2_kzg && cargo clean
cd circuits/halo2_kzg_evm && cargo clean
cd circuits/snarkjs_groth16 && \
rm -f *.ptau *.zkey *.r1cs *.sym witness.wtns proof.json public.json verification_key.json input.json && \
rm -rf circuit_js circuit_data && \
cd circuit_cpp && make clean && cd .. && \
rm -rf circuit_cpp/circuit
56 changes: 26 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# quantum-demo

Contains demos for different proving schemes supported by Quantum.
This repo contains demos for different proving schemes supported by Quantum.

### Test Quantum API (Circuit Registration + Proof Submission)
## Quick Start
Install dependencies and setup credentials
```bash
make setup
```
To clean build artifacts, run:
```bash
make clean
```

- schemes = {gnark_groth16, snarkjs_groth16, risc0, sp1, plonky2, gnark_plonk, halo2_kzg, halo2_kzg_evm}
- `node quantum_test.js --scheme gnark_groth16`
## Testing Individual Schemes

### Generate circuit data
You can build and test individual proving schemes using:

```bash
make <scheme_name>
```

Available schemes:
- `gnark_groth16`
- `snarkjs_groth16`
- `risc0`
- `sp1`
- `plonky2`
- `gnark_plonk`
- `halo2_kzg`
- `halo2_kzg_evm`

- gnark_groth16
- `cd circuits/gnark_groth16`
- `go run circuit.go`
- snarkjs_groth16
- circuits/snarkjs_groth16/circuit.circom
- risc0
- `cd circuits/risc0`
- `cargo run -r --package risc0 --bin risc0`
- sp1
- `cd circuits/sp1/program`
- `cargo prove build --output-directory circuits/sp1/elf`
- `cd ..`
- `cargo run -r --package sp1 --bin sp1`
- plonky2
- `cd circuits/plonky2`
- `cargo run -r --package plonky2:0.1.0 --bin plonky2`
- gnark_plonk plonky2
- cd `circuits/gnark_plonk`
- `go run circuit.go`
- halo2_kzg
- `cd circuits/halo2_kzg`
- `cargo run -r --package halo2_kzg --bin halo2_kzg`
- halo2_kzg_evm
- `cd circuits/halo2_kzg_evm`
- `cargo run -r --package halo2_kzg_evm --bin halo2_kzg_evm`
3 changes: 0 additions & 3 deletions circuits/gnark_groth16/circuit_data/pis.json

This file was deleted.

Binary file removed circuits/gnark_groth16/circuit_data/proof.bin
Binary file not shown.
Binary file removed circuits/gnark_groth16/circuit_data/vKey.bin
Binary file not shown.
3 changes: 0 additions & 3 deletions circuits/gnark_plonk/circuit_data/pis.json

This file was deleted.

Binary file removed circuits/gnark_plonk/circuit_data/proof.bin
Binary file not shown.
Binary file removed circuits/gnark_plonk/circuit_data/vKey.bin
Binary file not shown.
1 change: 0 additions & 1 deletion circuits/halo2_kzg/circuit_data/instances.json

This file was deleted.

Binary file removed circuits/halo2_kzg/circuit_data/proof.bin
Binary file not shown.
1 change: 0 additions & 1 deletion circuits/halo2_kzg/circuit_data/protocol.json

This file was deleted.

1 change: 0 additions & 1 deletion circuits/halo2_kzg/circuit_data/sg2.json

This file was deleted.

1 change: 0 additions & 1 deletion circuits/halo2_kzg_evm/circuit_data/instances.json

This file was deleted.

Binary file removed circuits/halo2_kzg_evm/circuit_data/proof.bin
Binary file not shown.
1 change: 0 additions & 1 deletion circuits/halo2_kzg_evm/circuit_data/protocol.json

This file was deleted.

1 change: 0 additions & 1 deletion circuits/halo2_kzg_evm/circuit_data/sg2.json

This file was deleted.

Binary file removed circuits/plonky2/circuit_data/common_data.bin
Binary file not shown.
Binary file removed circuits/plonky2/circuit_data/proof.bin
Binary file not shown.
Binary file removed circuits/plonky2/circuit_data/verifier_only.bin
Binary file not shown.
1 change: 0 additions & 1 deletion circuits/risc0/circuit_data/method_id.json

This file was deleted.

Binary file removed circuits/risc0/circuit_data/receipt.bin
Binary file not shown.
1 change: 0 additions & 1 deletion circuits/risc0/circuit_data/receipt.json

This file was deleted.

59 changes: 59 additions & 0 deletions circuits/snarkjs_groth16/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Constants
INPUT_VALUE=3
CIRCUIT_NAME="circuit"
POWER_LEVEL=12
CURVE="bn128"

# Directory structure
CIRCUIT_JS_DIR="circuit_js"
CIRCUIT_CPP_DIR="circuit_cpp"
CIRCUIT_DATA_DIR="circuit_data"

setup_directories() {
mkdir -p "$CIRCUIT_JS_DIR"
mkdir -p "$CIRCUIT_DATA_DIR"
printf "{\"x\": \"$INPUT_VALUE\"}\n" > input.json
}

compile_circuit() {
circom "$CIRCUIT_NAME.circom" --r1cs --wasm --sym
cd "$CIRCUIT_CPP_DIR" && make && cd ..
}

setup_powers_of_tau() {
local POT_0="pot12_0000.ptau"
local POT_1="pot12_0001.ptau"
local POT_FINAL="pot12_final.ptau"

snarkjs powersoftau new "$CURVE" "$POWER_LEVEL" "$POT_0"
snarkjs powersoftau contribute "$POT_0" "$POT_1" --name="First contribution" -e="random text"
snarkjs powersoftau prepare phase2 "$POT_1" "$POT_FINAL"
}

generate_proving_key() {
local ZKEY_0="circuit_0000.zkey"
local ZKEY_FINAL="circuit_final.zkey"

snarkjs groth16 setup "$CIRCUIT_NAME.r1cs" pot12_final.ptau "$ZKEY_0"
snarkjs zkey contribute "$ZKEY_0" "$ZKEY_FINAL" --name="1st Contributor" -e="random text"
snarkjs zkey export verificationkey "$ZKEY_FINAL" "$CIRCUIT_DATA_DIR/verification_key.json"
}

generate_proof() {
node "$CIRCUIT_JS_DIR/generate_witness.js" "$CIRCUIT_JS_DIR/$CIRCUIT_NAME.wasm" input.json witness.wtns
snarkjs groth16 prove circuit_final.zkey witness.wtns "$CIRCUIT_DATA_DIR/proof.json" "$CIRCUIT_DATA_DIR/public.json"
rm input.json
}

main() {
setup_directories
compile_circuit
setup_powers_of_tau
generate_proving_key
generate_proof
}

# Executes main function
main
Binary file removed circuits/snarkjs_groth16/circuit.r1cs
Binary file not shown.
4 changes: 0 additions & 4 deletions circuits/snarkjs_groth16/circuit.sym

This file was deleted.

Binary file removed circuits/snarkjs_groth16/circuit_0000.zkey
Binary file not shown.
Binary file removed circuits/snarkjs_groth16/circuit_0001.zkey
Binary file not shown.
Loading