No Withdraw for Small Shares:
When a user’s share is extremely small relative to the total pool, the contract calculates the withdrawable amount using a multiplication followed by a division operation. Due to integer division in Solidity, this operation may round down to zero even if the user holds a nonzero deposit. As a result, users with very small shares might not be able to withdraw any funds.
Subtraction Underflow:
In scenarios where collateralDeltaAmount is zero and feeAmount (or an additional subtraction adjustment from a negative PnL) is greater than zero, the contract will attempt to compute 0 - feeAmount. Since Solidity 0.8.4 includes built‑in overflow/underflow checks, this subtraction will trigger an underflow, automatically reverting the transaction.
Rounding Issue:
The proportional share calculation suffers from the inherent limitations of integer arithmetic in Solidity. Small values multiplied and then divided by a large total may round down to zero, leading to an incorrect zero-share calculation.
Unchecked Subtraction:
The contract does not validate that collateralDeltaAmount is sufficient before subtracting feeAmount (or any negative PnL adjustment), which can lead to an underflow when the fee exceeds the available collateral.
User Funds Inaccessibility:
Users with very small deposits relative to the overall pool might find that their computed withdrawable amount is zero, effectively locking their funds in the contract.
Transaction Reversion:
The subtraction underflow will cause the transaction to revert. This may prevent legitimate withdrawals or other operations from being successfully executed, resulting in a poor user experience and potential loss of confidence in the protocol.
Mitigate Rounding Errors:
Implement a minimum threshold for shares or deposits, below which the contract either rounds up or aggregates with a dust pool to ensure that small deposits can be withdrawn.
Consider using higher precision arithmetic or libraries designed to handle fractional values if necessary.
Guard Against Underflow:
Before performing the subtraction, explicitly check that collateralDeltaAmount is greater than or equal to feeAmount (including any adjustments from negative PnL).
Alternatively, use safe math libraries that provide clearer error messages and allow for graceful handling of underflow scenarios.
User Notification:
Provide clear error messages or warnings to users when their deposit amounts are too small, so they understand the limitations and potential issues with very small transactions.
Below is a simplified pseudocode snippet demonstrating how the issue might occur and a suggested mitigation:
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.
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.