The ship
function in the LibShipping
library fails to redistribute or report excess Beans when the total number of Beans to ship exceeds the sum of all specified caps in the shipment plans. This can lead to inefficiencies and a potential lack of transparency regarding the handling of surplus tokens.
Location: LibShipping.sol
- ship
function
The function aims to distribute Beans (tokens) across various shipping routes proportional to their points and respecting each route's cap. However, when the total Beans to ship (beansToShip
) exceeds the aggregate caps of all shipment plans, any remaining Beans (remainingBeansToShip
) are not redistributed or reported. This leaves the surplus Beans unallocated after all caps are reached:
Inefficient Token Utilization: Excess Beans are neither utilized nor redirected, potentially resulting in wasted token resources.
Transparency Issues: Without explicit handling or logging, it becomes difficult to track how many Beans were left unallocated, which might pose transparency concerns.
LibShippingTest.t.sol
Ran 1 test for test/foundry/sun/poc2.t.sol:LibShippingTest
[PASS] testShipExcessBeans() (gas: 55215)
Logs:
Remaining Beans Stuck: 1700
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 4.78ms (2.54ms CPU time)
Libraries and Structs:
Definition of LibAppStorage
, LibReceiving
, and LibShipping
libraries and relevant structs.
LibShippingTest Contract:
Uses Foundry's DSTest
and sets up initial storage with three shipment routes having mock plans with caps of 100 Beans each.
Mocks the shipment plan with a standard cap of 100 Beans for each route.
testShipExcessBeans Function:
Tests the condition where the total Beans to ship (2000) exceed the accumulated caps (100 * 3 = 300).
Ensures that the expected surplus Beans are stuck and outputs this for verification.
Manual Code Review
Foundry for testing and validation
Redistribute Excess Beans: Implement logic to redirect surplus Beans to a predefined recipient (e.g., a treasury or a holding account) after the distribution loop completes:
Logging and Transparency: Emit an event to log any excess Beans, providing clear records for transparency and auditing purposes:
State Updates: Maintain an internal state to register unallocated Beans, enhancing the contract's tracking and reporting capabilities:
Implementing these recommendations will help ensure efficient utilization of Beans and improve transparency regarding token distribution.
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.