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

Treasury takeover on all user funds if the transfer fails

Summary

During withdraw, if collateralToken.transfer fails, then all assets transfers to treasury. That's unfair with depositors. Depositors loose asets.

Vulnerability Details

The function PerpetualVault.sol::withdraw() attempts to transfer the amount (amount - fee) to the recipient using collateralToken.transfer(...) inside a try-catch.
If the transfer fails, it catches the failure and sends the entire remaining amount to the treasury (collateralToken.transfer(treasury, amount - fee)).

  • This means that the user loses their funds, and the protocol treasury gains them.

  • The protocol is only meant to collect fees, a transfer failure shouldn't redirect the user's entire assets to the treasury.

Link to code :

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

Impact

  1. Loss of user funds: If a transfer to the recipient fails, the user should at least have an option to retry or claim their funds later instead of the treasury absorbing them.

  2. Unfair behavior: The protocol only expects fees when a user makes a profit. But if a transfer fails, the whole withdrawal goes to the treasury, even when no profit was made.

Tools Used

Manual Review

Recommendations

Instead of directly sending funds to the treasury when a transfer fails, a better approach is:

  • Revert the transaction if collateralToken.transfer(...) fails.

  • Allow users to retry the withdrawal later instead of redirecting to the treasury.

Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Admin is trusted / Malicious keepers

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. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

Appeal created

mohitisimmortal Submitter
5 months ago
n0kto Lead Judge
5 months ago
n0kto Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Admin is trusted / Malicious keepers

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. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

Users mistake, only impacting themselves.

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.