Zaros implements a way to disable a market and prevent users from opening a position in it. However, Zaros still allows users to reduce and close their existing positions since they can still be subject to liquidation.
The updatePerpMarketStatus() function is responsible for disabling a market.
The issue occurs due to a lack of checks in the createMarketOrder() function when an order is made to modify an existing position.
This function determines if the order being created will increase or decrease the position : if the position is initially a short of -10e18, increasing the position consists in making the position go even more negative, to -20e18 for example ; if the position is initially a long of 10e18, increasing the position consists in making the position go even more positive, to 20e18 for example.
The Position.isIncreasing() function is responsible for this check.
https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/leaves/Position.sol#L155-L172
However, not all the cases have been taken into account : a position can still satisfy the requirements by going from short to long, which will be considered as a decrease.
This basically leaves users the ability to interact with the market while they should not, based on the admins decision.
Disabling a market has not the expected effect on users that already have an existing position and allows them to interact with it (still making profits and losses).
Here is a coded PoC that demonstrates the issue :
It can be pasted in test\integration\perpetuals\perp-market-branch\getFundingRate\getFundingRate.t.sol
Manual review
Add additionnal checks in the Position.isIncreasing() function to handle going from short to long and from long to short.
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.