arnaucube
arnaucube/circom-compatPublic Self-hosted repository
circom-compat/README.md
README.mdRaw
 1# <h1 align="center"> ark-circom </h1>
 2
 3Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
 4
 5![Github Actions](https://github.com/gakonst/ark-circom/workflows/Tests/badge.svg)
 6
 7## Documentation
 8
 9Clone the repository and run `cd ark-circom/ && cargo doc --open`
10
11## Add ark-circom to your repository
12
13```toml
14[dependencies]
15
16ark-circom = { git = "https://github.com/gakonst/ark-circom.git" }
17```
18
19## Example
20
21```rust
22// Load the WASM and R1CS for witness and proof generation
23let cfg = CircomConfig::<Bn254>::new(
24    "./test-vectors/mycircuit.wasm",
25    "./test-vectors/mycircuit.r1cs",
26)?;
27
28// Insert our public inputs as key value pairs
29let mut builder = CircomBuilder::new(cfg);
30builder.push_input("a", 3);
31builder.push_input("b", 11);
32
33// Create an empty instance for setting it up
34let circom = builder.setup();
35
36// Run a trusted setup
37let mut rng = thread_rng();
38let params = generate_random_parameters_with_reduction(circom, &mut rng)?;
39
40// Get the populated instance of the circuit with the witness
41let circom = builder.build()?;
42
43let inputs = circom.get_public_inputs().unwrap();
44
45// Generate the proof
46let proof = prove(&params, circom, &mut rng)?;
47
48// Check that the proof is valid
49let pvk = process_vk(&params.vk)?;
50let verified = verify_with_processed_vk(&pvk, &inputs, &proof)?;
51assert!(verified);
52```
53
54## Running the tests
55
56Tests require the following installed:
571. [`solc`](https://solidity.readthedocs.io/en/latest/installing-solidity.html). We also recommend using [solc-select](https://github.com/crytic/solc-select) for more flexibility.
582. [`ganache-cli`](https://github.com/trufflesuite/ganache-cli#installation)
59
60## Features
61
62- [x] Witness generation using Circom's WASM witness code
63- [x] ZKey parsing into Arkworks Proving Key over BN254
64- [x] Compatibility layer for Ethereum types, so that proofs can be used in Solidity verifiers
65- [x] Proof generations and verification using Arkworks
66- [ ] CLI for common operations
67
68## Acknowledgements
69
70This library would not have been possibly without the great work done in:
71- [`zkutil`](https://github.com/poma/zkutil/)
72- [`snarkjs`](https://github.com/iden3/snarkjs/)
73
74Special shoutout to [Kobi Gurkan](https://github.com/kobigurk/) for all the help in parsing SnarkJS' ZKey file format.