Examples of zk-SNARK verification on Starknet using Garaga.
This repository demonstrates the process of verifying Groth16 proofs on Starknet:
- Using arkworks-examples repository: Import verification key and proof in JSON format from the
arkworks-examplessubmodule - Verifier contract generation: Use Garaga to generate a Cairo Groth16 verifier contract
- Fork testing on Sepolia: Tests use Sepolia testnet fork to access pre-declared garaga contracts
# Clone the repository with submodules
git clone --recurse-submodules https://github.com/zk-examples/zk-starknet-examples.git
# Install garaga (requires Python 3.10+)
pip install garagaUsing the verification key from arkworks-examples, generate a Cairo Groth16 verifier contract:
garaga gen --system groth16 --vk arkworks-examples/merkle/export/verification_key.jsonThis command will create the verifier contract in the merkle/src/ directory.
Generate calldata for snforge tests from the verification key and proof:
cd merkle
garaga calldata \
--system groth16 \
--vk ../arkworks-examples/merkle/export/verification_key.json \
--proof ../arkworks-examples/merkle/export/proof.json \
--format snforge \
--output-path testsThis command will create the tests/proof_calldata.txt file with verification data.
Run tests with Sepolia testnet fork:
snforge testMake sure the SEPOLIA_RPC_URL environment variable is set before running the tests.
Gnark examples use verification keys and proofs from the gnark/ directory for BLS12_381 and BN254 curves.
Generate Cairo Groth16 verifier contracts for both curves:
garaga gen --system groth16 --vk gnark-to-snarkjs/test/cubic/keys/verification_key_gnark_bls12381.json
garaga gen --system groth16 --vk gnark-to-snarkjs/test/cubic/keys/verification_key_gnark_bn254.jsonBLS12_381:
cd gnark_bls12_381
garaga calldata \
--system groth16 \
--vk ../gnark-to-snarkjs/test/cubic/keys/verification_key_gnark_bls12381.json \
--proof ../gnark-to-snarkjs/test/cubic/proofs/proof_gnark_bls12381.json \
--public-inputs ../gnark-to-snarkjs/test/cubic/proofs/public.json \
--format snforge \
--output-path tests
cd ..BN254:
cd gnark_bn254
garaga calldata \
--system groth16 \
--vk ../gnark-to-snarkjs/test/cubic/keys/verification_key_gnark_bn254.json \
--proof ../gnark-to-snarkjs/test/cubic/proofs/proof_gnark_bn254.json \
--public-inputs ../gnark-to-snarkjs/test/cubic/proofs/public.json \
--format snforge \
--output-path tests
cd ..Run tests for each project:
source .evn
cd gnark_bls12_381 && snforge test && cd ..
cd gnark_bn254 && snforge testMake sure the SEPOLIA_RPC_URL environment variable is set before running the tests.