Skip to content

About

A Groth16 backend for Noir Lang

Resources

Stars

7 stars

Watchers

0 watching

Forks

Repository files navigation

Noir Groth16 Backend

Noir-Groth16 is a Rust workspace that turns Noir artifacts into deterministic witness and R1CS outputs for Groth16 tooling.

git clone https://github.com/jamesbachini/Noir-Groth16/
cd Noir-Groth16
./scripts/run_circuit.sh
./scripts/verify_stellar.sh

Docs

Full documentation available at: https://jamesbachini.github.io/Noir-Groth16/

Pipeline:

  1. Parse Noir artifact JSON + ABI metadata.
  2. Build and solve witnesses with ACVM from ABI-shaped inputs.
  3. Lower supported ACIR opcodes into R1CS.
  4. Emit deterministic artifacts (.r1cs, .wtns, JSON/bin debug outputs).

Quickstart

Prerequisites:

cargo --version
nargo --version
node --version
npm --version
  1. Edit the default circuit and inputs:
  • circuits/src/main.nr
  • circuits/inputs.json
  1. Run the full pipeline from repo root:
./scripts/run_circuit.sh

This performs:

  • nargo compile for circuits/
  • noir-cli interop to emit .r1cs/.wtns
  • snarkjs witness check
  • Groth16 setup, proof generation, and verification

Outputs are written to target/groth16/:

  • target/groth16/interop/circuit.r1cs
  • target/groth16/interop/witness.wtns
  • target/groth16/proof/proof.json
  • target/groth16/proof/public.json
  • target/groth16/proof/verification_key.json

Optional overrides:

CIRCUIT_DIR=/path/to/circuit OUT_DIR=/path/to/output PTAU_POWER=14 ./scripts/run_circuit.sh
  1. Optional on-chain verification
./scripts/verify_stellar.sh

This will use the stellar cli to deploy a verifier contract to testnet. Then invoke it to verify the proof generated by snarkjs.

Getting Started With noir-cli

Build the CLI:

cargo build -p noir-cli

compile-r1cs

Parse artifact and write deterministic parse summary JSON.

noir-cli compile-r1cs test-vectors/fixture_artifact.json --out out/parse

Output:

  • out/parse/parsed.json

witness

Generate witness outputs from artifact + ABI-shaped inputs.

noir-cli witness test-vectors/fixture_artifact.json test-vectors/fixture_inputs.json --out out/witness

Pedantic solving is enabled by default. Pass --no-pedantic to disable strict predicate/selector checks.

Outputs:

  • out/witness/witness_map.json
  • out/witness/witness.bin
  • out/witness/witness.wtns

r1cs-json

Compile supported ACIR into debug R1CS JSON.

noir-cli r1cs-json test-vectors/fixture_artifact.json --out out/circuit.r1cs.json

Output:

  • out/circuit.r1cs.json

interop

Emit snarkjs-friendly iden3 binaries (.r1cs and .wtns).

noir-cli interop test-vectors/fixture_artifact.json test-vectors/fixture_inputs.json --out out/interop

Pedantic solving is enabled by default. Pass --no-pedantic to disable strict predicate/selector checks.

Outputs:

  • out/interop/circuit.r1cs
  • out/interop/witness.wtns

Run Full Example Suite

The code has been tested against a library of generic Noir example circuits. Feel free to add more.

To run the circuits against the backend:

./examples/run_test_suite.sh

Current ACIR Support (crates/noir-r1cs)

Target assumptions:

  • Field: BN254
  • Output format: iden3 .r1cs and .wtns

Program opcode variants

ACIR opcode Status Notes
AssertZero(Expression) Supported Canonical lowering with deterministic row/wire ordering.
MemoryInit { .. } Supported Deterministic memory block initialization.
MemoryOp { .. } Supported (with checks) Static/dynamic memory access lowering; invalid block/index forms fail loudly.
BlackBoxFuncCall(BlackBoxFuncCall) Partially supported Native lowering for AND, XOR, RANGE, Blake2s, Blake3, EcdsaSecp256k1, EcdsaSecp256r1, Poseidon2Permutation, Sha256Compression, MultiScalarMul, and EmbeddedCurveAdd. Other blackboxes are hint-lowered and require downstream constraints on outputs.
BrilligCall { .. } Supported (guarded) Lowered via hint plumbing; predicates must be boolean and outputs must be transitively constrained by non-hint rows.
Call { .. } Supported (guarded) Non-recursive nested calls supported with predicate gating and output binding constraints.

Unsupported / rejected cases

  • Predicates for Call / BrilligCall that are not 0/1.
  • Recursive Call and invalid call targets (including function id 0 / main).
  • Blackbox or Brillig opcodes that expose no outputs when their predicate is not provably false.
  • Hint outputs not constrained by non-hint R1CS rows.

Execution modes

  • Strict mode (default): fails immediately on unsupported/underconstrained behavior.
  • --allow-unsupported: collects unsupported opcode diagnostics and writes unsupported_opcodes.json (for r1cs-json and interop), but still fails and does not emit final .r1cs / .wtns.
  • Witness solving mode defaults to pedantic predicate/selector validation. Use --no-pedantic on witness/interop only when intentionally matching legacy non-pedantic ACVM behavior.

Workspace Layout

  • crates/noir-acir: Noir artifact parsing (including base64/legacy-compatible bytecode decoding), ABI modeling, witness layout helpers.
  • crates/noir-witness: ABI input flattening, pedantic-by-default ACVM witness solving, witness emitters.
  • crates/noir-r1cs: ACIR lowering, strict/diagnostic unsupported handling, and .r1cs / debug JSON writers.
  • crates/noir-cli: CLI entrypoints.
  • circuits/: default Noir circuit package used by the one-command proof script.
  • scripts/run_circuit.sh: compile + prove + verify runner for circuits/.
  • examples/: Noir example packages used by compatibility tests.
  • test-vectors/: Fixture artifacts + inputs used by tests.

Development Workflow

Run before PRs:

cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo test --workspace

Optional interop smoke test:

npm i -g snarkjs
cargo test -p noir-cli --features interop-test -- --ignored

Compatibility corpus differential test (compiles all real Noir projects under examples/, solves via ACVM, lowers to R1CS, checks satisfaction, then tamper-fails constrained wires):

nargo --version
cargo test -p noir-cli compatibility_corpus_differential_checks -- --ignored --nocapture

Disclaimer

Experimental software; not currently suitable for production use.

License

MIT

About

A Groth16 backend for Noir Lang

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages