Skip to content

Commit a75f40c

Browse files
authored
fix: checked_sub when initialising zero account balance (#1662)
1 parent 55b8163 commit a75f40c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

zilliqa/src/state.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,27 @@ impl State {
118118
Some(contract_addr::INTERSHARD_BRIDGE),
119119
)?;
120120

121-
let zero_account_balance = config.consensus.total_native_token_supply.0
122-
- (config
123-
.consensus
124-
.genesis_accounts
125-
.iter()
126-
.fold(0, |acc, item: &(Address, Amount)| acc + item.1 .0))
127-
- (config.consensus.genesis_deposits.iter().fold(
121+
let zero_account_balance = config
122+
.consensus
123+
.total_native_token_supply
124+
.0
125+
.checked_sub(
126+
config
127+
.consensus
128+
.genesis_accounts
129+
.iter()
130+
.fold(0, |acc, item: &(Address, Amount)| acc + item.1 .0),
131+
)
132+
.expect("Genesis accounts sum to more than total native token supply")
133+
.checked_sub(config.consensus.genesis_deposits.iter().fold(
128134
0,
129135
|acc, item: &(crypto::NodePublicKey, libp2p::PeerId, Amount, Address)| {
130136
acc + item.2 .0
131137
},
132-
));
138+
))
139+
.expect(
140+
"Genesis accounts + genesis deposits sum to more than total native token supply",
141+
);
133142
state.mutate_account(Address::ZERO, |a| {
134143
a.balance = zero_account_balance;
135144
Ok(())

0 commit comments

Comments
 (0)