mirror of https://github.com/zcash/orchard.git
Protect bundle burn from adding assets with zero amount (#60)
Prevent the burning of assets with zero value.
This commit is contained in:
parent
95fcf88407
commit
8e71fffc51
|
@ -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);
|
||||
|
|
17
tests/zsa.rs
17
tests/zsa.rs
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue