Skip to content
Business logic Audit finding Intermediate

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:

  1. Users will not be able to create/cancel the operations
  2. 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:

  1. Bob creates a deposit using createDeposit
  2. GMX disabled deposits because of maintenance.
  3. Keeper executed Bobs deposit
  4. Bobs deposit is cancelled and the execution fee is paid to the keeper from Bobs pocket.
  5. 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:

  1. 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
  2. Add the feature check in the internal DepositUtils.cancelDeposit functions

Discussion

xvi10

Fix in https://github.com/gmx-io/gmx-synthetics/commit/51d1a7f161ab1b5081dc7cc5172ae30dfa063e1f

The original report as published on Sherlock, by 0xdeadbeef. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Bob creates a deposit using createDeposit
  2. GMX disables deposits for maintenance
  3. A keeper executes Bob's deposit
  4. The deposit is cancelled and the execution fee is paid to the keeper from Bob's funds
  5. 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.

More by 0xdeadbeef

View all

9 more disclosed reports, best first.

More from GMX Update

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.