Beanstalk 3 introduces multiple Fields - previously there was just 1 Field. Also it introduces new way to distribute newly minted Beans via ShipmentPlanner.
Issue arises on the edge of these 2 new mechanics. In summary problem is:
ShipmentRoutes are stored in storage. ShipmentRoute for Field contains fieldId as data
. I.e. fieldId to add new Beans is strictly stored.
Sun.stepSun()
uses difference between harvestable
indexes before distribution and after distribution to calculate amount of Beans minted to Field. Note that it uses active fieldId to calculate it.
And here's a problem: active fieldId can differ from fieldId configured in ShipmentRoute. I assume development team is not aware of discrepancy which will arise from updating activeFieldId.
This issue doesn't require admin mistake because admin is not aware of the discrepancy in codebase which requires to update ShipmentRoutes AND activeFieldId in the same time to not cause issues.
Here you can see that it "ships" newly minted Beans and then uses difference in active field to calculate Soil:
https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/df2dd129a878d16d4adc75049179ac0029d9a96b/protocol/contracts/beanstalk/sun/SeasonFacet/Sun.sol#L41-L57
And here you see that ShipmentRoute stores the fieldId to submit Beans:
There is obviously a discrepancy between ShipmentRoute and Sun: it must use same fieldId in both contracts. But Shipment logic uses stored fieldId and Sun uses active fieldId.
In case fieldIds differ between ShipmentRoute and activeFieldId i.e. in case of update of either ShipmentRoute or activeFieldId, it will set 0 Soil in next seasons.
0 Soil means users can't buy Pods by burning Bean to maintain Bean peg. In other words Field module completely doesn't work, i.e. core peg mechanism of Bean doesn't work after such update.
Manual Review
I propose to not store fieldId in ShipmentRoute, but use activeFieldId instead.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.