Remco Bloemen a93c8b03d4 | 2 years ago | |
---|---|---|
.github/workflows | 2 years ago | |
benches | 3 years ago | |
src | 2 years ago | |
test-vectors | 3 years ago | |
tests | 2 years ago | |
.gitignore | 3 years ago | |
Cargo.lock | 2 years ago | |
Cargo.toml | 2 years ago | |
README.md | 2 years ago |
Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
Clone the repository and run cd ark-circom/ && cargo doc --open
[dependencies]
ark-circom = { git = "https://github.com/gakonst/ark-circom.git" }
// 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, ¶ms, &mut rng)?;
// Check that the proof is valid
let pvk = prepare_verifying_key(¶ms.vk);
let verified = verify_proof(&pvk, &proof, &inputs)?;
assert!(verified);
Tests require the following installed:
solc
. We also recommend using solc-select for more flexibility.ganache-cli
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.