mirror of
https://github.com/arnaucube/circom-compat.git
synced 2026-01-07 06:21:33 +01:00
master
As discussed in https://github.com/arkworks-rs/circom-compat/issues/72 it's not currently possible to load parameters from their binary. This would help a lot in browser envoiroments where JS can take care of handling the read and we just open the door in the WASM module to allow to load new ones from the bytes read. The commit adds a change in the tests which now load from binary instead of reading from file. This ensures that the reading is indeed working as expected although we rely on a different fn from `wasmer`.
ark-circom
Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
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(¶ms, circom, &mut rng)?;
// Check that the proof is valid
let pvk = process_vk(¶ms.vk)?;
let verified = verify_with_processed_vk(&pvk, &inputs, &proof)?;
assert!(verified);
Running the tests
Tests require the following installed:
solc. We also recommend using solc-select for more flexibility.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.
Description
Languages
Rust
90.2%
JavaScript
7.8%
Shell
2%