The _withdraw function performs multiple share-based calculations that can lead to precision loss and value extraction opportunities, particularly in scenarios with large numbers of shares or small deposit amounts.
The function uses integer division for share calculations without properly accounting for rounding errors or precision loss. This occurs in multiple critical calculations involving shares, collateral amounts, and position sizes.
The vulnerability manifests in three key areas within the function:
Initial token balance calculation:
Collateral amount calculation:
Size calculation:
Each of these calculations follows the pattern of (amount * shares) / totalShares, which can lead to significant rounding errors, especially when:
The total number of shares is large
The withdrawal amount is small relative to total shares
Multiple withdrawals are performed sequentially
Users may receive less value than they should due to rounding down
Last depositor might be unable to withdraw their full amount
Malicious users could perform multiple small withdrawals to extract extra value
Accumulation of dust amounts over time could lead to locked funds
PoC:
Slither
Manual Review
Mathematical Analysis
Implement a decimal-based share calculation system:
Add minimum withdrawal amount checks to prevent dust attacks
Implement rounding protection mechanisms
Add share price calculations that account for decimals
Consider implementing a withdrawal fee to discourage exploitation
Add invariant checks to ensure withdrawal amounts are reasonable
Document precise mathematical formulas for all share calculations
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.