DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Precision Loss in Share Calculation Leads to Incorrect Withdrawals

Summary

Precision loss in the share calculation logic when withdrawing funds from the vault. Due to Solidity's integer division behavior, users with small shares relative to totalShares will receive fewer funds than expected, leading to an unfair distribution of withdrawals.

Vulnerability Details

2025-02-gamma/contracts/PerpetualVault.sol at main · CodeHawks-Contests/2025-02-gamma

2025-02-gamma/contracts/PerpetualVault.sol at main · CodeHawks-Contests/2025-02-gamma

The issue occurs in the following calculation:

amount = withdrawn + balanceBeforeWithdrawal * shares / totalShares;

Since Solidity performs integer division, if shares is significantly smaller than totalShares, the result of balanceBeforeWithdrawal * shares / totalShares may round down to zero, causing some depositors to lose a portion of their rightful withdrawal amount.

Impact

Users with smaller shares will receive significantly less than their fair share of withdrawals.

In extreme cases, small withdrawals will result in receiving nothing, leading to a loss of funds.

Tools Used

Manual code review

Recommendations

Use OpenZeppelin’s SafeMath, Multiply first, then divide to avoid precision loss.

amount = withdrawn.add(balanceBeforeWithdrawal.mul(shares).div(totalShares));
Updates

Lead Judging Commences

n0kto Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

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.

Suppositions

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.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.