diff --git a/src/bundle.rs b/src/bundle.rs index a8c924716..95113978b 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -527,7 +527,7 @@ impl + std::iter::Sum> SwapBundle { .map(|a| ValueCommitTrapdoor::from_bsk(a.authorization().bsk)) .sum::() .into_bsk(); - let sighash = BundleCommitment(hash_action_groups_txid_data( + let sighash: [u8; 32] = BundleCommitment(hash_action_groups_txid_data( action_groups.iter().collect(), value_balance, )) diff --git a/tests/builder.rs b/tests/builder.rs index 08d40a5c1..0792414f2 100644 --- a/tests/builder.rs +++ b/tests/builder.rs @@ -34,22 +34,16 @@ pub fn verify_bundle( ); } +// Verify a swap bundle +// - verify each action group (its proof and for each action, the spend authorization signature) +// - verify the binding signature pub fn verify_swap_bundle(swap_bundle: &SwapBundle, vks: Vec<&VerifyingKey>) { assert_eq!(vks.len(), swap_bundle.action_groups().len()); for (action_group, vk) in swap_bundle.action_groups().iter().zip(vks.iter()) { - assert!(matches!(action_group.verify_proof(vk), Ok(()))); - let action_group_sighash: [u8; 32] = action_group.commitment().into(); - for action in action_group.actions() { - assert_eq!( - action - .rk() - .verify(&action_group_sighash, action.authorization()), - Ok(()) - ); - } + verify_action_group(action_group, vk); } - let sighash = swap_bundle.commitment().into(); + let sighash: [u8; 32] = swap_bundle.commitment().into(); let bvk = swap_bundle.binding_validating_key(); assert_eq!( bvk.verify(&sighash, swap_bundle.binding_signature()), @@ -60,15 +54,12 @@ pub fn verify_swap_bundle(swap_bundle: &SwapBundle, vks: Vec<&VerifyingKey> // Verify an action group // - verify the proof // - verify the signature on each action -// - do not verify the binding signature because for some asset, the value balance could be not zero pub fn verify_action_group( bundle: &Bundle, vk: &VerifyingKey, - verify_proof: bool, ) { - if verify_proof { - assert!(matches!(bundle.verify_proof(vk), Ok(()))); - } + assert!(matches!(bundle.verify_proof(vk), Ok(()))); + let sighash: [u8; 32] = bundle.commitment().into(); for action in bundle.actions() { assert_eq!(action.rk().verify(&sighash, action.authorization()), Ok(())); diff --git a/tests/zsa.rs b/tests/zsa.rs index 781c22a6b..ab8a02319 100644 --- a/tests/zsa.rs +++ b/tests/zsa.rs @@ -350,7 +350,7 @@ fn build_and_verify_action_group( build_and_sign_action_group(builder, rng, keys.pk(), keys.sk()) }; - verify_action_group(&shielded_bundle, &keys.vk, true); + verify_action_group(&shielded_bundle, &keys.vk); assert_eq!(shielded_bundle.actions().len(), expected_num_actions); // TODO // assert!(verify_unique_spent_nullifiers(&shielded_bundle)); @@ -729,8 +729,15 @@ fn swap_order_and_swap_bundle() { merkle_path: merkle_path_user2_native_note2, }; - // --------------------------- Tests ----------------------------------------- + // --------------------------- Swap description-------------------------------- + // User1: + // - spends 10 asset1 + // - receives 20 asset2 + // User2: + // - spends 20 asset2 + // - receives 10 asset1 + // --------------------------- Tests ----------------------------------------- // 1. Create and verify ActionGroup for user1 let action_group1 = build_and_verify_action_group( vec![ @@ -741,11 +748,11 @@ fn swap_order_and_swap_bundle() { ], vec![ TestOutputInfo { - value: NoteValue::from_raw(10), + value: NoteValue::from_raw(32), asset: asset1_note1.asset(), }, TestOutputInfo { - value: NoteValue::from_raw(5), + value: NoteValue::from_raw(20), asset: asset2_note1.asset(), }, TestOutputInfo { @@ -771,11 +778,11 @@ fn swap_order_and_swap_bundle() { ], vec![ TestOutputInfo { - value: NoteValue::from_raw(10), + value: NoteValue::from_raw(22), asset: asset2_note1.asset(), }, TestOutputInfo { - value: NoteValue::from_raw(5), + value: NoteValue::from_raw(10), asset: asset1_note1.asset(), }, TestOutputInfo {