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

Unbounded Loop in `getUserDeposits` Function

Summary

The getUserDeposits function in PerpetualVault.sol iterates over all deposits for a user, which could lead to gas exhaustion if the number of deposits is large.

https://github.com/CodeHawks-Contests/2025-02-gamma/blob/84b9da452fc84762378481fa39b4087b10bab5e0/contracts/PerpetualVault.sol#L643-L652

Vulnerability Details

  • The function uses EnumerableSet to store user deposits, but it does not limit the number of deposits that can be retrieved in a single call.

  • If a user has a large number of deposits, the function could run out of gas and revert.

  • The getUserDeposits function iterates over all deposits for a user using EnumerableSet and returns an array of deposit IDs. The issue arises because the function does not implement pagination or any mechanism to limit the number of deposits retrieved in a single call. If a user has a large number of deposits, the function could consume an excessive amount of gas, potentially leading to gas exhaustion and causing the transaction to revert.

  • Example Scenario:

    • A user has made 10,000 deposits into the vault.

    • When the getUserDeposits function is called, it attempts to iterate over all 10,000 deposits.

    • The gas cost of iterating over 10,000 deposits exceeds the block gas limit, causing the transaction to revert.

    • The user is unable to retrieve their deposit information, and the contract becomes unusable for them.

Impact

Gas exhaustion could prevent users from retrieving their deposit information.

Tools Used

Manual Review

Recommendations

  • Add pagination to the getUserDeposits function to limit the number of deposits retrieved in a single call.

  • Alternatively, use a mapping to store deposit information instead of an EnumerableSet.

Updates

Lead Judging Commences

n0kto Lead Judge 7 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.

n0kto Lead Judge 7 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.

Support

FAQs

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