# Partially filled Short Records created without a short order cannot be liquidated and exited

Partially filled Short Records created without an attached Short Order become unexitable and unliquidatable, and can be created below minShortErc.

- Payout: Audit contest
- Severity: high
- Program: DittoETH
- Found by: nonseodion
- Disclosed: 2024-06-25
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2024-03-dittoeth-findings/issues/133
- Library page: https://bugbountylibrary.com/r/c4%3A2024-03-dittoeth%3AH-04
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:business-logic vuln:dos vuln:liquidation

**Target:** DittoETH short record / order matching (LibOrders.sellMatchAlgo, ExitShortFacet, liquidation facets)
**Root cause:** matchIncomingSell sets SR.PartiallyFilled status before checking if remaining ercAmount*price >= minAskEth; if below minAskEth the short order is never added to the market, leaving an orphan Short Record with no shortOrderId.
**Steps:**
1. Open a limit bid with amount = target - minAskEth + 1 so the incoming short partially fills leaving < minAskEth remaining.
2. Open a limit short of the target amount; matchIncomingSell matches, sets SR.PartiallyFilled, then skips addSellOrder because ercAmount*price < minAskEth.
3. Verify getShorts() returns empty and short.status == SR.PartialFill.
4. Call exitShortWallet/exitShortErcEscrowed/exitShort with any shortOrderId -> reverts InvalidShortOrder.
5. Move price so position is liquidatable; call liquidate() -> reverts InvalidShortOrder; call liquidateSecondary() with the orphan SR -> reverts SecondaryLiquidationNoValidShorts.
6. Observe short.ercDebt < minShortErc, violating the minimum short size invariant.
**How found:** Code reading of sellMatchAlgo: noticed SR status is set to PartiallyFilled by matchIncomingSell before the minAskEth check that gates addSellOrder, then traced downstream exit/liquidation paths that require a valid shortOrderId.
**Exploitation:** Attacker crafts bid/short sizes so the short record is partially filled below minAskEth, creating an orphan SR. The position cannot be exited by the owner nor liquidated by anyone, and can be below minShortErc. Secondary liquidation only succeeds if the same shorter has another valid short order id to pass.
**Escalation:** Orphan SR can be created below minShortErc, and secondary liquidation can be bypassed by supplying another short order id belonging to the same shorter, exposing a related bug.
**Insight:** When auditing order-matching engines, check ordering of state mutations (status flags) versus the guards that decide whether the residual order is persisted; any status set before a skip/continue branch can leave orphan records that break downstream id-based lookups.

