Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
Go to file
Dmitriy Ryajov 71f1ceb11a
use `Affine*::new_unchecked` to speed up zkey loading
2024-02-15 09:03:54 -06:00
.github/workflows Fix CI by fixing version + add toolchain file (#52) 2023-07-24 18:12:23 +02:00
benches Update ark-circom for arkworks 0.4.0 (#43) 2023-03-16 14:42:33 -07:00
src use `Affine*::new_unchecked` to speed up zkey loading 2024-02-15 09:03:54 -06:00
test-vectors Initial Circom 2 support (#10) 2021-11-29 10:02:46 +02:00
tests Update ark-circom for arkworks 0.4.0 (#43) 2023-03-16 14:42:33 -07:00
.gitignore feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
Cargo.lock Preparatory work for issue #47 (#48) 2023-07-24 09:30:45 -07:00
Cargo.toml description and licence (#54) 2023-07-26 08:54:58 -04:00
LICENSE-APACHE chore: add mit/apache dual license 2022-08-29 10:06:57 -07:00
LICENSE-MIT chore: add mit/apache dual license 2022-08-29 10:06:57 -07:00
README.md Fix CI by fixing version + add toolchain file (#52) 2023-07-24 18:12:23 +02:00
rust-toolchain.toml Fix CI by fixing version + add toolchain file (#52) 2023-07-24 18:12:23 +02:00

README.md

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", 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

  • 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

Known limitations

Currently, due to an issue in our upstream (https://github.com/wasmerio/wasmer/issues/4072), this crate works as expected only up to Rust version 1.67.0; in newer Rust versions, wasmer is currently unsound.

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.