# Total cds deposited amount is incorrectly modified when cds depositor is at a loss, leading to stuck USDa

CDS withdrawal reduces totalCdsDepositedAmount by the lossy return amount instead of the deposit, corrupting cumulative accounting and stranding USDa.

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

**Target:** CDS.sol / CDSLib.sol withdrawal accounting
**Root cause:** CDSLib.sol:713 decreases totalCdsDepositedAmount by the returned amount (deposit minus loss) rather than the depositor's actual deposited amount, so the total no longer equals the sum of individual deposits.
**Steps:**
1. Two CDS depositors deposit 400 and 600 USDa at ETH price 1000.
2. Borrower deposits 1 ETH at 1000.
3. Price drops to 900.
4. 400 depositor withdraws: lossy cumulative = 1*(1000-900)/1000 = 0.1, return = 400-40 = 360; totalCdsDepositedAmount = 1000-360 = 640.
5. Remaining depositor has 600 but totals use 640; on price recovery to 1000, cumulative += 1*(1000-900)/640 = 0.15625, net 0.05625, payout 633.75, stranding 6.25 USDa.
6. If price drops to 850 and borrower withdraws, downside 150 makes totalCdsDepositedAmount underflow: 640-150-(600-600*(0.1+1*(900-850)/640)) = -3.125.
**How found:** Code review of CDSLib withdrawal logic noticing totalCdsDepositedAmount is decremented by the lossy returned amount rather than the deposited amount, then modeling cumulative-value math with concrete numbers.
**Exploitation:** Any CDS depositor withdrawing at a loss triggers the miscalculation; subsequent cumulative-value computations use the wrong denominator, causing stuck USDa, loss on withdrawal, or DoS of withdrawals depending on price path.
**Escalation:** Underflow of totalCdsDepositedAmount when borrower withdraws after a further price drop DoSes withdrawals.
**Insight:** When a protocol tracks an aggregate total alongside per-user balances, verify the aggregate is decremented by the principal, not by a loss-adjusted payout; otherwise cumulative-rate math silently diverges and can underflow.

