The execution fee in the PerpetualVault._payExecutionFee function is calculated using tx.gasprice, which can vary significantly. This can lead to insufficient fees if gas prices spike, causing transactions to fail or be delayed.
The _payExecutionFee function calculates the minimum execution fee using the current transaction's gas price (tx.gasprice). Gas prices can fluctuate significantly, especially during periods of high network congestion. If the gas price spikes after the execution fee is calculated but before the transaction is mined, the calculated fee may become insufficient, leading to failed transactions.
Root Cause:
The execution fee is calculated using tx.gasprice, which can vary significantly, leading to insufficient fees if gas prices spike.
Proof of Concept:
Code Analysis:
Example Scenario:
Execution Fee Calculation:
Assume the gas price at the time of calculation is 50 gwei.
The execution fee is calculated as getExecutionGasLimit(isDeposit) * 50 gwei.
Gas Price Spike:
Before the transaction is mined, the gas price spikes to 100 gwei.
The calculated execution fee is now insufficient to cover the increased gas cost.
Transaction Failure:
The transaction fails due to insufficient execution fees.
The user needs to resubmit the transaction with a higher fee, causing delays and additional costs.
** Unit Test: copy and paste to** PerpetualVault.t.sol
Failed transactions due to insufficient execution fees can cause delays in processing deposits and withdrawals, leading to stuck operations and a poor user experience. Users may need to resubmit transactions with higher fees, incurring additional costs and delays.
Manual
To prevent insufficient execution fees due to gas price fluctuations, consider implementing a buffer or using a more stable mechanism for calculating the execution fee. One approach is to add a buffer to the calculated fee:
You can also consider to use maxGasCost technique as recommended in this report below:
https://solodit.cyfrin.io/issues/m-02-maker-order-buyer-is-forced-to-reimburse-the-gas-cost-at-any-txgasprice-code4rena-infinity-nft-marketplace-infinity-nft-marketplace-contest-git
The frontrunner won’t trigger "congestion" without a huge amount of transactions, and it will cost a lot. Moreover, the execution gas limit is overestimated to prevent such cases: ``` executionGasLimit = baseGasLimit + ((estimatedGasLimit + _callbackGasLimit) * multiplierFactor) / PRECISION; ``` The keeper won’t wait long to execute the order; otherwise, GMX would not be competitive.
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.