Keepers can be forced to waste gas with long revert messages
A malicious user can force keepers to waste gas by making a callback revert with an extremely long message, which is then fetched and emitted, tripling the expected gas cost. This can prevent orders from being executed or allow price manipulation.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/141
Found by
0xAmanda, IllIllI, KingNFT
Summary
Most actions done on behalf of users have a callback triggered on an address provided by the position's account holder. In order to ensure that these callbacks don't affect order execution, they're wrapped in a try-catch block, and the actual external call has a limited amount of gas provided to it. If the callback fails, the revert message is fetched and emitted, before processing continues. Keepers are given a limited gas budget based on estimated amounts of gas expected to be used, including a maximum amount allotted for callbacks via the callbackGasLimit().
Vulnerability Detail
A malicious user can use the full callbackGasLimit() to create an extremely long revert string. This would use three times the expected amount of gas, since the callback will spend that amount, the fetching of the message during the revert will fetch that much, and the emitting of the same string will fetch that much.
Impact
Keepers can be forced to spend more gas than they expect to for all operations. If they don't have a reliable way of calculating how much gas is used, they'll have spent more gas than they get in return.
If all keepers are expected to be able to calculate gas fees, then an attacker can submit an order whose happy path execution doesn't revert, but whose failure path reverts with a long string, which would essentially prevent the order from being executed until a more favorable price is reached. The user could, for example, submit an order with a long revert string in the frozen order callback, which would prevent the order from being frozen, and would allow them to game the price impact
Code Snippet
A single revert message uses gas x3:
// File: gmx-synthetics/contracts/callback/CallbackUtils.sol : CallbackUtils.afterOrderCancellation() #1
127 function afterOrderCancellation(bytes32 key, Order.Props memory order) internal {
128 if (!isValidCallbackContract(order.callbackContract())) { return; }
129
130 @> try IOrderCallbackReceiver(order.callbackContract()).afterOrderCancellation{ gas: order.callbackGasLimit() }(key, order) {
131 } catch (bytes memory reasonBytes) {
132 @> (string memory reason, /* bool hasRevertMessage */) = ErrorUtils.getRevertMessage(reasonBytes);
133 @> emit AfterOrderCancellationError(key, order, reason, reasonBytes);
134 }
135: }
Tool used
Manual Review
Recommendation
Count the gas three times during gas estimation
Discussion
xvi10
Fix in https://github.com/gmx-io/gmx-synthetics/commit/b0bac262191f4f96edc9606192d2e4abfa043dc3
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 gas estimation for keepers does not account for the triple cost of a callback revert message: the callback itself, fetching the revert reason, and emitting it.
Impact
Keepers may spend more gas than they earn, and attackers could delay order execution or manipulate prices by preventing order freezing.
What the attacker needed
A position with a callback contract; ability to submit orders
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.
In blockchain systems, 'keepers' are automated bots that execute orders for users and get paid in gas. A user can set up a callback that fails with a very long error message, and the system then processes that message twice more, making the keeper spend much more gas than planned. This can make keepers lose money or skip orders.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.