diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 9ed1b39a79..589143baa3 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -107,7 +107,7 @@ pub type NovaCircuitShape = R1CSWithArity>; pub type NovaPublicParams = nova::PublicParams, E2, C1, C2>; /// A struct that contains public parameters for the Nova proving system. -#[derive(Clone, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(bound = "")] pub struct PublicParams> where diff --git a/src/public_parameters/mem_cache.rs b/src/public_parameters/mem_cache.rs index 64d4899a3f..3ee97dd973 100644 --- a/src/public_parameters/mem_cache.rs +++ b/src/public_parameters/mem_cache.rs @@ -40,6 +40,10 @@ pub(crate) static PUBLIC_PARAM_MEM_CACHE: Lazy = }); impl PublicParamMemCache { + /// ## Safety + // This assumes: + // 1. no one is mutating these params, which is reasonable if all accesses are Lurk processes, + // 2. our process only reads this once, otherwise the produced Arc will leak memory. fn get_from_disk_cache_or_update_with< 'a, F: CurveCycleEquipped, @@ -66,7 +70,7 @@ impl PublicParamMemCache { let (pp, rest) = unsafe { decode::>>(&mut bytes).unwrap() }; assert!(rest.is_empty()); - Ok(Arc::new(pp.clone())) // this clone is VERY expensive + Ok(unsafe { Arc::from_raw(pp as *const PublicParams>) }) } Err(Error::IO(e)) => { warn!("{e}");