Protect bundle burn from adding assets with zero amount (#60)

Prevent the burning of assets with zero value.
This commit is contained in:
Dmitry Demin 2023-05-29 15:06:53 +03:00 committed by GitHub
parent 95fcf88407
commit 8e71fffc51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -397,6 +397,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);

View File

@ -508,4 +508,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"),
}
}