feat(rln): add rln zkey based circuit abstraction

Different from CircomConfig etc
This commit is contained in:
Oskar Thoren 2022-03-18 14:13:10 +08:00
parent c566b29c6d
commit be1fafd27f
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
2 changed files with 28 additions and 0 deletions

Binary file not shown.

28
rln/src/circuit.rs Normal file
View File

@ -0,0 +1,28 @@
/// Adapted from semaphore-rs
use ark_bn254::{Bn254, Fr};
use ark_circom::{read_zkey, WitnessCalculator};
use ark_groth16::ProvingKey;
use ark_relations::r1cs::ConstraintMatrices;
use core::include_bytes;
use once_cell::sync::Lazy;
use std::io::{Cursor, Write};
use tempfile::NamedTempFile;
const ZKEY_BYTES: &[u8] = include_bytes!("../resources/rln_final.zkey");
const WASM: &[u8] = include_bytes!("../resources/semaphore.wasm");
pub static ZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
let mut reader = Cursor::new(ZKEY_BYTES);
read_zkey(&mut reader).expect("zkey should be valid")
});
pub static WITNESS_CALCULATOR: Lazy<WitnessCalculator> = Lazy::new(|| {
// HACK: ark-circom requires a file, so we make one!
let mut tmpfile = NamedTempFile::new().expect("Failed to create temp file");
let written = tmpfile.write(WASM).expect("Failed to write to temp file");
assert_eq!(written, WASM.len());
let path = tmpfile.into_temp_path();
let result = WitnessCalculator::new(&path).expect("Failed to create witness calculator");
path.close().expect("Could not remove tempfile");
result
});