Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Oct 15, 2024
1 parent 5871966 commit b9e9112
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl<V: Copy + Into<i64> + std::iter::Sum> SwapBundle<V> {
.map(|a| ValueCommitTrapdoor::from_bsk(a.authorization().bsk))
.sum::<ValueCommitTrapdoor>()
.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,
))
Expand Down
23 changes: 7 additions & 16 deletions tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ pub fn verify_bundle<FL: OrchardFlavor>(
);
}

// 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<i64>, 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()),
Expand All @@ -60,15 +54,12 @@ pub fn verify_swap_bundle(swap_bundle: &SwapBundle<i64>, 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<FL: OrchardFlavor>(
bundle: &Bundle<ActionGroupAuthorized, i64, FL>,
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(()));
Expand Down
19 changes: 13 additions & 6 deletions tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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![
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit b9e9112

Please sign in to comment.