The GmxProxy::getExecutionGasLimit function is responsible for estimating the gas required to execute various GMX operations, such as deposits, withdrawals, and swaps. However, the current implementation has critical flaws in how gas fees are calculated, leading to potential underpayment or overpayment of gas fees. These issues stem from static assumptions about the number of swaps and oracle prices, which do not account for dynamic transaction requirements.
The function assumes that only one swap will occur for all order types. This is evident in the following code:
However, in practice, transactions may involve multiple swaps, especially in complex operations like multi-hop swaps or batch transactions. This static assumption leads to incorrect gas estimations.
The function uses a hardcoded value for the number of oracle prices (oraclePriceCount = 5):
This value is derived from the formula numberOfSwaps + 3, but it is not dynamically calculated. As a result:
If the number of swaps is greater than 2, the oracle price count will be underestimated, leading to insufficient gas fees.
If the number of swaps is less than 2, the oracle price count will be overestimated, causing users to overpay.
Insufficient Gas Fees:
Transactions may fail due to insufficient gas, leading to a poor user experience and potential loss of funds.
Failed transactions can also result in wasted gas fees.
Overpayment of Gas Fees:
Users may pay more than necessary for gas, reducing the cost-effectiveness of the protocol.
Overpayment can discourage users from using the platform, especially in high-frequency trading scenarios.
Manual Code Review
Introduce a parameter to dynamically calculate the number of swaps based on the transaction requirements. For example:
Replace the hardcoded oraclePriceCount with a dynamic calculation based on the number of swaps:
Likelihood: Low/Medium, when swapPath has more than 1 item. Impact: Medium/High, could lead to not enough fee collected to execute the transaction in GMX
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.