During shipping if the amount to be shipped is larger than sum of the cap of all the routes, then some beans will not be shipped and will be remained in the protocol unreachable.
When the function ship
is called, the amount of beansToShip
would be distributed across all active shipping routes.
https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/df2dd129a878d16d4adc75049179ac0029d9a96b/protocol/contracts/libraries/LibShipping.sol#L28C14-L28C18
The issue is that if the amount to be shipped is larger than sum of the cap of all the routes, the remaining beans will not be shipped, and they will be locked in the protocol.
For simplicity assumes that we have only the following two shipment plans.
shipmentPlans[0] = ShipmentPlan{points: 10, cap: 500}
shipmentPlans[1] = ShipmentPlan{points: 10, cap: 400}
If beansToShip
is equal to 1000, in the first iteration of the outer for-loop, we will have:
shipmentAmounts[1]
= 400
remainingBeansToShip
= 1000 - 400 = 600
totalPoints
= 20 - 10 = 10
shipmentPlans[1].points
= 0
In the second interaion of the outer for-loop, we will have:
shipmentAmounts[2]
= 500
remainingBeansToShip
= 600 - 500 = 100
totalPoints
= 10 - 10 = 0
shipmentPlans[2].points
= 0
Then the last for-loop will be executed where the shipmentAmounts
will be shipped to the routes. It shows that 500 and 400 will be shipped to the first and the second shipment routes, respectively. While, the total beans to be shipped was 1000. So, 100 beans are not shipped and locked in the protocol.
In the following simplified version of the code, the emitted event LogPoc
is 100
which shows the amount of beans that are remained and not shipped.
To run the PoC, first the function setShipmentRoutes
, should be called, and then ship(1000)
.
Output is:
Lock of to-be-shipped beans in case of being higher than the total cap of the routes.
It is recomended that when such case happens, the remained beans be transferred to an authorized contract to not be out of the circulation.
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.