Skip to content

Commit

Permalink
Protect bundle burn from adding assets with zero amount (#60)
Browse files Browse the repository at this point in the history
Prevent the burning of assets with zero value.
  • Loading branch information
dmidem authored and Dmitry Demin committed Jun 26, 2023
1 parent 743f749 commit 020e185
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ impl Builder {
if asset.is_native().into() {
return Err("Burning is only possible for non-native assets");
}

if value.inner() == 0 {
return Err("Burning is not possible for zero values");
}

let cur = *self.burn.get(&asset).unwrap_or(&ValueSum::zero());
let sum = (cur + value).ok_or("Orchard ValueSum operation overflowed")?;
self.burn.insert(asset, sum);
Expand Down
17 changes: 17 additions & 0 deletions tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,21 @@ fn zsa_issue_and_transfer() {
Ok(_) => panic!("Test should fail"),
Err(error) => assert_eq!(error, "Burning is only possible for non-native assets"),
}

// 12. Try to burn zero value - should fail
let result = build_and_verify_bundle(
vec![&zsa_spend_1],
vec![TestOutputInfo {
value: zsa_spend_1.note.value(),
asset: zsa_spend_1.note.asset(),
}],
vec![(zsa_spend_1.note.asset(), NoteValue::from_raw(0))],
anchor,
2,
&keys,
);
match result {
Ok(_) => panic!("Test should fail"),
Err(error) => assert_eq!(error, "Burning is not possible for zero values"),
}
}

0 comments on commit 020e185

Please sign in to comment.