make librustzcash_init_zksnark_params idempotent

This commit is contained in:
sasha 2022-03-03 22:21:20 -08:00
parent 13351ff31d
commit 0e6b004a64
1 changed files with 55 additions and 51 deletions

View File

@ -29,6 +29,7 @@ use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::slice; use std::slice;
use std::sync::Once;
use subtle::CtOption; use subtle::CtOption;
use tracing::{error, info}; use tracing::{error, info};
@ -84,6 +85,7 @@ mod test_harness_ffi;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
static PROOF_PARAMETERS_LOADED: Once = Once::new();
static mut SAPLING_SPEND_VK: Option<PreparedVerifyingKey<Bls12>> = None; static mut SAPLING_SPEND_VK: Option<PreparedVerifyingKey<Bls12>> = None;
static mut SAPLING_OUTPUT_VK: Option<PreparedVerifyingKey<Bls12>> = None; static mut SAPLING_OUTPUT_VK: Option<PreparedVerifyingKey<Bls12>> = None;
static mut SPROUT_GROTH16_VK: Option<PreparedVerifyingKey<Bls12>> = None; static mut SPROUT_GROTH16_VK: Option<PreparedVerifyingKey<Bls12>> = None;
@ -127,6 +129,7 @@ pub extern "C" fn librustzcash_init_zksnark_params(
#[cfg(target_os = "windows")] sprout_path: *const u16, #[cfg(target_os = "windows")] sprout_path: *const u16,
sprout_path_len: usize, sprout_path_len: usize,
) { ) {
PROOF_PARAMETERS_LOADED.call_once(|| {
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
let (spend_path, output_path, sprout_path) = { let (spend_path, output_path, sprout_path) = {
( (
@ -185,6 +188,7 @@ pub extern "C" fn librustzcash_init_zksnark_params(
ORCHARD_PK = Some(orchard_pk); ORCHARD_PK = Some(orchard_pk);
ORCHARD_VK = Some(orchard_vk); ORCHARD_VK = Some(orchard_vk);
} }
});
} }
/// Writes the "uncommitted" note value for empty leaves of the Merkle tree. /// Writes the "uncommitted" note value for empty leaves of the Merkle tree.