From 19904d5cae5be23ea7dbd9791ac115792781ff49 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 3 Jun 2024 17:01:59 +0100 Subject: [PATCH] add dup function --- src/ffi.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ffi.rs b/src/ffi.rs index f56c677..878cf46 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -63,6 +63,31 @@ fn to_err_code(result: Result>) -> i32 { } } +#[no_mangle] +#[allow(private_interfaces)] +pub unsafe extern "C" fn circom_config_duplicate( + orig_cfg_ptr: *mut CircomBn254Cfg, + cfg_ptr: &mut *mut CircomBn254Cfg, +) -> i32 { + let result = catch_unwind(AssertUnwindSafe(|| { + + let cfg = (*(*orig_cfg_ptr).cfg).clone(); + let proving_key = (*(*orig_cfg_ptr).proving_key).clone(); + + let circom_bn254_cfg = CircomBn254Cfg { + cfg: Box::into_raw(Box::new(cfg)), + proving_key: Box::into_raw(Box::new(proving_key)), + _marker: std::marker::PhantomData, + }; + + *cfg_ptr = Box::into_raw(Box::new(circom_bn254_cfg)); + + ERR_OK + })); + + to_err_code(result) +} + #[no_mangle] #[allow(private_interfaces)] pub unsafe extern "C" fn init_circom_config_with_checks(