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

Infinite Loop in `init` Function

Summary

The ReseedField has an error in its init function in the sense that the inner loop of a nested loop structure incorrectly increments the outer loop's iterator, leading to an infinite loop and incomplete processing of account plots.

Vulnerability Details

In the init function of the ReseedField contract, there is a nested loop structure intended to iterate over all plots for all accounts. Albeit, the inner loop incorrectly increments the outer loop's iterator i instead of its own iterator j:

https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/4e0ad0b964f74a1b4880114f4dd5b339bc69cd3e/protocol/contracts/beanstalk/init/reseed/L2/ReseedField.sol#L49

for (uint i; i < accountPlots.length; i++) {
for (uint j; j < accountPlots[i].plots.length; i++) {
// ... (loop body)
}
}

This will cause the inner loop to never terminate properly, and the outer loop to skip most of the accountPlots entries. As a result, only the plots from the first account will be processed before the function likely runs out of gas due to the infinite inner loop.

Impact

Firstly, Only the first account's plots will be processed, leaving all other accounts' data uninitialized. Also, the calculatedTotalPods will not reflect the true sum of all pod amounts across all accounts. init function will likely run out of gas due to the infinite loop, causing the entire initialization process to fail.

Likelihood is high and Impact is high, hence the reason this was marked as HIGH.

Tools Used

Manual code review

Recommendations

Modify the inner loop to increment the correct iterator:

for (uint i; i < accountPlots.length; i++) {
- for (uint j; j < accountPlots[i].plots.length; i++) {
+ for (uint j; j < accountPlots[i].plots.length; j++) {
// ... (loop body)
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Very broken loop in ReseedField::init

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Very broken loop in ReseedField::init

Support

FAQs

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