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

`ReseedBarn.init()` will run out of gas due to minting firtilizers on some L2s

Summary

ReseedBarn.init() deploys Fertilizer contract and mints Fertilizer ids to all the current holders during migration:

function init(
Fertilizers[] calldata fertilizerIds,
uint256 activeFertilizer,
uint256 fertilizedIndex,
uint256 unfertilizedIndex,
uint128 bpf
) external {
// deploy fertilizer implmentation.
Fertilizer fertilizer = new Fertilizer();
// deploy fertilizer proxy. Set owner to beanstalk.
@> TransparentUpgradeableProxy fertilizerProxy = new TransparentUpgradeableProxy(
address(fertilizer),
address(this),
abi.encode(IFertilizer.init.selector)
);
@> mintFertilizers(Fertilizer(address(fertilizerProxy)), fertilizerIds);
...
}

All tokens must be minted in one transaction because it deploys Fertilizer contract.

I researched and found that at the moment of report writing there are 1101 unique entries owner-tokenId. Gist with performed script

Here is analysis with gas consumption of function mintFertilizers(). It minted each of 100 FertilizerIds to 10 different owners, result is 33M gas.
https://gist.github.com/T1MOH593/024dda0357660dc366d62f25ee0caced

33M gas cannot be operated in some L2s, for example Optimism stack has 30M gasLimit in block, Polygon has 30M gasLimit too.

Impact

Migration won't succeed on some L2s because all fertilizer ids cannot be minted in single transaction.

Tools Used

Manual Review

Recommendations

Refactor ReseedBarn to mint fertilizer ids in batches.

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.