diff --git a/crates/core/src/token.rs b/crates/core/src/token.rs index 1a13df9a3f..10fd8cab19 100644 --- a/crates/core/src/token.rs +++ b/crates/core/src/token.rs @@ -1015,15 +1015,6 @@ pub mod testing { } } - impl std::ops::Mul for Amount { - type Output = Amount; - - fn mul(mut self, rhs: Uint) -> Self::Output { - self.raw *= rhs; - self - } - } - impl std::ops::Div for Amount { type Output = Self; diff --git a/crates/core/src/uint.rs b/crates/core/src/uint.rs index 68593e46f7..b22970d68c 100644 --- a/crates/core/src/uint.rs +++ b/crates/core/src/uint.rs @@ -511,7 +511,13 @@ impl FromStr for I256 { fn from_str(num: &str) -> Result { if let Some(("", neg_num)) = num.split_once('-') { - let uint = neg_num.parse::()?.negate(); + let (uint, overflow) = neg_num.parse::()?.negate(); + if overflow { + return Err(Box::new(std::io::Error::new( + std::io::ErrorKind::InvalidData, + "I256 overflow", + ))); + } Ok(I256(uint)) } else { let uint = num.parse::()?; @@ -522,8 +528,9 @@ impl FromStr for I256 { impl I256 { /// Compute the two's complement of a number. - pub fn negate(&self) -> Self { - Self(self.0.negate()) + pub fn negate(&self) -> Option { + let (uint, overflow) = self.0.negate(); + if overflow { None } else { Some(Self(uint)) } } /// Check if the amount is not negative (greater @@ -1133,7 +1140,7 @@ mod test_uint { #[test] fn test_i256_str_roundtrip() { - let minus_one = I256::one().negate(); + let minus_one = I256::one().negate().unwrap(); let minus_one_str = minus_one.to_string(); assert_eq!(minus_one_str, "-1"); diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 97ad0cc7e5..7a2d8fccb3 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -518,7 +518,7 @@ where .map_err(|e| Error::FeeError(e.to_string()))?; let current_block_height = - state.in_mem().get_last_block_height() + 1; + state.in_mem().get_last_block_height().next_height(); if let Some(post_bal) = balance.checked_sub(fees) { token_transfer( diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index ccc220c85c..f7d3f19d24 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -51,7 +51,6 @@ use masp_proofs::prover::LocalTxProver; #[cfg(not(feature = "testing"))] use masp_proofs::sapling::SaplingVerificationContext; use namada_core::address::Address; -use namada_core::arith::checked; use namada_core::collections::{HashMap, HashSet}; use namada_core::dec::Dec; pub use namada_core::masp::{