Skip to content

Commit

Permalink
Merge pull request #2364 from AleoHQ/supply-check
Browse files Browse the repository at this point in the history
[nit] Use `checked_add` for account supply calculation
  • Loading branch information
howardwu authored Feb 20, 2024
2 parents 0f9e500 + 0f796fd commit f262864
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion synthesizer/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ impl<N: Network, C: ConsensusStorage<N>> VM<N, C> {
// 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.
Expand Down

0 comments on commit f262864

Please sign in to comment.