LiquidationBranch::liquidateAccounts() will update market's skew and openInterest. However, at this step both ctx.newOpenInterestX18 and ctx.newSkewX18 are haven't been initialized, which leaves them to 0.
ctx.newOpenInterestX18 and ctx.newSkewX18 should have been the original values minus those of the liquidated accounts like what they do in here.In fact this step is missed according to the comment we don't enforce open interest and skew caps.
There is another thing I would like to point out is that the developer do want to check the skew and openInterest are handled properly here.They create a nonLiquidatableTradingAccountId and want to make sure that after liquidation the skew and openInterest contributed by nonLiquidatableTradingAccount stays.But they forgot to open a position for that nonLiquidatableTradingAccount, which makes the nonLiquidatableTradingAccount's size is 0, and that happens to make the check passed because 0=0.
To prove the issue stands, we only need to add something in testFuzz_GivenThereAreLiquidatableAccountsInTheArray() as below:
The whole POC is here, put it into test/integration/perpetuals/liquidation-branch/liquidateAccounts/liquidateAccounts.t.sol and then run forge test --match-path test/integration/perpetuals/liquidation-branch/liquidateAccounts/liquidateAccounts.t.sol --match-test testFuzz_LiqudateWillMakeOiAndSkewto0 -vvvvv
part of the result as follows:
The skew and openinterest are crucial parameters of a market.Especially the skew. According to the doc, the project use a special way to calculate mark price based on the skew. This value represent how many size the long and short have been opened in the market and if every liquidation event which happens all the time in any markets, will make the two values become 0.Then the whole functionality of the contract will be broken and any calculations based on this will go wrong which makes this issue as high.
Manually Review
Ensure that ctx.newOpenInterestX18 and ctx.newSkewX18 are correctly initialized and assigned.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.