# Borrower withdrawing at a loss will cause losses for cds depositors that only withdraw after the price recovers

CDS depositor who waits for price recovery withdraws full amount, causing later depositor's withdrawal to underflow due to misaccounted downside protection.

- 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/734
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AH-11
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:high technique:source-review vuln:accounting-error vuln:business-logic

**Target:** CDS deposit/withdraw and borrower withdrawal logic in BorrowLib and CDS contracts
**Root cause:** Downside protection loss is realized only when a CDS depositor withdraws, but the cumulative value is updated on new deposits and borrower withdrawals without properly adjusting the cds deposited amount, allowing earlier depositors to withdraw unaffected while later depositors bear the loss.
**Steps:**
1. CDS depositor A deposits 1000 USDA.
2. Borrower B borrows 800 USDA against 1 ETH at price 1000 USD/ETH.
3. Price drops to 900 USD/ETH.
4. B withdraws, adding loss 0.1 to cumulative value and 100 to downside protected.
5. New borrower C deposits 1 ETH at 900 USD/ETH.
6. Price returns to 1000 USD/ETH.
7. CDS depositor D deposits 1000 USDA, increasing cumulative value gain by 0.1 (bringing cumulative value to 0) and cds deposited to 1900 (1000+1000-100).
8. A withdraws 1000 USDA at cumulative value 0, reducing cds deposited to 900.
9. D cannot withdraw 1000 USDA because cds deposited is only 900, causing underflow.
**How found:** Analyzed the interaction between borrower withdrawal loss accounting and CDS deposit/withdraw cumulative value updates, identifying that the cds deposited variable is not adjusted when price recovers, leading to underflow for later depositors.
**Exploitation:** A CDS depositor times withdrawal after price recovery to avoid bearing downside protection loss, leaving insufficient funds for later depositors who deposited at the same price.
**Escalation:** Loss scales with more borrowers and depositors participating in similar sequences.
**Insight:** In protocols with shared downside protection, check whether loss realization is deferred and whether accounting variables (like cds deposited) are updated on price recovery to prevent earlier withdrawers from escaping losses at the expense of later depositors.

