If between the creation and filling of an order, the account becomes liquidatable, then the filling would be successful, although the protocol intends to prevent liquidatable accounts from trading.
Increasing/decreasing size in a liquidatable position is not allowed.
https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/branches/OrderBranch.sol#L128-L137
But, if a decreasing size order is created, and before it is filled, the account becomes liquidatable, then this order can be filled. This is against the intention of the protocol because decreasing size order is filled even though it is liquidatable.
The root cause of this issue is that during filling the order, it does not check that the associated account is liquidatable or not. It is only checked during creating order in the function simulateTrade
.
In the following test, a long position with size 80 is created and filled. Later, another position with size -50 is created. Before this order is filled, the price of ETH decreases by 8$, making the account liquidatable (marginBalance < requiredMaintenanctMargin
). But, since the order is already created, the filling of this order would be done successfully.
If an account becomes liquidatable before its order is filled, the order will be filled although it is against the protocol rule.
During filling the order, it should check the liquidatability of the account by calling the function checkLiquidatableAccounts
.
https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/branches/LiquidationBranch.sol#L42C14-L42C39
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.