https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/branches/OrderBranch.sol#L271-L275
https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/branches/SettlementBranch.sol#L376-L380
Zaros intends to prevent traders from increasing their positions when the relevant market or Settlement is disabled, allowing only position closures to gradually reduce the market's total open interest to zero. However, the system fails to account for the possibility of increasing reverse positions during closure, enabling users to exploit this oversight. By maintaining a minimal position in one direction, users can open arbitrary positions in the opposite direction after market closure and then revert to their original direction, effectively circumventing the system's trading control mechanisms.
In both createMarketOrder()
and _fillOrder()
functions, Zaros checks if an order is opening or increasing an existing position using Position.isIncreasing()
. When true, the trader increases the market's total open interest. When the market or Settlement is disabled, the system aims to prevent position increases, expecting the market's open interest to eventually reach zero. However, when a trader opens a position in the opposite direction, it bypasses these checks, allowing continued trading.
The key steps are:
Trader opens a long position of 1e19 when the market is enabled.
Market is disabled.
Trader opens a short position of -3e19 after market disablement.
The transaction is approved, increasing the market's total open interest.
Trader can then open another long position of 5e19.
Place the following test into createMarketOrder.t.sol::CreateMarketOrder_Integration_Test
:
Heightened Risk During Market Volatility: Considering that markets are often closed due to extreme volatility and high risk, this vulnerability becomes particularly dangerous. It allows users to increase their exposure precisely when the market is most unstable, potentially leading to:
a) Severe financial losses for traders who may not fully understand the risks.
b) Increased platform risk as larger positions are opened during highly volatile periods.
c) Amplified systemic risk as the platform's exposure to volatile assets increases when it should be decreasing.
Low-Cost Exploitation: The cost of exploiting this vulnerability is remarkably low. Users need only create multiple accounts and maintain minimal positions in both directions of the market. This low barrier to exploitation increases the likelihood and frequency of its occurrence, potentially leading to:
a) Widespread abuse of the system by multiple users.
b) Difficulty in detecting and preventing exploitative behavior due to its low-cost nature.
c) Increased strain on the platform's risk management systems as they attempt to handle numerous small positions that can quickly become large exposures.
Manual Review.
Ensure Users Can Only Close Positions Without Increasing Exposure in the Opposite Direction:
Modify the createMarketOrder()
and _fillOrder()
functions to strictly limit trading activities when the market or Settlement is disabled.
Implement a checking mechanism to ensure that when a user attempts to open a position in the opposite direction, the size of the new position does not exceed the absolute value of the existing position.
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.