2021-07-26 14:59:11 +00:00
# <h1 align="center"> ark-circom </h1>
Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
![Github Actions ](https://github.com/gakonst/ark-circom/workflows/Tests/badge.svg )
## Documentation
Clone the repository and run `cd ark-circom/ && cargo doc --open`
## Add ark-circom to your repository
```toml
[dependencies]
2022-02-01 16:11:30 +00:00
ark-circom = { git = "https://github.com/gakonst/ark-circom.git" }
2021-07-26 14:59:11 +00:00
```
2021-07-26 15:13:46 +00:00
## Example
```rust
// 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();
2023-03-16 21:42:33 +00:00
let params = generate_random_parameters_with_reduction(circom, & mut rng)?;
2021-07-26 15:13:46 +00:00
// Get the populated instance of the circuit with the witness
let circom = builder.build()?;
let inputs = circom.get_public_inputs().unwrap();
// Generate the proof
2023-03-16 21:42:33 +00:00
let proof = prove(& params, circom, & mut rng)?;
2021-07-26 15:13:46 +00:00
// Check that the proof is valid
2023-03-16 21:42:33 +00:00
let pvk = process_vk(¶ms.vk)?;
let verified = verify_with_processed_vk(& pvk, & inputs, &proof)?;
2021-07-26 15:13:46 +00:00
assert!(verified);
```
2021-07-26 14:59:11 +00:00
## Running the tests
Tests require the following installed:
1. [`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.
2. [`ganache-cli` ](https://github.com/trufflesuite/ganache-cli#installation )
## Features
- [x] Witness generation using Circom's WASM witness code
- [x] ZKey parsing into Arkworks Proving Key over BN254
- [x] Compatibility layer for Ethereum types, so that proofs can be used in Solidity verifiers
- [x] Proof generations and verification using Arkworks
- [ ] CLI for common operations
2023-07-24 16:12:23 +00:00
## 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.
2021-07-26 14:59:11 +00:00
## Acknowledgements
This library would not have been possibly without the great work done in:
- [`zkutil` ](https://github.com/poma/zkutil/ )
- [`snarkjs` ](https://github.com/iden3/snarkjs/ )
Special shoutout to [Kobi Gurkan ](https://github.com/kobigurk/ ) for all the help in parsing SnarkJS' ZKey file format.