# `borrowing::withdraw()` at a loss will increase downside protected and misscalculate option fees

Withdrawing at a loss inflates downsideProtected, shrinking the CDS fee base so option fees are over-distributed to CDS depositors, draining USDa liquidity.

- 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/757
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AH-17
- 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:reward-distribution

**Target:** BorrowLib/CDS option-fee accounting
**Root cause:** CDS.sol:680 subtracts downsideProtected from totalCdsDepositedAmountWithOptionFees when computing the cumulative rate, but the rate is later multiplied by the full checkpointed normalized amount, over-crediting fees.
**Steps:**
1. CDS deposits 1000 USDa at ETH=1000, rate=1, normalizedAmount=1000.
2. Borrower deposits 1 ETH, borrows 800 USDa.
3. ETH drops to 900; borrower withdraws, setting downsideProtected=100.
4. New borrower pays 50 USDa fees: percentageChange = 50/(1000-100) = 50/900; currentCumulativeRate = 1 + 50/900 = 950/900.
5. CDS depositor withdraws: fees = 1000 * 950/900 - 1000 = 55.55, exceeding the 50 actually charged.
**How found:** Code reading of the fee-rate formula in CDS.sol:680 and CDSLib.sol:182, noticing downsideProtected is subtracted from the base but not from the normalized amount multiplier.
**Exploitation:** Attacker (CDS depositor) waits for a loss-driven withdrawal to inflate downsideProtected, then a borrower deposit charges fees against the reduced base, inflating lastCumulativeRate; attacker withdraws to collect more fees than paid, draining USDa from other depositors.
**Escalation:** Repeated loss events and deposits compound the over-distribution, eventually leaving insufficient liquidity for other CDS depositors to withdraw.
**Insight:** When a rate is computed on a reduced base but applied to a full checkpointed amount, the mismatch mints value; audit every place a denominator is adjusted for one variable but the numerator/multiplier is not.

