Part 2

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

Liquidation all Positions Cause Slippage Cascade in the `LiquidationBranch.sol` Contract

Summary

In the liquidateAccounts function of LiquidationBranch.sol contract all positions can be fully liquidated at once. This can be a problem in illiquid markets, where large-scale liquidations could cause significant slippage. Such behavior can negatively affect both the users involved in the liquidation and the market itself. Implementing partial liquidation based on market liquidity could help mitigate these risks.

Vulnerability Details

In the LiquidationBranch.sol contract, the code sets ctx.liquidationSizeX18 = -ctx.oldPositionSizeX18;, assuming that the entire position can be liquidated in a single transaction.
However, in illiquid markets, attempting to liquidate large positions in a single transaction may lead to significant slippage. Large-scale liquidations can severely impact market prices, making the liquidation price significantly worse than the market price, resulting in unfair liquidation outcomes for users. Major price fluctuations due to large liquidations could lead to a cascade effect, triggering liquidations of other positions and potentially causing a liquidation "cascade."

src/perpetuals/branches/LiquidationBranch.sol:liquidateAccounts#L189

function liquidateAccounts(uint128[] calldata accountsIds) external {
...
// save inverted sign of open position size to prepare for closing the position
ctx.liquidationSizeX18 = -ctx.oldPositionSizeX18;

Impact

  1. Significant Slippage: In markets with low liquidity, large position liquidations could cause substantial price slippage, resulting in users being liquidated at much worse prices than expected.

  2. Unfair Liquidations: Users with positions being liquidated might experience unfair losses due to the price impact of large-scale liquidations in illiquid markets.

  3. Market Instability: A lack of partial liquidation mechanisms could lead to a cascade of liquidations, further destabilizing the market and possibly triggering a domino effect of additional liquidations.

Tools Used

Manual Code Review

Recommendations

It is recommended to implement partial liquidation and add logic to limit the liquidation size based on the market liquidity. For large positions, split the liquidation into multiple smaller transactions to avoid overwhelming the market and causing significant price movements. And set a limit on the size of any single liquidation transaction to prevent excessive market impact. For example:

function calculateLiquidationSize(uint256 positionSize, uint256 marketLiquidity) internal returns (uint256) {
uint256 maxLiquidationSize = min(positionSize, marketLiquidity);
return maxLiquidationSize;
}
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.