Circom Prover
Circom prover is a Rust library for generating and verifying proofs for Circom circuits. It is designed to be used in cross-platform applications, and is compatible with the Mopro library.
It supports multiple adapters, allowing you to choose the one that best optimizes performance.
Adapters
Witness Generation
Proof Generation
Performance
It speeds up circom proof by ~100x comparing to arkworks-rs/circom-compat in keccak256 circuits. We will provide more benchmarks with different adapters in the future. And you can also check the Mopro documentation for more benchmarks. We’ve also published a blog post that outlines the pros and cons of each adapter: Comparison of Circom Provers.
Usage
Install circom-prover
Depends on the witness generation method, build the rust witness function first. Here is how to use the rust-witness generator.
Include the crate in your Cargo.toml:
[]
= "0.1"
[]
= "0.1"
In build.rs, add the following code to compile the witness generator wasm sources (.wasm) into a native library and link to it:
transpile_wasm;
// e.g. rust_witness::transpile::transpile_wasm("./test-vectors".to_string());
// The directory should contain the following files:
// - <circuit name>.wasm
Proof Generation
use HashMap;
use ;
// Prepare witness generator
witness!;
// Prepare inputs
let inputs = from;
let input_str = to_string.unwrap;
// Prepare zkey path
let zkey_path = "./test-vectors/multiplier2_final.zkey".to_string;
// Generate proof
let result = prove.unwrap;
Proof Verification
// Verify proof
let valid = verify.unwrap;
Advanced usage
circom-prover also supports witnesscalc, circom-witnesscalc and rapidsnark for advanced users. These tools offer better performance but may not be entirely stable.
Below is a tutorial on how to enable witnesscalc, circom-witnesscalc and rapidsnark.
witnesscalc
Setup features flags
[]
= { = "0.1", = false, = ["witnesscalc"] }
= "0.1"
[]
= "0.1"
Install dependencies:
- Linux:
- MacOS
Rust toolchain: cargo 1.81.0 (2dbb1af80 2024-08-20)
In build.rs, add the following code to compile the witness generator cpp and dat sources (.cpp, .dat) into a native library and link to it:
build_and_link;
// e.g. witnesscalc_adapter::build_and_link("../testdata");
// The directory should contain the following files:
// - <circuit name>.cpp
// - <circuit name>.dat
Usage
let result = prove.unwrap;
circom-witnesscalc
Prepare the graph.
Clone the repo: https://github.com/iden3/circom-witnesscalc, go to the directory circom-witnesscalc, and run:
Setup features flags
[]
= { = "0.1", = false, = ["circom-witnesscalc"] }
Install dependencies:
- Linux:
Usage
// import graph path
const GRAPH_PATH: &str = "./test-vectors/circom/multiplier2.bin";
graph!;
let result = prove.unwrap;
rapidsnark
[]
= { = "0.1", = false, = ["rapidsnark"] }
[]
= { = "0.1", = false, = ["rapidsnark"] }
use ;
use HashMap;
use Result;
// Prepare witness generator
witness!;
// Prepare inputs
let inputs = from;
let input_str = to_string.unwrap;
// Prepare zkey path
let zkey_path = "./test-vectors/multiplier2_final.zkey".to_string;
// Generate proof
let result = prove
.unwrap;
Proof Verification
// Verify proof
let valid = verify.unwrap;
Community
- X account:
- Telegram group:
- Mopro Documentation: https://zkmopro.org
Acknowledgements
This work is sponsored by PSE.