# `totalCdsDepositedAmountWithOptionFees` is incorrectly reduced in `CDSLib::withdrawUser()`, leading to stuck option fees

CDSLib.withdrawUser reduces totalCdsDepositedAmountWithOptionFees by the wrong option-fee term, leaving phantom fees that underflow getOptionsFeesProportions and strand option fees.

- Payout: Audit contest
- Severity: high
- Program: Autonomint
- Found by: 0x73696d616f
- Disclosed: 2024-11-26
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/1019
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AH-33
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** CDS withdrawal accounting in CDSLib.sol
**Root cause:** withdrawUser subtracts optionsFeesToGetFromOtherChain instead of (optionFees - optionsFeesToGetFromOtherChain) from totalCdsDepositedAmountWithOptionFees, so the local chain's option-fee total diverges from reality.
**Steps:**
1. CDS depositor has depositedAmount=1000, liquidationAmount=500, optionFees=50, optionsFeesToGetFromOtherChain=0.
2. Call withdrawUser; line 731 subtracts (1000-500+0)=500 from totalCdsDepositedAmountWithOptionFees instead of (1000-500+(50-0))=550.
3. Observe totalCdsDepositedAmountWithOptionFees retains 50 phantom option fees after user withdraws them.
4. Later getOptionsFeesProportions computes totalOptionFeesInOtherChain as 1050-1100 and underflows.
**How found:** Code review of the withdrawal accounting line comparing the subtracted term against the intended option-fee delta.
**Escalation:** Phantom option-fee balance propagates into getOptionsFeesProportions, causing underflow/revert and stuck option fees across chains.
**Insight:** In cross-chain accounting, verify that each aggregate is decremented by the same delta it was incremented by; mismatched local-vs-remote fee terms silently desync totals and later underflow proportion math.

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

**Incorrect reduction line in CDSLib::withdrawUser**

```
totalCdsDepositedAmountWithOptionFees -= (params.cdsDepositDetails.depositedAmount - params.cdsDepositDetails.liquidationAmount + params.optionsFeesToGetFromOtherChain);
```

