The createOrder
function in the GmxProxy
contract approves token spending for gmxRouter
without explicitly resetting prior approvals. This could lead to a scenario where an old allowance remains valid, which might be exploited if gmxRouter
is compromised. While the contract does not grant infinite approvals (i.e., type(uint256).max
), best practices dictate resetting prior approvals before assigning a new one to prevent unintended token drains.
gmxRouter
is compromisedFunction: createOrder
The function directly approves orderData.amountIn
for gmxRouter
without first setting the previous approval to zero. If an earlier approval is still active, it remains valid until explicitly overridden. This behavior could allow unintended token access if gmxRouter
is compromised or behaves maliciously.
If gmxRouter
is safe: No immediate impact, but best practices suggest mitigating this.
If gmxRouter
is compromised or upgraded maliciously: Any leftover approval from a prior transaction could be exploited, leading to unintended token transfers.
If an attacker gains control over gmxRouter
: They could call transferFrom()
using the unrevoked old allowance, draining funds.
Manual Code Review
Slither (Static Analysis)
OpenZeppelin SafeERC20 Best Practices Review
To prevent any potential exploitation, modify the approval logic to first reset the previous allowance before assigning a new one:
This ensures that no prior approvals persist and that only the exact required amount is approved, eliminating potential risks.
The issue is not a critical vulnerability but a medium-severity risk that can be mitigated with a simple fix. Implementing the recommended mitigation will ensure safer token approvals, reducing the likelihood of unintended token transfers if gmxRouter
is ever compromised.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
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.