Submitted by nonseodion, also found by 0xbepresent
A user can create a ShortOrder with ercAmount == minAskEth/2 by matching the ShortOrder with a bid that fills it up to minAskEth/2 and exiting the ShortRecord leaving only minAskEth/2 in the ShortOrder with an empty ShortRecord.
This issue makes use of two properties in the codebase.
A ShortOrder on the market can be matched by an incoming bid. This match is done in the call to bidMatchAlgo() function. Which tries to fill the bid with asks or shorts in the market.
BidOrdersFacet.sol#L106-L111
In the call to bidMatchAlgo(), it goes through a loop and on each iteration, it first tries to match lowestSell in line 155 below. lowestSell is the current lowest bid or ask.  After matching it compares the ercAmount in the bid and lowest sell.
If the ercAmount in the lowest sell exceeds that in the bid, the bid is filled and executes the else statement in line 179 below. If the amount left in the lowest sell is >= LibAsset.minAskEth(asset).mul(C.DUST_FACTOR), b.dustShortId and b.dustAskId are set to zero in line 191 below. This ensures the lowest sell isnt deleted in the call to matchIncomingBid() function.
BidOrdersFacet.sol#L155-L197
If the amount in lowestSell is less than LibAsset.minAskEth(asset).mul(C.DUST_FACTOR), matchIncomingBid() deletes in the code section below.
BidOrdersFacet.sol#L292-L296
LibAsset.minAskEth(asset).mul(C.DUST_FACTOR) translates to minAskEth/2 because C.DUST_FACTOR is a constant and is 0.5 ether. So if a ShortOrder has minAskEth/2 it wont be deleted.
When a call is made to the exitShortWallet() or exitShortErcEscrowed() function, shortOrderId is passed which is expected to be the order id of the ShortRecord currently being exited. exitShortWallet() function calls checkShortMinErc() and passes the shortOrderId.
ExitShortFacet.sol#L67-L73
In the call to checkShortMinErc(), the shortOrderId is verified in line 94 below by checking if the shortOrder currently points to ShortRecord or if its address points to the shorter, i.e. the owner of the ShortRecord.
LibSRUtil.sol#L81-L99
Note: it doesnt check if the ShortOrder is cancelled. This means we can use a cancelled ShortOrder that points to the ShortRecord and is owned by the owner of the ShortRecord being exited.
A malicious user can use these two properties of the codebase to create a ShortOrder that has minAskEth/2 as ercAmount and 0 debt in its ShortRecord by following these setps:
If the minAskEth is small, well end up creating small ShortOrders in the market. ShortOrders like this may make a transaction trying to fill a large order run out of gas and may disincentivize liquidators from liquidating them if they become liquidatable.
The issue above has the following effects:
The test below can be run in the Shorts.t.sol file. It shows how a malicious user can create a ShortOrder with a small amount.
Make sure to import the library below:
import {STypes, MTypes, O, SR} from "contracts/libraries/DataTypes.sol";
Consider checking if the ShortOrder being validated in checkShortMinErc() is cancelled.
LibSRUtil.sol#L84
DoS
ditto-eth (DittoETH) confirmed and commented:
hansfriese (judge) decreased severity to Medium and commented:
