-
Notifications
You must be signed in to change notification settings - Fork 30
/
mod.rs
37 lines (33 loc) · 1.12 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use ark_bls12_381::Bls12_381;
use ark_std::rand::RngCore;
use legogroth16::{
circom::{CircomCircuit, R1CS},
ProvingKey,
};
use std::path::PathBuf;
pub mod bounded_sum;
pub mod mimc_hash;
pub mod multiple_circuits_in_single_proof;
pub mod proof_aggregation;
pub mod set_membership;
pub mod single_circuit_in_a_proof;
/// Given path relative to this crate, return absolute disk path
pub fn abs_path(relative_path: &str) -> String {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push(relative_path);
path.to_string_lossy().to_string()
}
pub fn get_r1cs_and_wasm_bytes<R: RngCore>(
r1cs_file_path: &str,
wasm_file_path: &str,
commit_witness_count: u32,
rng: &mut R,
) -> (ProvingKey<Bls12_381>, R1CS<Bls12_381>, Vec<u8>) {
let circuit = CircomCircuit::<Bls12_381>::from_r1cs_file(abs_path(r1cs_file_path)).unwrap();
let snark_pk = circuit
.generate_proving_key(commit_witness_count, rng)
.unwrap();
let r1cs = R1CS::from_file(abs_path(r1cs_file_path)).unwrap();
let wasm_bytes = std::fs::read(abs_path(wasm_file_path)).unwrap();
(snark_pk, r1cs, wasm_bytes)
}