DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: medium
Invalid

Code Improvement Report - GmxProxy.sol (Wrong Use of safeApprove and Token Transfer)

Summary

Inside GmxProxy.sol, within the createOrder function, safeApprove is granted to gmxRouter, but the token transfer is executed using gExchangeRouter.

if (
orderType == Order.OrderType.MarketSwap ||
orderType == Order.OrderType.MarketIncrease
) {
// Approval given to 'gmxRouter'
IERC20(orderData.initialCollateralToken).safeApprove(
address(gmxRouter),
orderData.amountIn
);
// Token transfer using 'gExchangeRouter.'
gExchangeRouter.sendTokens(
orderData.initialCollateralToken,
orderVault,
orderData.amountIn
);
}

Vulnerability Details

The function approves gmxRouter but then transfers the tokens using gExchangeRouter. Since gExchangeRouter has not been granted approval, the token transfer may fail.

Impact

  • Token Transfer Failure: Since the approval is given to gmxRouter but the transfer is executed using gExchangeRouter, the transaction might revert due to missing approval.

  • Potential Security Risk: Improper handling of approvals and transfers can lead to unexpected contract behavior and failed transactions.

Tools Used

  • Manual Code Review

  • Solidity Static Analysis Tools

Recommendations

Solution: Approve the Correct Address

Ensure that the approval is granted to the entity performing the token transfer.

Updated Code

if (
orderType == Order.OrderType.MarketSwap ||
orderType == Order.OrderType.MarketIncrease
) {
// Approval given to 'gExchangeRouter' instead of 'gmxRouter'
IERC20(orderData.initialCollateralToken).safeApprove(
address(gExchangeRouter),
orderData.amountIn
);
// Token transfer using 'gExchangeRouter.'
gExchangeRouter.sendTokens(
orderData.initialCollateralToken,
orderVault,
orderData.amountIn
);
}

This ensures that the address executing the token transfer has the required approval.

Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.