Deposits/Withdrawals/Orders will be canceled if created before feature is disabled and attempted to be executed after
The protocol allows disabling operations like deposits, withdrawals, and orders, but when a keeper attempts to execute a disabled operation, the execution fails and the operation is cancelled, charging the user an execution fee. This leads to users losing funds and having to redo the operation.
0xdeadbeef Follow with IllIllI, csanuragjain and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/124
Found by
0xdeadbeef, IllIllI, csanuragjain, rvierdiiev
Summary
The protocol has the ability to enable/disable operations such as deposits, withdrawals and orders.
If the the above operations are disabled:
- Users will not be able to create/cancel the operations
- Keepers will not be able to execute the operations
However - on execution failure, cancellation will succeed even if the feature is disabled.
Therefore - keepers executing operations that are disabled will cancel them and make the user pay execution fees. (loss of funds)
Vulnerability Detail
Let us use deposits as an example. Other operations behave in a similar way.
Consider the following scenario:
- Bob creates a deposit using
createDeposit - GMX disabled deposits because of maintenance.
- Keeper executed Bobs deposit
- Bobs deposit is cancelled and the execution fee is paid to the keeper from Bobs pocket.
- GMX finished maintenance and enables again the deposits
Execution will fail in the following check: https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/exchange/DepositHandler.sol#L144-L150
The revert will be caught in the catch statement and _handleDepositError will be called:
https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/exchange/DepositHandler.sol#L102-L113
_handleDepositError will call DepositUtils.cancelDeposit which does not have feature validation:
https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/exchange/DepositHandler.sol#L181-L203
Impact
Users lose execution fee funds and have to deposit again.
Code Snippet
Tool used
Manual Review
Recommendation
For each operation:
- add a customer error to catch and revert the feature disable reason, like empty price is caught: https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/exchange/DepositHandler.sol#L190
- Add the feature check in the internal
DepositUtils.cancelDepositfunctions
Discussion
xvi10
Fix in https://github.com/gmx-io/gmx-synthetics/commit/51d1a7f161ab1b5081dc7cc5172ae30dfa063e1f
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The cancellation function does not check whether the feature is disabled, so it proceeds even when execution fails due to the feature being disabled.
Impact
Users lose execution fee funds and have to deposit again.
What the attacker needed
Feature is disabled by admin; User has created an operation before disabling; Keeper executes the operation while disabled
The fix
The fix adds a feature check in the cancellation function and a custom error to catch the disabled feature reason.
How it was found
- Bob creates a deposit using createDeposit
- GMX disables deposits for maintenance
- A keeper executes Bob's deposit
- The deposit is cancelled and the execution fee is paid to the keeper from Bob's funds
- GMX re-enables deposits
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The system lets admins turn off certain actions, like deposits. If someone tries to perform a turned-off action, the system cancels it but still charges a fee to the user. So users lose money even though the action was not allowed.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.