groth16-compile

star 1

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.

HorizenLabs By HorizenLabs schedule Updated 2/3/2026

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:

# 1. Install Rust if not present
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

# 2. Install build tools (Linux/Docker)
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

# 3. Clone and build circom
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

# 4. Ensure PATH is updated
source "$HOME/.cargo/env"

# 5. Verify
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

# Choose size based on constraints (see reference.md for full table)
# pot12 = up to 4,096 constraints
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)

# Phase 2: Circuit-specific setup
npx snarkjs groth16 setup \
    build/<circuit_name>.r1cs \
    build/pot12_final.ptau \
    build/<circuit_name>_0000.zkey

# REQUIRED: Add contribution (DO NOT skip this!)
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

  1. Verify all files exist in build/
  2. Run /groth16-prove to generate proofs
  3. Keep .zkey file secure

Checklist

  • Prerequisites installed (circom auto-installed if missing, snarkjs)
  • Circuit compiled (r1cs + wasm generated)
  • Powers of Tau downloaded (correct size for constraints)
  • Phase 2 contribution completed (not using _0000.zkey!)
  • Verification key exported
  • Cleanup done (removed _0000.zkey)
  • Reminded user of next steps

Automation Principles

DO NOT ask the user to do things manually. This skill should:

  1. Auto-install circom if missing (using Rust/cargo)
  2. Auto-install snarkjs if missing (npm install snarkjs)
  3. Auto-download the correct Powers of Tau file
  4. Run all compilation steps automatically
  5. Only stop if there's an unrecoverable error

Additional Resources

Install via CLI
npx skills add https://github.com/HorizenLabs/hl-claude-marketplace --skill groth16-compile
Repository Details
star Stars 1
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator