test: Load the proof verification keys in Boost tests
The change to use Orchard batch validation now requires the Orchard verifying key to be available even if there are no items in the batch. For simplicity, we now load all verifying keys in the Boost tests.
This commit is contained in:
parent
d46e18f955
commit
eb9dd95f69
|
@ -39,7 +39,8 @@ main(int argc, char** argv)
|
|||
reinterpret_cast<const codeunit*>(sapling_output_str.c_str()),
|
||||
sapling_output_str.length(),
|
||||
reinterpret_cast<const codeunit*>(sprout_groth16_str.c_str()),
|
||||
sprout_groth16_str.length()
|
||||
sprout_groth16_str.length(),
|
||||
true
|
||||
);
|
||||
|
||||
benchmark::BenchRunner::RunAll();
|
||||
|
|
|
@ -30,7 +30,8 @@ void LoadProofParameters() {
|
|||
reinterpret_cast<const codeunit*>(sapling_output_str.c_str()),
|
||||
sapling_output_str.length(),
|
||||
reinterpret_cast<const codeunit*>(sprout_groth16_str.c_str()),
|
||||
sprout_groth16_str.length()
|
||||
sprout_groth16_str.length(),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -881,7 +881,8 @@ static void ZC_LoadParams(
|
|||
reinterpret_cast<const codeunit*>(sapling_output_str.c_str()),
|
||||
sapling_output_str.length(),
|
||||
reinterpret_cast<const codeunit*>(sprout_groth16_str.c_str()),
|
||||
sprout_groth16_str.length()
|
||||
sprout_groth16_str.length(),
|
||||
true
|
||||
);
|
||||
|
||||
gettimeofday(&tv_end, 0);
|
||||
|
|
|
@ -35,7 +35,8 @@ extern "C" {
|
|||
const codeunit* output_path,
|
||||
size_t output_path_len,
|
||||
const codeunit* sprout_path,
|
||||
size_t sprout_path_len
|
||||
size_t sprout_path_len,
|
||||
bool load_proving_keys
|
||||
);
|
||||
|
||||
/// Writes the "uncommitted" note value for empty leaves
|
||||
|
|
|
@ -122,6 +122,11 @@ fn fixed_scalar_mult(from: &[u8; 32], p_g: &jubjub::SubgroupPoint) -> jubjub::Su
|
|||
|
||||
/// Loads the zk-SNARK parameters into memory and saves paths as necessary.
|
||||
/// Only called once.
|
||||
///
|
||||
/// If `load_proving_keys` is `false`, the proving keys will not be loaded, making it
|
||||
/// impossible to create proofs. This flag is for the Boost test suite, which never
|
||||
/// creates shielded transactions, but exercises code that requires the verifying keys to
|
||||
/// be present even if there are no shielded components to verify.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn librustzcash_init_zksnark_params(
|
||||
#[cfg(not(target_os = "windows"))] spend_path: *const u8,
|
||||
|
@ -133,6 +138,7 @@ pub extern "C" fn librustzcash_init_zksnark_params(
|
|||
#[cfg(not(target_os = "windows"))] sprout_path: *const u8,
|
||||
#[cfg(target_os = "windows")] sprout_path: *const u16,
|
||||
sprout_path_len: usize,
|
||||
load_proving_keys: bool,
|
||||
) {
|
||||
PROOF_PARAMETERS_LOADED.call_once(|| {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -173,24 +179,26 @@ pub extern "C" fn librustzcash_init_zksnark_params(
|
|||
|
||||
// Load params
|
||||
let params = load_parameters(spend_path, output_path, sprout_path);
|
||||
let sapling_spend_params = params.spend_params;
|
||||
let sapling_output_params = params.output_params;
|
||||
|
||||
// Generate Orchard parameters.
|
||||
info!(target: "main", "Loading Orchard parameters");
|
||||
let orchard_pk = orchard::circuit::ProvingKey::build();
|
||||
let orchard_pk = load_proving_keys.then(orchard::circuit::ProvingKey::build);
|
||||
let orchard_vk = orchard::circuit::VerifyingKey::build();
|
||||
|
||||
// Caller is responsible for calling this function once, so
|
||||
// these global mutations are safe.
|
||||
unsafe {
|
||||
SAPLING_SPEND_PARAMS = Some(params.spend_params);
|
||||
SAPLING_OUTPUT_PARAMS = Some(params.output_params);
|
||||
SAPLING_SPEND_PARAMS = load_proving_keys.then(|| sapling_spend_params);
|
||||
SAPLING_OUTPUT_PARAMS = load_proving_keys.then(|| sapling_output_params);
|
||||
SPROUT_GROTH16_PARAMS_PATH = sprout_path.map(|p| p.to_owned());
|
||||
|
||||
SAPLING_SPEND_VK = Some(params.spend_vk);
|
||||
SAPLING_OUTPUT_VK = Some(params.output_vk);
|
||||
SPROUT_GROTH16_VK = params.sprout_vk;
|
||||
|
||||
ORCHARD_PK = Some(orchard_pk);
|
||||
ORCHARD_PK = orchard_pk;
|
||||
ORCHARD_VK = Some(orchard_vk);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -74,6 +74,28 @@ BasicTestingSetup::~BasicTestingSetup()
|
|||
|
||||
TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(chainName)
|
||||
{
|
||||
fs::path sapling_spend = ZC_GetParamsDir() / "sapling-spend.params";
|
||||
fs::path sapling_output = ZC_GetParamsDir() / "sapling-output.params";
|
||||
fs::path sprout_groth16 = ZC_GetParamsDir() / "sprout-groth16.params";
|
||||
|
||||
static_assert(
|
||||
sizeof(fs::path::value_type) == sizeof(codeunit),
|
||||
"librustzcash not configured correctly");
|
||||
auto sapling_spend_str = sapling_spend.native();
|
||||
auto sapling_output_str = sapling_output.native();
|
||||
auto sprout_groth16_str = sprout_groth16.native();
|
||||
|
||||
librustzcash_init_zksnark_params(
|
||||
reinterpret_cast<const codeunit*>(sapling_spend_str.c_str()),
|
||||
sapling_spend_str.length(),
|
||||
reinterpret_cast<const codeunit*>(sapling_output_str.c_str()),
|
||||
sapling_output_str.length(),
|
||||
reinterpret_cast<const codeunit*>(sprout_groth16_str.c_str()),
|
||||
sprout_groth16_str.length(),
|
||||
// Only load the verifying keys, which some tests need.
|
||||
false
|
||||
);
|
||||
|
||||
const CChainParams& chainparams = Params();
|
||||
// Ideally we'd move all the RPC tests to the functional testing framework
|
||||
// instead of unit tests, but for now we need these here.
|
||||
|
|
Loading…
Reference in New Issue