From 45521c78496f2a1ce2ed99c515496615dcc51bf8 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 11 Aug 2021 00:18:39 +0100 Subject: [PATCH] zcash_primitives: Test that batched trial decryption matches unbatched --- zcash_primitives/src/sapling/note_encryption.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/zcash_primitives/src/sapling/note_encryption.rs b/zcash_primitives/src/sapling/note_encryption.rs index 5ecef7bff..a1c66a534 100644 --- a/zcash_primitives/src/sapling/note_encryption.rs +++ b/zcash_primitives/src/sapling/note_encryption.rs @@ -1446,11 +1446,23 @@ mod tests { }) .collect(); - let res = batch::try_note_decryption(&[invalid_ivk, valid_ivk], &outputs); + let res = batch::try_note_decryption(&[invalid_ivk.clone(), valid_ivk.clone()], &outputs); assert_eq!(res.len(), 20); + // The batched trial decryptions with invalid_ivk failed. assert_eq!(&res[..10], &vec![None; 10][..]); - for result in &res[10..] { + for (result, (_, output)) in res[10..].iter().zip(outputs.iter()) { + // Confirm that the outputs should indeed have failed with invalid_ivk + assert_eq!( + try_sapling_note_decryption(&TEST_NETWORK, height, &invalid_ivk, output), + None + ); + + // Confirm the successful batched trial decryptions gave the same result. assert!(result.is_some()); + assert_eq!( + result, + &try_sapling_note_decryption(&TEST_NETWORK, height, &valid_ivk, output) + ); } } }