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

Position closure bug

Summary

The run function is designed to change the position type (long/short/close) based on off-chain instructions. However, there is a logical flaw in how positions are handled when switching between long and short positions. The comment suggests that the current position should be closed before opening a new one, but the implementation does not fully ensure this.

Vulnerability Details

Issue: Position Closure is Not Guaranteed

  • In the else block where beenLong != isLong, the comment states:

    "Close current position first and then open the requested position in the next action."

  • However, the function does not explicitly close the current position before opening a new one. Instead, it:

    1. Sets nextAction.selector = NextActionSelector.INCREASE_ACTION.

    2. Encodes isLong into nextAction.data.

    3. Calls _runSwap(metadata, false, prices) if the previous position was long with one leverage.

    4. Calls _createDecreasePosition(0, 0, beenLong, acceptablePrice, prices); otherwise.

Why is This a Problem?

  1. No Explicit Closure of Position

    • _runSwap(metadata, false, prices); only swaps tokens but does not necessarily close the GMX position.

    • _createDecreasePosition(0, 0, beenLong, acceptablePrice, prices); suggests a partial decrease, but does not guarantee full closure.

    • There is no check that the position is fully closed before proceeding to the next action.

  2. Potential State Conflict

    • If the position remains open but the nextAction is set to INCREASE_ACTION, it could lead to an inconsistent state where both long and short positions exist.

    • If _createDecreasePosition fails due to insufficient liquidity or slippage, the contract may end up in a broken state.

Impact

  • Incorrect trading behavior: The system may assume a position is closed when it is not.

  • Potential financial losses: If a long position remains open but the contract attempts to open a short position, unintended exposure may occur.

  • Smart contract inconsistencies: The contract may end up in an incorrect state, affecting future trades.

Tools Used

  • Manual code review

  • Solidity analysis

Recommendations

Updates

Lead Judging Commences

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

Admin is trusted / Malicious keepers

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. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

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.