Liquidation will reduce total cds deposited amount, leading to incorrect option fees
Summary
borrowLiquidation::liquidationType1() reduces 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
- ETH price is 1000 USD / ETH.
- Cds depositor deposits 1000 USDa.
- Borrower deposits 1 ETH and borrows 800 USDa. Assume no option fees are charged.
- 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).
- Borrower is liquidated and
omniChainData.totalCdsDepositedAmountbecomes360(1000 - (800 + 20 - 180), where 800 is the debt, 20 is the amount to return to abond and 180 is the cds profits). - New borrower deposits and pays 50 USD option fees. CDS::calculateCumulativeRate() calculates
percentageChangeas50 / 360. The new rate becomes1 * (1 + 50 / 360) = 1.1389. - Borrower withdraws.
- 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.