| name | groth16-compile |
| description | Compile Circom circuits and run Groth16 trusted setup for zkVerify. Use when the user wants to compile a circuit, generate r1cs/wasm/zkey files, run powers of tau ceremony, or prepare for proof generation. |
| argument-hint | ["circuit-name"] |
Compile Circom Circuit for zkVerify
Help the user compile their Circom circuit and run the trusted setup ceremony to prepare for proof generation.
Arguments
If invoked with an argument (e.g., /groth16-compile password_hash), use it as the circuit name.
If no argument provided, look for .circom files in circuits/ or ask the user which circuit to compile.
Scope
This skill compiles Circom circuits for Groth16 proof generation with snarkjs.
What this covers:
- Circom → R1CS compilation
- Groth16 trusted setup (Powers of Tau + phase 2 contribution)
- Proving key and verification key generation
Alternatives not covered:
- Noir (Aztec) → compiles to Ultraplonk/Ultrahonk, not Groth16
- Leo (Aleo) → targets Aleo's proof system
- Cairo (Starknet) → uses STARKs, not SNARKs
Pre-flight Check
Before compiling, verify tools are installed:
circom --version && npx snarkjs --version
| Check | If Missing |
|---|
| circom | Auto-install (see below) |
| snarkjs | npm install snarkjs |
| circomlib | npm install circomlib (if circuit uses it) |
IMPORTANT: Auto-Install Circom if Missing
If circom is not installed, DO NOT stop and ask the user to install it manually. Instead, automatically install it by running these commands:
if ! command -v cargo &> /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
fi
if [ -f /etc/debian_version ]; then
apt-get update && apt-get install -y build-essential git || sudo apt-get update && sudo apt-get install -y build-essential git
fi
if [ ! -d /tmp/circom ]; then
git clone https://github.com/iden3/circom.git /tmp/circom
fi
cd /tmp/circom && cargo build --release && cargo install --path circom
source "$HOME/.cargo/env"
circom --version
Always proceed with installation automatically. Only stop if the installation itself fails after multiple attempts.
Compilation Steps
Step 1: Compile Circuit
mkdir -p build
circom circuits/<circuit_name>.circom \
--r1cs \
--wasm \
--sym \
-o build/ \
-l node_modules
Note: The -l node_modules flag tells circom where to find circomlib.
Step 2: Check Constraint Count
npx snarkjs r1cs info build/<circuit_name>.r1cs
Note the constraint count to choose the right Powers of Tau size.
Step 3: Download Powers of Tau
curl -L https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_12.ptau \
-o build/pot12_final.ptau
| Constraints | ptau | File |
|---|
| < 4,096 | 12 | 4.8 MB |
| < 16,384 | 14 | 19 MB |
| < 65,536 | 16 | 75 MB |
| < 262,144 | 18 | 300 MB |
See reference.md for larger sizes.
Step 4: Generate Proving Key (zkey)
npx snarkjs groth16 setup \
build/<circuit_name>.r1cs \
build/pot12_final.ptau \
build/<circuit_name>_0000.zkey
npx snarkjs zkey contribute \
build/<circuit_name>_0000.zkey \
build/<circuit_name>.zkey \
--name="Circuit contribution" -v \
-e="$(openssl rand -hex 32)"
WARNING: The _0000.zkey is NOT safe for production. The contribution step is mandatory.
Step 5: Export Verification Key
npx snarkjs zkey export verificationkey \
build/<circuit_name>.zkey \
build/verification_key.json
Step 6: Clean Up
rm -f build/<circuit_name>_0000.zkey
Expected Output
build/
├── <circuit_name>.r1cs # Constraint system
├── <circuit_name>.zkey # Proving key
├── <circuit_name>_js/
│ └── <circuit_name>.wasm # Witness calculator
├── pot12_final.ptau # Powers of Tau (reusable)
└── verification_key.json # For zkVerify
After Compilation
- Verify all files exist in
build/
- Run
/groth16-prove to generate proofs
- Keep
.zkey file secure
Checklist
Automation Principles
DO NOT ask the user to do things manually. This skill should:
- Auto-install circom if missing (using Rust/cargo)
- Auto-install snarkjs if missing (
npm install snarkjs)
- Auto-download the correct Powers of Tau file
- Run all compilation steps automatically
- Only stop if there's an unrecoverable error
Additional Resources