Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
Go to file
oskarth b1daefca96
Early exit in error callback from Wasm (#9)
* Early exit in error callback from Wasm

This avoids Wasm execution hanging due to problems such as wrong public
input.

Mimics circom_runtime behaviour with less detailed debug information.

See https://github.com/iden3/circom_runtime/blob/master/js/witness_calculator.js#L52-L64

Adds test for wrong public input. Without early exit, the test stalls.
With it, the Circom build step fails as expected.

* chore: clean up error handling

* ci: add caching

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
2021-11-18 12:03:37 +02:00
.github/workflows Early exit in error callback from Wasm (#9) 2021-11-18 12:03:37 +02:00
benches feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
src Early exit in error callback from Wasm (#9) 2021-11-18 12:03:37 +02:00
test-vectors feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
tests Early exit in error callback from Wasm (#9) 2021-11-18 12:03:37 +02:00
.gitignore feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
Cargo.lock feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
Cargo.toml feat: benchmarks (#3) 2021-09-08 21:52:17 +03:00
README.md chore: trim deps 2021-07-26 18:13:46 +03: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-rs" }

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::<Bn254, _, _>(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(circom, &params, &mut rng)?;

// Check that the proof is valid
let pvk = prepare_verifying_key(&params.vk);
let verified = verify_proof(&pvk, &proof, &inputs)?;
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.