Part 2

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

Missing Time-Based Liquidation Cooldown Period in LiquidationBranch.sol::liquidateAccounts()

Summary

The liquidation mechanism does not enforce any time-based cooldown between successive liquidation attempts. As a result, accounts that have just been liquidated (or are borderline liquidatable) can be immediately targeted again. This absence of a grace period prevents traders from adding margin or adjusting positions, potentially leading to unnecessarily aggressive and repeated liquidations.

Vulnerability Details

In the liquidateAccounts(uint128[] calldata accountsIds) function, there is no check of a time-stamp or cooldown parameter to ensure that sufficient time has passed between liquidation attempts on the same account. For example, the function implementation:

function liquidateAccounts(uint128[] calldata accountsIds) external {
// No check for last liquidation attempt timestamp
// Immediate processing of liquidation requests
...
}

The lack of any time-based cooldown mechanism means that an account that is liquidatable can be processed repeatedly in rapid succession. During periods of high market volatility, temporary price fluctuations might push an account below the maintenance margin requirement. Without a cooldown, the account can be liquidated multiple times without giving the trader an opportunity to add margin or otherwise mitigate the situation.

Impact

  • Repeated Liquidations: Traders may experience multiple liquidations in quick succession, which can drastically erode their collateral and lead to severe financial losses.

  • Unfair Penalties: A lack of a grace period means that temporary market perturbations can trigger unnecessary liquidations, penalizing traders for momentary liquidity issues.

  • Market Manipulation: Malicious actors could exploit this rapid-fire liquidation mechanism to manipulate the market or repeatedly target specific accounts.

Tools Used

  • Manual Code Review

  • Static Analysis Tools

  • Simulation Testing.

Recommendations

  • Implement a Cooldown Period: Introduce a time-based cooldown interval in the liquidation mechanism, during which an account cannot be re-liquidated. This can be achieved by storing the timestamp of the last liquidation attempt for each account.

    Example:

    require(
    block.timestamp >= tradingAccount.lastLiquidationTimestamp + COOLDOWN_PERIOD,
    "Liquidation cooldown period has not elapsed"
    );
  • Grace Period for Margin Top-ups: Allow a grace period after an account becomes liquidatable to provide traders with the opportunity to add margin or adjust their positions.

  • Update State Variables: Ensure that upon liquidation, the account’s lastLiquidationTimestamp (or equivalent storage variable) is updated accordingly.

  • Extensive Testing: Develop tests to verify that the cooldown mechanism effectively prevents repeated liquidations in rapid succession and works correctly under various market conditions.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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