remove rng from context and use thread local rng
This commit is contained in:
parent
ddf956e310
commit
18d30300a5
|
@ -10,7 +10,7 @@ use ark_bn254::{Bn254, Fr};
|
||||||
use ark_circom::{read_zkey, CircomBuilder, CircomConfig, CircomReduction};
|
use ark_circom::{read_zkey, CircomBuilder, CircomConfig, CircomReduction};
|
||||||
use ark_crypto_primitives::snark::SNARK;
|
use ark_crypto_primitives::snark::SNARK;
|
||||||
use ark_groth16::{prepare_verifying_key, Groth16, ProvingKey};
|
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 ruint::aliases::U256;
|
||||||
|
|
||||||
use crate::ffi_types::*;
|
use crate::ffi_types::*;
|
||||||
|
@ -50,7 +50,6 @@ struct CircomBn254 {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct CircomCompatCtx {
|
struct CircomCompatCtx {
|
||||||
circom: *mut CircomBn254,
|
circom: *mut CircomBn254,
|
||||||
rng: ThreadRng,
|
|
||||||
_marker: core::marker::PhantomData<(*mut CircomCompatCtx, core::marker::PhantomPinned)>,
|
_marker: core::marker::PhantomData<(*mut CircomCompatCtx, core::marker::PhantomPinned)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +143,6 @@ pub unsafe extern "C" fn init_circom_compat(
|
||||||
ctx_ptr: &mut *mut CircomCompatCtx,
|
ctx_ptr: &mut *mut CircomCompatCtx,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
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 builder = CircomBuilder::new((*(*cfg_ptr).cfg).clone()); // clone the config
|
||||||
let circom_bn254 = CircomBn254 {
|
let circom_bn254 = CircomBn254 {
|
||||||
builder: Box::into_raw(Box::new(builder)),
|
builder: Box::into_raw(Box::new(builder)),
|
||||||
|
@ -153,7 +151,6 @@ pub unsafe extern "C" fn init_circom_compat(
|
||||||
|
|
||||||
let circom_compat_ctx = CircomCompatCtx {
|
let circom_compat_ctx = CircomCompatCtx {
|
||||||
circom: Box::into_raw(Box::new(circom_bn254)),
|
circom: Box::into_raw(Box::new(circom_bn254)),
|
||||||
rng: rng,
|
|
||||||
_marker: core::marker::PhantomData,
|
_marker: core::marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,7 +239,7 @@ pub unsafe extern "C" fn prove_circuit(
|
||||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||||
let circom = &mut *to_circom(ctx_ptr);
|
let circom = &mut *to_circom(ctx_ptr);
|
||||||
let proving_key = (*(*cfg_ptr).proving_key).clone();
|
let proving_key = (*(*cfg_ptr).proving_key).clone();
|
||||||
let rng = &mut (*ctx_ptr).rng;
|
let rng = &mut thread_rng();
|
||||||
|
|
||||||
let circuit = (*circom.builder)
|
let circuit = (*circom.builder)
|
||||||
.clone()
|
.clone()
|
||||||
|
|
Loading…
Reference in New Issue