The LiquidationBranch::liquidateAccounts
function does not calculate the new open interest and new skew when liquidating positions. Thus, it sets the open interest to zero, regardless of the actual state of open positions in the market. This occurs because the ctx.newOpenInterestX18
and ctx.newSkewX18
variables are not being calculated or updated before calling perpMarket.updateOpenInterest()
.
Open positions:
Naruto opens a long position of 1 BTC.
Sasuke opens a short position of 1 BTC.
Price fluctuates in one side and trigger one liquidation
After performing the liquidation, the open interest is incorrectly set to 0, while the other position still exists.
Attempting to close the remaining position fails, causing the protocol to panic due to insufficient open interest, even though the position still exists.
Add the following test in test/integration/perpetuals/liquidation-branch/liquidateAccounts/liquidateAccounts.t.sol
This issue has severe implications for the protocol:
Market Integrity: The open interest being incorrectly set to zero misrepresents the true state of the market, leading to incorrect risk assessments.
Protocol Instability: Users wouldn't be able to close their positions, as the system would incorrectly believe that no open interest exists. This could lead to:
Trapped funds: Users unable to exit their positions, potentially leading to significant losses.
Loss of trust: Users may lose confidence in the protocol, potentially causing a mass exodus and liquidity crisis.
Foundry Invariant Testing + Stress Test of the protocol
To address this issue, implement the following changes in the LiquidationBranch::liquidateAccounts
function:
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.