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