# Flawed if check causes inaccurate tracking of the protocol's ercDebt and collateral

Flawed && check in claimRemainingCollateral lets a shorter claim collateral early, then a dispute re-credits a deleted shortRecord, corrupting asset ercDebt/collateral accounting.

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

**Target:** DittoETH RedemptionFacet::claimRemainingCollateral / disputeRedemption
**Root cause:** The authorization check uses `&&` instead of `||`, so it only reverts when both shorter and shortId mismatch; a matching shorter with a different shortId bypasses the timeToDispute gate.
**Steps:**
1. Shorter owns multiple shortRecords; redeemer proposes redemption on shortRecord A and timeToDispute elapses.
2. Redeemer2 proposes redemption on shortRecord B; timeToDispute has NOT elapsed.
3. Shorter calls `claimRemainingCollateral(asset, redeemer, 0, shortIdB)` — passes because claimProposal.shorter == msg.sender (&& shortId mismatch is ignored).
4. ShortRecord B is deleted before its dispute window ends.
5. Disputer calls `disputeRedemption(asset, redeemer2, 0, shorter, shortIdB)` on the deleted shortRecord.
6. disputeRedemption re-adds colRedeemed/ercDebtRedeemed to the deleted shortRecord and increments Asset.dethCollateral and Asset.ercDebt.
7. Invariant sum(shortRecords) == Asset totals is broken; asset ercDebt/collateral inflated.
**How found:** Code review of the claimRemainingCollateral authorization check; noticed `&&` between two independent mismatch conditions and reasoned that a matching shorter with a different shortId passes. Traced downstream effect through disputeRedemption's re-credit loop.
**Exploitation:** Attacker (shorter) front-runs the dispute window by calling claimRemainingCollateral with a stale redeemer address and a different shortId, deleting a shortRecord early. A colluding disputer then disputes the deleted record, causing disputeRedemption to credit collateral and ercDebt to a non-existent shortRecord and to the asset totals, permanently desyncing protocol accounting.
**Escalation:** Desynced ercDebt/collateral feeds protocol-wide calculations (CR, redemption, liquidation math), enabling further accounting manipulation.
**Insight:** When an auth check ANDs two independent identity conditions (owner AND id), test each condition separately — a valid owner with a stale/foreign id often slips through. Then check whether the guarded state (deleted shortRecord) can still be mutated by a later function like dispute.

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

**Flawed && check in claimRemainingCollateral**

```
if (claimProposal.shorter != msg.sender && claimProposal.shortId != id) revert Errors.CanOnlyClaimYourShort();
```

