# Borrower deposit, withdraw, deposit will reinit `omniChainData.cdsPoolValue`, getting profit stuck for cds depositors

Borrower deposit/withdraw/deposit resets omniChainData.cdsPoolValue when deposit index count hits zero, underflowing CDS withdrawals and trapping depositor profit.

- 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/919
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AH-27
- 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:business-logic

**Target:** BorrowLib.calculateRatio / CDS withdrawal accounting
**Root cause:** calculateRatio overwrites omniChainData.cdsPoolValue with previousData.totalCDSPool + netPLCdsPool when totalNoOfDepositIndices is zero, discarding accumulated CDS profit tracked in cumulativeValue.
**Steps:**
1. CDS depositor deposits 1000 USDa; ETH price 1000 USD/ETH.
2. Borrower deposits 1 ETH, borrows 800 USDa at strike 1050.
3. ETH price rises to 1050; borrower withdraws, cdsPoolValue becomes 1050 and cumulativeValue += 0.05.
4. totalNoOfDepositIndices returns to 0 after borrower withdraw.
5. New borrower deposits 1 wei ETH; calculateRatio sets cdsPoolValue = totalCDSPool + netPLCdsPool = 1000, wiping the 50 USD profit.
6. CDS depositor withdraws; CDS.sol#L395 underflows because cdsPoolValue (1000) < owed (1050).
**How found:** Code reading of BorrowLib.calculateRatio noticed cdsPoolValue is assigned rather than accumulated when noOfDeposits is null, and traced that totalNoOfDepositIndices can return to zero while CDS profit remains.
**Exploitation:** Attacker (or any borrower) cycles deposit/withdraw to zero out totalNoOfDepositIndices, then a dust deposit reinitializes cdsPoolValue, blocking CDS depositors from withdrawing accrued profit until a new CDS deposit subsidizes it.
**Insight:** When a pool value is recomputed from a 'previous' snapshot gated on a counter being zero, check whether that counter can be driven back to zero while other accumulators (cumulativeValue) still hold profit — the reset silently discards it.

