Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove rng from context and use thread local rng #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading