DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: high
Valid

Market Open Interest and Skew are set to 0 after liquidation

Summary

Uninitialized variables ctx.newOpenInterestX18 and ctx.newSkewX18 are used for setting market open interest value and skew value during liquidation, results in incorrect open interest and skew.

Vulnerability Details

When accounts are liquidated, protocol iterates each account's active markets and do same updates, including updating each market's open interest value and skew value.

// update perp market's open interest and skew; we don't enforce ipen
// interest and skew caps during liquidations as:
// 1) open interest and skew are both decreased by liquidations
// 2) we don't want liquidation to be DoS'd in case somehow those cap
// checks would fail
@> perpMarket.updateOpenInterest(ctx.newOpenInterestX18, ctx.newSkewX18);

Unfortunately, ctx.newOpenInterestX18 and ctx.newSkewX18 are not initialized during liquidation, hence the value are both 0, leading to each market's open interest value and skew value are set to 0.

Please copy the following code snippet into testFuzz_GivenThereAreLiquidatableAccountsInTheArray() in liquidateAccounts.t.sol to verify:

// Market openInterest is set to 0
(UD60x18 longsOpenInterest, UD60x18 shortsOpenInterest, UD60x18 totalOpenInterest)
= perpsEngine.getOpenInterest(ctx.fuzzMarketConfig.marketId);
assertEq(0, longsOpenInterest.unwrap());
assertEq(0, shortsOpenInterest.unwrap());
assertEq(0, totalOpenInterest.unwrap());
// Market skew is set to 0
SD59x18 skew = perpsEngine.getSkew(ctx.fuzzMarketConfig.marketId);
assertEq(0, skew.unwrap());

Impact

Open interest and skew are used to determine the mark price for trades and the funding rate for positions.

  • Incorrect open interest and skew could result in traders being allowed to open positions that exceed the market limits, potentially leading to price manipulation and instability.

  • Incorrect mark price may also bring huge loss to the traders.

Tools Used

Manual Review

Recommendations

Initialize ctx.newOpenInterestX18 and ctx.newSkewX18 before setting market open interest and skew.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`liquidateAccounts` calls `updateOpenInterest` with uninitialized OI and skew)

Support

FAQs

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