# Treasury will run out of liquidated funds to give to withdrawing users causing withdrawals to fail

Autonomint treasury never decrements cached liquidatedCollateralAmountInWei after withdrawals, so CDS users who opted into liquidation get reverting withdrawals once real balance is drained.

- Payout: Audit contest
- Severity: medium
- Program: Autonomint
- Found by: John44
- Disclosed: 2024-11-26
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/799
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AM-25
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** CDS/treasury withdrawal logic in CDSLib.sol
**Root cause:** liquidatedCollateralAmountInWei is only incremented in updateDepositedCollateralAmountInWei and never decremented when liquidated collateral is paid out to withdrawing users, so getLiquidatedCollateralToGive overestimates available funds.
**Steps:**
1. User opts into liquidation and later calls withdrawUser in CDSLib.
2. CDSLib.sol:687 calls getLiquidatedCollateralToGive passing treasury.liquidatedCollateralAmountInWei(ETH/WeETH/WrsETH) as available amounts.
3. getLiquidatedCollateralToGive (CDSLib.sol:324) sees cached amount >= needed and returns the full amount in that single token.
4. CDSLib.sol:825 calls treasury.transferEthToCdsLiquidators(msg.sender, params.ethAmount) (same for weETH/wrsETH).
5. Treasury's actual token balance is lower than the cached value, so the transfer reverts and the withdrawal fails.
**How found:** Code reading of the withdrawal path: noticed getLiquidatedCollateralToGive trusts liquidatedCollateralAmountInWei, then traced that the only writer, updateDepositedCollateralAmountInWei, only increases the value and no decrement exists in withdrawUser.
**Insight:** When a contract caches an 'available balance' for allocation logic, grep every writer of that storage slot; if only an increment path exists and payouts read the cache instead of balanceOf, the cache drifts and later payouts revert.

