From 0f796fd387f854638e8f5eb9bca07fb434a62c2c Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:43:48 -0800 Subject: [PATCH] Use checked_add for account supply calculation --- synthesizer/src/vm/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index 50eca744f9..8db16cb60a 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -275,7 +275,9 @@ impl> VM { // Retrieve the total stake. let total_stake = committee.total_stake(); // Compute the account supply. - let account_supply = public_balances.values().fold(0u64, |acc, x| acc.saturating_add(*x)); + let account_supply = public_balances + .values() + .try_fold(0u64, |acc, x| acc.checked_add(*x).ok_or(anyhow!("Invalid account supply")))?; // Compute the total supply. let total_supply = total_stake.checked_add(account_supply).ok_or_else(|| anyhow!("Invalid total supply"))?; // Ensure the total supply matches.