MCPcopy Index your code
hub / github.com/arkworks-rs/circom-compat

github.com/arkworks-rs/circom-compat @v0.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.0 ↗ · + Follow
217 symbols 530 edges 21 files 32 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ark-circom

Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.

Github Actions

Documentation

Clone the repository and run cd ark-circom/ && cargo doc --open

Add ark-circom to your repository

[dependencies]

ark-circom = "0.5.0"

Example

// Load the WASM and R1CS for witness and proof generation
let cfg = CircomConfig::<Bn254>::new(
    "./test-vectors/mycircuit.wasm",
    "./test-vectors/mycircuit.r1cs",
)?;

// Insert our public inputs as key value pairs
let mut builder = CircomBuilder::new(cfg);
builder.push_input("a", 3);
builder.push_input("b", 11);

// Create an empty instance for setting it up
let circom = builder.setup();

// Run a trusted setup
let mut rng = thread_rng();
let params = generate_random_parameters_with_reduction(circom, &mut rng)?;

// Get the populated instance of the circuit with the witness
let circom = builder.build()?;

let inputs = circom.get_public_inputs().unwrap();

// Generate the proof
let proof = prove(&params, circom, &mut rng)?;

// Check that the proof is valid
let pvk = process_vk(&params.vk)?;
let verified = verify_with_processed_vk(&pvk, &inputs, &proof)?;
assert!(verified);

Running the tests

Tests require the following installed:

  1. solc. We also recommend using solc-select for more flexibility.
  2. ganache-cli

Features

  • [x] Witness generation using Circom's WASM witness code
  • [x] ZKey parsing into Arkworks Proving Key over BN254
  • [x] Compatibility layer for Ethereum types, so that proofs can be used in Solidity verifiers
  • [x] Proof generations and verification using Arkworks
  • [ ] CLI for common operations

Notes

The prover key generated by circom differs from the one generated by arkworks' groth16 library. While the format is the same, it represents different values. Circom 'prepares' the powers of tau by converting them to Lagrange base, i.e. from s^i.G -> L_i(s).G. This affects the witness generation process, and the caller needs to ensure the correct R1CSToQAP implementer is used: - use CircomReduction for working with circom-generated files, - use LibsnarkReduction for setup produced using the arkworks backend.

Acknowledgements

This library would not have been possibly without the great work done in:

Special shoutout to Kobi Gurkan for all the help in parsing SnarkJS' ZKey file format.

Core symbols most depended-on inside this repo

Shape

Function 96
Method 92
Class 28
Enum 1

Languages

Rust76%
TypeScript24%

Modules by API surface

src/zkey.rs45 symbols
src/witness/witness_calculator.rs27 symbols
src/witness/memory.rs26 symbols
test-vectors/witness_calculator.js20 symbols
src/ethereum.rs19 symbols
test-vectors/mycircuit_js/witness_calculator.js16 symbols
test-vectors/circuit2_js/witness_calculator.js16 symbols
src/witness/circom.rs12 symbols
src/circom/r1cs_reader.rs9 symbols
src/circom/builder.rs9 symbols
tests/groth16.rs4 symbols
src/circom/qap.rs4 symbols

For agents

$ claude mcp add circom-compat \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page