<!-- canonical: https://0xsimao.com/findings/autonomint-liquidation-reduce-option-fees -->

# Liquidation will reduce total cds deposited amount, leading to incorrect option fees

Crit/High · Sherlock · Hedged stablecoin · 4th December 2024

Finding H-29 of the Autonomint competition.

- Protocol: https://audits.sherlock.xyz/contests/569
- Report: /reports/autonomint
- Codebase: https://github.com/0xsimao/2024-11-autonomint/tree/0d324e04d4c0ca306e1ae4d4c65f0cb9d681751b
- Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/993

---

### Summary

`borrowLiquidation::liquidationType1()` [reduces](https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/Core_logic/borrowLiquidation.sol#L248) `omniChainData.totalCdsDepositedAmount`, so the option fees will be calculated on this reduced total cds depositors, but the normalized deposit of each borrower still amounts to their initial value, overcharging option fees.

### Root Cause

In `borrowLiquidation:248`, the `omniChainData.totalCdsDepositedAmount` is reduced, but the option fees normalized deposits are not accounted for.

### Internal pre-conditions

None.

### External pre-conditions

None.

### Attack Path

1. ETH price is 1000 USD / ETH.
2. Cds depositor deposits 1000 USDa.
3. Borrower deposits 1 ETH and borrows 800 USDa. Assume no option fees are charged.
4. Price drops to 800 USD / ETH.

At this point, the total normalized amount of the cds depositor is 1000 (1000 USda divided by 1 rate).
6. Borrower is liquidated and `omniChainData.totalCdsDepositedAmount` becomes `360` (`1000 - (800 + 20 - 180)`, where 800 is the debt, 20 is the amount to return to abond and 180 is the cds profits).
7. New borrower deposits and pays 50 USD option fees. [CDS::calculateCumulativeRate()](https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/lib/CDSLib.sol#L163) calculates `percentageChange` as `50 / 360`. The new rate becomes `1 * (1 + 50 / 360) = 1.1389`.
8. Borrower withdraws.
9. Cds depositor withdraws, getting from option fees `1000 * 1.1389 - 1000 = 138.9`, way more than it should.

### Impact

Cds depositor gets much more option fees than it should.

### PoC

See above.

### Mitigation

Adjust the cumulative rate when reducing the cds deposited amount with option fees or similar.

---

Related findings:

- [Mismatch between yield amount deposited in shares calculation and getAccountYieldBalance()](https://0xsimao.com/findings/benddao-mismatch-yield-deposited-shares): BendDAO
- [`totalEarnings` is incorrect when withdrawing after ending which will withdraw too many funds leaving the `Vault` insolvent](https://0xsimao.com/findings/saffron-lido-vaults-ending-withdraw-leaving-insolvent): Saffron Lido Vaults
- [Uniswap collect fees should skip collecting fees of one of the tokens if the amount is 0](https://0xsimao.com/findings/singularity-uniswap-fees-skip-collecting): Singularity
- [`ManagedLeveragedVault::executeWithdrawalEpoch()` incorrect ICR and DoSed withdrawals due to not accouting for fees](https://0xsimao.com/findings/beraborrow-i-withdrawal-epoch-withdrawals-fees): Beraborrow Managed Dens
