Skip to content
Business logic Audit finding Intermediate

when execute deposit fails, cancel deposit will be called which means that execution fee for keeper will be little for executing the cancellation depending on where the executeDeposit fails

When a deposit execution fails partway through, the contract automatically cancels the deposit and pays the keeper from whatever execution fee remains. Because the failed execution already consumed part of that fee, the keeper can receive very little for the cancellation work.

koxuan Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/89

Found by

koxuan

Summary

When execute deposit fails, the deposit will be automatically cancelled. However, since executeDeposit has taken up a portion of the execution fee, execution fee left for cancellation might be little and keeper will lose out on execution fee.

Vulnerability Detail

In executeDeposit when an error is thrown, _handleDepositError is called.

Solidity
            _handleDepositError(
                key,
                startingGas,
                reasonBytes
            );

Notice that in _handleDepositError that cancelDeposit is called which will pay execution fee to the keeper. However, since the failure can have failed at the late stage of executeDeposit, the execution fee left for the cancellation will be little for the keeper.

Solidity
    function _handleDepositError(
        bytes32 key,
        uint256 startingGas,
        bytes memory reasonBytes
    ) internal {
        (string memory reason, /* bool hasRevertMessage */) = ErrorUtils.getRevertMessage(reasonBytes);


        bytes4 errorSelector = ErrorUtils.getErrorSelectorFromData(reasonBytes);


        if (OracleUtils.isEmptyPriceError(errorSelector)) {
            ErrorUtils.revertWithCustomError(reasonBytes);
        }


        DepositUtils.cancelDeposit(
            dataStore,
            eventEmitter,
            depositVault,
            key,
            msg.sender,
            startingGas,
            reason,
            reasonBytes
        );
    }
}

Note: This also applies to failed executeWithdrawal.

Impact

Keeper will lose out on execution fee in the event of a failed deposit.

Code Snippet

DepositHandler.sol#L109-L113 DepositHandler.sol#L181-L205

Tool used

Manual Review

Recommendation

Recommend increasing the minimum required execution fee to account for failed deposit and refund the excess to the user when a deposit succeeds.

Discussion

xvi10

this is a valid issue, no code changed, the configuration for gas estimation should be updated to account for this

The original report as published on Sherlock, by koxuan. 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

Likely the execution fee is sized only for the main execution path, so when a failure triggers a second cancellation transaction, the remaining fee does not cover the keeper's gas cost.

Impact

Keepers may lose money on failed deposits and withdrawals because the cancellation fee can be too small to cover their gas.

What the attacker needed

Keeper executes a deposit; deposit fails during execution

The fix

The minimum required execution fee should be raised to cover a possible failed deposit, with any excess refunded to the user when the deposit succeeds.

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.

A keeper is an automated bot that runs transactions for users and is paid a fee for the gas it spends. Here, if the main deposit step fails, the contract still asks the keeper to run a cancellation step, but most of the fee was already used up by the failed attempt, so the keeper is underpaid for that extra work.

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 koxuan

View all

7 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.