Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Invalid

No Partial Liquidation Support in LiquidationBranch,sol::liquidateAccounts()

Summary

The liquidation mechanism currently mandates the complete closure of a position rather than supporting partial liquidation. This all-or-nothing approach may force traders to liquidate their entire market exposure unnecessarily, potentially resulting in higher losses than if only a fraction of the position were closed to restore adequate margin levels.

Vulnerability Details

The code forces full liquidation by computing the liquidation size as the negative of the entire open position:

// Save inverted sign of open position size to prepare for closing the position
ctx.liquidationSizeX18 = -ctx.oldPositionSizeX18;

Later, the entire position is cleared:

// ... later in the code ...
position.clear();

This indicates that the system does not support partial liquidation where only a portion of the position is closed to bring the account back in compliance with margin requirements. The absence of flexibility in liquidation size means that even when a small position reduction would suffice, the protocol liquidates the entire position, potentially exacerbating losses.

Impact

  • Excessive Losses for Traders: Forcing a full liquidation may lead to higher-than-necessary losses, as traders lose the benefit of retaining some exposure which might still be profitable.

  • Inefficient Risk Management: Traders lose the opportunity to adjust positions gradually and recover by partially closing positions, leading to more aggressive and costly liquidation outcomes.

  • Market Confidence Erosion: The inability to execute partial liquidations may deter market participants who value flexibility in managing risk, potentially affecting overall market liquidity.

Tools Used

  • Manual Code Review

  • Static Analysis Tools

  • Simulation Testing

Recommendations

  • Implement Partial Liquidation Logic: Modify the liquidation mechanism to allow for closing only a portion of a position when appropriate. This may involve:

    • Calculating the minimum liquidation size necessary to restore the margin above the maintenance threshold.

    • Adjusting the position size by the calculated amount instead of clearing it entirely.

  • Dynamic Liquidation Parameters: Introduce parameters that determine the optimal fraction of the position to liquidate based on the margin shortfall and current market conditions.

  • Update Event Logging: Enhance event emissions to include details of the partial liquidation, such as the portion liquidated and the remaining position size.

  • Comprehensive Testing: Develop unit and integration tests to cover various partial liquidation scenarios ensuring that the system behaves as expected under different market conditions.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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