Skip to content

Commit

Permalink
Use checked math for ICS20 withdrawal addition
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Feb 8, 2024
1 parent 29b9323 commit 53d1280
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ pub trait Ics20TransferWriteExt: StateWrite {
.expect("able to retrieve value balance in ics20 withdrawal! (execute)")
.unwrap_or_else(Amount::zero);

let new_value_balance = existing_value_balance + withdrawal.amount;
let new_value_balance = existing_value_balance
.checked_add(&withdrawal.amount)
.ok_or_else(|| {
anyhow::anyhow!("overflow adding value balance in ics20 withdrawal")
})?;
self.put(
state_key::ics20_value_balance(&withdrawal.source_channel, &withdrawal.denom.id()),
new_value_balance,
Expand Down

0 comments on commit 53d1280

Please sign in to comment.