https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/leaves/Position.sol#L171
If a user creates first MarketOrder with a small sizeDelta and then creates another MarketOrder with a higher sizeDelta in opposite direction (long if first order is short, and vice versa), isIncreasing function in Position library will return false for second order.
Position.sol#L171: return self.size == 0 || (self.size > 0 && sizeDelta > 0) || (self.size < 0 && sizeDelta < 0);
Case 1:
If a user creates a MarketOrder with a small sizeDelta of 1 (long position) and then creates another MarketOrder with a higher sizeDelta of -100 (short position), isIncreasing function will return false for second order.
For second order, size will be > 0 (i.e., 1)
sizeDelta < 0 (i.e., -100)
Case 2:
If a user creates a MarketOrder with a small sizeDelta of -1 (short position) and then creates another MarketOrder with a higher sizeDelta of 100 (long position), isIncreasing function will return false for second order.
For second order, size will be < 0 (i.e., -1)
sizeDelta > 0 (i.e., 100)
In both cases, overall position size is increasing but isIncreasing function is not behaving as expected.
Traders can change side (long/short) of a position even if the market is disabled, which breaks market controls.
Incorrect margin requirements will be applied, letting positions to stay open with insufficient initial margin.
Manual, Foundry
Add a check in createMarketOrder and _fillOrder functions before calling isIncreasing, to revert transaction if user is switching position side from short to long, and vice versa.
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.