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

Reentrancy Vulnerability in afterOrderExecution Allowing Potential Repeated Order Execution

Summary

The function afterOrderExecution in GmxProxy.sol is vulnerable to reentrancy due to an external call being made before state variables are updated. This allows an attacker to potentially re-enter the function and manipulate contract state in an unintended way.

Vulnerability Details

. The function interacts with an external contract (gExchangeRouter) to claim funding fees:

claimedAmounts = gExchangeRouter.claimFundingFees(markets, tokens, perpVault);
  • This external call could trigger arbitrary logic if the external contract is malicious or if it interacts with another user-controlled contract.
    . The function then calls another external contract (IPerpetualVault):

IPerpetualVault(perpVault).afterOrderExecution(requestKey, positionKey, orderResultData, prices);
  • If afterOrderExecution contains logic that calls back into GmxProxy, it could exploit the function before state variables are updated

. State update occurs AFTER external calls

delete queue;

PoC

Attacker Contract

  • The attacker contract would create an order and ensure execution of afterOrderExecution.

  • The attacker would then use the reentrancy attack to manipulate queue-related operations before deletion.

contract Attacker {
IGmxProxy gmxProxy;
IPerpetualVault perpVault;
constructor(address _gmxProxy, address _perpVault) {
gmxProxy = IGmxProxy(_gmxProxy);
perpVault = IPerpetualVault(_perpVault);
}
function attack(bytes32 requestKey, bytes32 positionKey, IGmxProxy.OrderResultData calldata orderResultData, MarketPrices calldata prices) external {
// Trigger the afterOrderExecution function
gmxProxy.afterOrderExecution(requestKey, positionKey, orderResultData, prices);
// Reentering before queue is deleted
gmxProxy.afterOrderExecution(requestKey, positionKey, orderResultData, prices);
}
}

Impact

  • An attacker could manipulate the queue before it is deleted, leading to unintended execution of orders.

  • Potential double execution or order manipulation if an attacker reenters before state update.

  • Can lead to fund mismanagement or even DoS (Denial of Service) if exploited correctly.

Tools Used

Manual Review

Recommendations

  • Reorder the statements to update state variables before making external calls, i.e.:

delete queue;
IPerpetualVault(perpVault).afterOrderExecution(requestKey, positionKey, orderResultData, prices);

This ensures that queue is cleared before any external function is executed.

  • Perform Checks-Effects-Interactions Pattern

    Update state before external calls to reduce attack vectors.

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

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.

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

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.

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

Support

FAQs

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

Give us feedback!