The createOrder and settle function in the GmxProxy contract currently uses tx.gasprice to calculate execution fees. This approach introduces a security risk, as malicious users can manipulate the gas price to influence the order execution fees. This issue could lead to insufficient fees for Keeper incentives and transaction failure.
In the current implementation of the createOrder and settle function, the execution fee is calculated as follows:
contracts/GmxProxy.sol:createOrder:#L379
contracts/GmxProxy.sol:settle#L467
The use of tx.gasprice allows users to manipulate the execution fees by setting an artificially low gas price when submitting the transaction. This could result in the following:
Manipulation of Execution Fee: Users can influence the fee by adjusting the gas price, leading to an insufficient fee for executing the order.
Keeper Incentive Disruption: If the calculated fee is too low, Keepers may refuse to execute the order, disrupting the system's incentive structure.
Potential Transaction Failures: The actual gas price during execution may differ significantly from the transaction’s tx.gasprice, leading to failures in executing the orders.
Security Risk: The ability for users to manipulate gas prices introduces a significant security flaw that can be exploited.
Economic Model Disruption: The manipulation of fees undermines the economic incentives for Keepers, potentially causing orders to accumulate without being executed.
Transaction Failures: Orders might fail due to gas price discrepancies between creation and execution, impacting user experience and trust in the platform.
Manual Review
To prevent gas price manipulation, we recommend modifying the code to use a fixed or calculated safe gas price rather than relying on tx.gasprice. Specifically:
Implement a Fixed Gas Price Mechanism: Introduce a default multiplier or a buffer based on block.basefee to calculate a more secure gas price.
Use a Secure Gas Price Calculation: Implement a function to return a more consistent and predictable gas price rather than using tx.gasprice.
If the sender does not provide enough, the transaction to create the order won't be included in the current block: no problem. If the user provides more, they will pay more: user mistake. Moreover, the `refundFee` is set to `true` only when the keeper is the caller, preventing manipulation.
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.