DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: low
Valid

`ReseedInternalBalances.init()` can run out of gas

Summary

ReseedInternalBalances.init() requires to pass all migrate-able balances at once because in the end it sets totalBalance:

function setInternalBalances(BeanstalkInternalBalance calldata internalBalances) internal {
...
@> s.sys.internalTokenBalanceTotal[IERC20(internalBalances.token)] = totalInternalBalance;
}

Roughly speaking setting internal balance costs 20k gas because of SLOAD on every iteration:

function setInternalBalances(BeanstalkInternalBalance calldata internalBalances) internal {
uint256 totalInternalBalance;
for (uint i; i < internalBalances.farmers.length; i++) {
s.accts[internalBalances.farmers[i]].internalTokenBalance[
IERC20(internalBalances.token)
@> ] = internalBalances.balances[i];
...
}
...
}

There are L2s with block gasLimit 30M such as Optimism, Blast, Polygon. So migration won't succeed on these chains in case total number of balances prior to migration increases threshold 30M / 20k = 1500 balances.

Impact

Migration can run out of gas on certain L2s with block gasLimit 30M gas in case there will be more than 1500 internal balances prior to migration.

Tools Used

Manual Review

Recommendations

Refactor ReseedInternalBalances to allow divide migration into multiple transactions.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

init functions will run out of gas on some L2s

Appeal created

T1MOH Submitter
12 months ago
inallhonesty Lead Judge
12 months ago
inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

init functions will run out of gas on some L2s

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.