Skip to content

Commit 49f5939

Browse files
committed
PR471 Review: Added MAX_BURN_VALUE
Added MAX_BURN_VALUE to be u63 in order to fit both u64 and i64 as requested in zcash#471 (comment)
1 parent fcd1a0b commit 49f5939

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/bundle/burn_validation.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use core::fmt;
77

88
use crate::{note::AssetBase, value::NoteValue};
99

10+
/// Maximum burn value.
11+
/// Burns must fit in both u64 and i64 for value balance calculations.
12+
pub const MAX_BURN_VALUE: u64 = (1u64 << 63) - 1;
13+
1014
/// Possible errors that can occur during bundle burn validation.
1115
#[derive(Debug)]
1216
#[cfg_attr(test, derive(PartialEq, Eq))]
@@ -47,7 +51,7 @@ pub fn validate_bundle_burn(burn: &[(AssetBase, NoteValue)]) -> Result<(), BurnE
4751
if value.inner() == 0 {
4852
return Err(BurnError::ZeroAmount);
4953
}
50-
if value.inner() >= (1u64 << 63) {
54+
if value.inner() > MAX_BURN_VALUE {
5155
return Err(BurnError::InvalidAmount);
5256
}
5357
if !burn_set.insert(*asset) {
@@ -166,7 +170,7 @@ mod tests {
166170

167171
let bundle_burn = vec![
168172
burn_tuple_unique(&mut rng, &mut used, 10),
169-
burn_tuple_unique(&mut rng, &mut used, 1u64 << 63),
173+
burn_tuple_unique(&mut rng, &mut used, MAX_BURN_VALUE + 1),
170174
burn_tuple_unique(&mut rng, &mut used, 10),
171175
];
172176

0 commit comments

Comments
 (0)