Skip to content

Commit

Permalink
remove rng from context and use thread local rng
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed May 22, 2024
1 parent ddf956e commit 18d3030
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ark_bn254::{Bn254, Fr};
use ark_circom::{read_zkey, CircomBuilder, CircomConfig, CircomReduction};
use ark_crypto_primitives::snark::SNARK;
use ark_groth16::{prepare_verifying_key, Groth16, ProvingKey};
use ark_std::rand::{rngs::ThreadRng, thread_rng};
use ark_std::rand::thread_rng;
use ruint::aliases::U256;

use crate::ffi_types::*;
Expand Down Expand Up @@ -50,7 +50,6 @@ struct CircomBn254 {
#[derive(Debug, Clone)]
struct CircomCompatCtx {
circom: *mut CircomBn254,
rng: ThreadRng,
_marker: core::marker::PhantomData<(*mut CircomCompatCtx, core::marker::PhantomPinned)>,
}

Expand Down Expand Up @@ -144,7 +143,6 @@ pub unsafe extern "C" fn init_circom_compat(
ctx_ptr: &mut *mut CircomCompatCtx,
) -> i32 {
let result = catch_unwind(AssertUnwindSafe(|| {
let rng = thread_rng(); // TODO: use a shared rng - how?
let builder = CircomBuilder::new((*(*cfg_ptr).cfg).clone()); // clone the config
let circom_bn254 = CircomBn254 {
builder: Box::into_raw(Box::new(builder)),
Expand All @@ -153,7 +151,6 @@ pub unsafe extern "C" fn init_circom_compat(

let circom_compat_ctx = CircomCompatCtx {
circom: Box::into_raw(Box::new(circom_bn254)),
rng: rng,
_marker: core::marker::PhantomData,
};

Expand Down Expand Up @@ -242,7 +239,7 @@ pub unsafe extern "C" fn prove_circuit(
let result = catch_unwind(AssertUnwindSafe(|| {
let circom = &mut *to_circom(ctx_ptr);
let proving_key = (*(*cfg_ptr).proving_key).clone();
let rng = &mut (*ctx_ptr).rng;
let rng = &mut thread_rng();

let circuit = (*circom.builder)
.clone()
Expand Down

0 comments on commit 18d3030

Please sign in to comment.