Skip to content

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

License

Notifications You must be signed in to change notification settings

anagrambuild/circom-compat

 
 

Repository files navigation

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 = { git = "https://github.com/gakonst/ark-circom.git" }

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", ark_circom::circom::Inputs::BigInt(3.into()));
builder.push_input("b", ark_circom::circom::Inputs::BigInt(11.into()));
// for 2d array, use
// builder.push_input("a", ark_circom::circom::Inputs::BigIntVec(vec[3.into()]));
// for 3d array, use
// builder.push_input(
//     "a",
//     ark_circom::circom::InputValue::BigIntVecVec(vec![
//         vec![
//             3.into(),
//         ],
//         vec![
//             11.into(),
//         ],
//     ]),
// );

// 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

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

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 82.0%
  • Solidity 7.7%
  • JavaScript 7.3%
  • Shell 1.8%
  • Circom 1.2%