From 53d1280e408c720ddf52e48c5b375c11701469b1 Mon Sep 17 00:00:00 2001 From: Chris Czub Date: Thu, 8 Feb 2024 16:09:41 -0500 Subject: [PATCH] Use checked math for ICS20 withdrawal addition --- .../core/component/shielded-pool/src/component/transfer.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/core/component/shielded-pool/src/component/transfer.rs b/crates/core/component/shielded-pool/src/component/transfer.rs index 504b873236..74972efc14 100644 --- a/crates/core/component/shielded-pool/src/component/transfer.rs +++ b/crates/core/component/shielded-pool/src/component/transfer.rs @@ -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,