This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
0xdeadbeef - Insufficiant gas calculations when paying execution cost to keeper #222
Labels
Escalation Resolved
This issue's escalations have been approved/rejected
Excluded
Excluded by the judge without consulting the protocol or the senior
Non-Reward
This issue will not receive a payout
0xdeadbeef
high
Insufficiant gas calculations when paying execution cost to keeper
Summary
The protocol calculates the execution fees it should send the the keeper and then returns any additional funds to the user.
However, the calculations do not include the operation of sending the funds themselves.
The sending operation is currently not deterministic and can result in large gas consumption which will be paid by the keeper without compensation
Vulnerability Detail
After executions of deposits/withdrawals/orders, the protocol pays the keeper the execution cost through
payExecutionFee
The
executionFeeForKeeper
is calculated by the gas used and additional factors defined inadjustGasUsage
:As can be seen, the gas price is adjusted to account for
withOraclePrices
gas consumption but is not adjusted to include the execution of thebank.transferOutNativeToken
of the fees and refund.bank.transferOutNativeToken
will callwithdrawAndSendNativeToken
and can consume a lot of gas for native transfers and for non-native transfers (when failed)It first attempts to transfer native token unwrapped and caps the gas consumption to
NATIVE_TOKEN_TRANSFER_GAS_LIMIT
(currently 200_000 gas) and if it fails it will wrap the native token and transform it using ERC20 transfer function.Consider a user that consumes more then 200_000 gas when receiving the refund. This will make the keeper pay a large amount of gas for the attempted transfer and for the wrapping and transfer of ERC20.
Impact
Loss of funds for keeper
Code Snippet
https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/gas/GasUtils.sol#L97
Tool used
Manual Review
Recommendation
The main issue is that it is not deterministic how much gas
withdrawAndSendNativeToken
will consumeTo make it deterministic I suggest:
CALL
opcode to transfer funds.With the above recommendations, the gas can be calculated in a deterministic way and included in
adjustGasUsage
adjustmentsThe text was updated successfully, but these errors were encountered: