The admin can remove collateral from the LiquidationPriority List at any time to rearrange the priority list. However, if a user deposits this collateral, creates a position, and then attempts to increase a position already in loss (while the admin has removed the collateral, perhaps temporarily), the fill order succeeds without deducting from the account margin. Likewise liquidation attempts as well will fail to deduct loss from margin due to the same reason.
The LiquidationPriority List determines which collateral types are used first when deducting margin. This priority list ensures collateral with the lowest LTV is used first, maintaining the highest quality collateral for the user after deductions. The priority-based deduction logic is within the deductAccountMargin function:
A problem arises if the admin removes a collateral type from the priority list via the removeCollateralFromLiquidationPriority function in the GlobalConfigurationBranch.sol. This removal can be for various reasons, including removing elements and readding them to rearrange priorities for instance.
The act of removing a collateral type from the priority list introduces this edge case:
Bob deposits collateral A and executes a market order to buy 1 BTC. The order gets filled.
The price of BTC falls slightly, but Bob is not yet liquidatable. However, he has a loss on his current position.
The Admin executes a call to remove collateral A from the collateralLiquidationPriority.
Bob requests to increase his position size.
Since collateral A is not in the collateralLiquidationPriority list, the current loss is not deducted from Bob via deductAccountMargin, and the order to increase the position is filled successfully.
Similarly it also introduces this edge case in regards to liquidations:
Bob deposits collateral A and executes a market order to buy 1 BTC. The order gets filled.
The price of BTC falls dramatically, and Bob's position is liquidatable.
The Admin executes a call to remove collateral A from the collateralLiquidationPriority.
The liquidation keeper attempts to liquidate Bob's position.
Since collateral A is not in the collateralLiquidationPriority list, the request to liquidate Bob's position executes succesfully, but the current loss is not deducted from Bob via deductAccountMargin.
The first POC demonstrates the former edge case, while the second demonstrates the latter.
Output is:
Output is:
All trades to increase a position will fail to fully deduct losses from current position if the collateral type was removed from the priority list before submitting the order. Similarly, liquidation calls will succeeed without deducting losses from user's margin.
Manual Review
Before creating/filling an order that 'increases' position size, make sure that all the user's deposited margins are included with the Liquidation priority list. A solution will also need to be introduced to ensure liquidation calls will only occur if all user deposited margins are included in liquidation priority list.
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.