Submitted by web3km, also found by crypticdefense, nnez, 3n0ch, and pkqs90
https://github.com/code-423n4/2024-05-predy/blob/a9246db5f874a91fb71c296aac6a66902289306a/src/markets/gamma/ArrayLib.sol#L20-L32https://github.com/code-423n4/2024-05-predy/blob/a9246db5f874a91fb71c296aac6a66902289306a/src/markets/gamma/GammaTradeMarket.sol#L146-L149
Griefing/DOS attack is possible when, a malicious user creates many very small positions, which could cause excessive gas consumed and even transactions reverted when other users are trying to liquidate any of the users positions.
The function GammaTradeMarket.sol:_removePosition is using the ArrayLib::removeItem, which is currently just looping over the items, until it finds the one its looking for.
This function is called multiple times inside of GammaTradeMarket.sol, it is called right after calling GammaTradeMarket::execLiquidationCall.
A malicious user can create many really small positions with very little leverage to make sure those position will hardly be liquidated and the create, a normal position with a good amount of leverage. As a result every liquidator who tries to liquidate the users position will most likely fail, since the arrays length is too big and the position they want to liquidate is at the last place of the array.
Consider using OZs EnumerableSet Library, which will allow to add/remove items easily without the need to loop over every item to find the one that needs to be removed.
DoS
syuhei176 (Predy) confirmed
0xsomeone (judge) commented via duplicate Issue #59:
