Merge pull request #6434 from softminus/better-errors
Give better error messages if proof parameters aren't loaded
This commit is contained in:
commit
5829feed10
|
@ -157,7 +157,8 @@ pub extern "C" fn orchard_unauthorized_bundle_prove_and_sign(
|
|||
let bundle = unsafe { Box::from_raw(bundle) };
|
||||
let keys = unsafe { slice::from_raw_parts(keys, keys_len) };
|
||||
let sighash = unsafe { sighash.as_ref() }.expect("sighash pointer may not be null.");
|
||||
let pk = unsafe { ORCHARD_PK.as_ref() }.unwrap();
|
||||
let pk = unsafe { ORCHARD_PK.as_ref() }
|
||||
.expect("Parameters not loaded: ORCHARD_PK should have been initialized");
|
||||
|
||||
let signing_keys = keys
|
||||
.iter()
|
||||
|
|
|
@ -235,8 +235,8 @@ pub extern "C" fn orchard_batch_add_bundle(
|
|||
pub extern "C" fn orchard_batch_validate(batch: *mut BatchValidator) -> bool {
|
||||
if !batch.is_null() {
|
||||
let batch = unsafe { Box::from_raw(batch) };
|
||||
let vk =
|
||||
unsafe { crate::ORCHARD_VK.as_ref() }.expect("ORCHARD_VK should have been initialized");
|
||||
let vk = unsafe { crate::ORCHARD_VK.as_ref() }
|
||||
.expect("Parameters not loaded: ORCHARD_VK should have been initialized");
|
||||
if batch.validator.validate(vk, OsRng) {
|
||||
// `BatchValidator::validate()` is only called if every
|
||||
// `BatchValidator::check_bundle()` returned `true`, so at this point
|
||||
|
|
|
@ -554,12 +554,11 @@ pub extern "C" fn librustzcash_sprout_prove(
|
|||
vpub_new: u64,
|
||||
) {
|
||||
// Load parameters from disk
|
||||
let sprout_fs = File::open(
|
||||
unsafe { &SPROUT_GROTH16_PARAMS_PATH }
|
||||
.as_ref()
|
||||
.expect("parameters should have been initialized"),
|
||||
)
|
||||
.expect("couldn't load Sprout groth16 parameters file");
|
||||
let sprout_fs =
|
||||
File::open(unsafe { &SPROUT_GROTH16_PARAMS_PATH }.as_ref().expect(
|
||||
"Parameters not loaded: SPROUT_GROTH16_PARAMS_PATH should have been initialized",
|
||||
))
|
||||
.expect("couldn't load Sprout groth16 parameters file");
|
||||
|
||||
let mut sprout_fs = BufReader::with_capacity(1024 * 1024, sprout_fs);
|
||||
|
||||
|
@ -625,7 +624,8 @@ pub extern "C" fn librustzcash_sprout_verify(
|
|||
unsafe { &*cm2 },
|
||||
vpub_old,
|
||||
vpub_new,
|
||||
unsafe { SPROUT_GROTH16_VK.as_ref() }.expect("parameters should have been initialized"),
|
||||
unsafe { SPROUT_GROTH16_VK.as_ref() }
|
||||
.expect("Parameters not loaded: SPROUT_GROTH16_VK should have been initialized"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -335,8 +335,12 @@ impl Prover {
|
|||
value,
|
||||
anchor,
|
||||
merkle_path,
|
||||
unsafe { SAPLING_SPEND_PARAMS.as_ref() }.unwrap(),
|
||||
&prepare_verifying_key(unsafe { SAPLING_SPEND_VK.as_ref() }.unwrap()),
|
||||
unsafe { SAPLING_SPEND_PARAMS.as_ref() }.expect(
|
||||
"Parameters not loaded: SAPLING_SPEND_PARAMS should have been initialized",
|
||||
),
|
||||
&prepare_verifying_key(unsafe { SAPLING_SPEND_VK.as_ref() }.expect(
|
||||
"Parameters not loaded: SAPLING_SPEND_VK should have been initialized",
|
||||
)),
|
||||
)
|
||||
.expect("proving should not fail");
|
||||
|
||||
|
@ -387,7 +391,9 @@ impl Prover {
|
|||
payment_address,
|
||||
rcm,
|
||||
value,
|
||||
unsafe { SAPLING_OUTPUT_PARAMS.as_ref() }.unwrap(),
|
||||
unsafe { SAPLING_OUTPUT_PARAMS.as_ref() }.expect(
|
||||
"Parameters not loaded: SAPLING_OUTPUT_PARAMS should have been initialized",
|
||||
),
|
||||
);
|
||||
|
||||
// Write the proof out to the caller
|
||||
|
@ -485,7 +491,10 @@ impl Verifier {
|
|||
sighash_value,
|
||||
spend_auth_sig,
|
||||
zkproof,
|
||||
&prepare_verifying_key(unsafe { SAPLING_SPEND_VK.as_ref() }.unwrap()),
|
||||
&prepare_verifying_key(
|
||||
unsafe { SAPLING_SPEND_VK.as_ref() }
|
||||
.expect("Parameters not loaded: SAPLING_SPEND_VK should have been initialized"),
|
||||
),
|
||||
)
|
||||
}
|
||||
fn check_output(
|
||||
|
@ -525,7 +534,11 @@ impl Verifier {
|
|||
cm,
|
||||
epk,
|
||||
zkproof,
|
||||
&prepare_verifying_key(unsafe { SAPLING_OUTPUT_VK.as_ref() }.unwrap()),
|
||||
&prepare_verifying_key(
|
||||
unsafe { SAPLING_OUTPUT_VK.as_ref() }.expect(
|
||||
"Parameters not loaded: SAPLING_OUTPUT_VK should have been initialized",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
fn final_check(
|
||||
|
@ -625,8 +638,11 @@ impl BatchValidator {
|
|||
fn validate(&mut self) -> bool {
|
||||
if let Some(inner) = self.0.take() {
|
||||
if inner.validator.validate(
|
||||
unsafe { SAPLING_SPEND_VK.as_ref() }.unwrap(),
|
||||
unsafe { SAPLING_OUTPUT_VK.as_ref() }.unwrap(),
|
||||
unsafe { SAPLING_SPEND_VK.as_ref() }
|
||||
.expect("Parameters not loaded: SAPLING_SPEND_VK should have been initialized"),
|
||||
unsafe { SAPLING_OUTPUT_VK.as_ref() }.expect(
|
||||
"Parameters not loaded: SAPLING_OUTPUT_VK should have been initialized",
|
||||
),
|
||||
OsRng,
|
||||
) {
|
||||
// `Self::validate()` is only called if every `Self::check_bundle()`
|
||||
|
|
Loading…
Reference in New Issue