`borrowing::withdraw()` at a loss will increase downside protected and misscalculate option fees
The withdraw function in the borrowing contract incorrectly increases the downside protected amount when a borrower withdraws at a loss. This inflated downside protected value is then subtracted when calculating option fees, causing CDS depositors to receive more fees than they should, effectively stealing funds from other users.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/757
Found by
0x73696d616f
Summary
borrowing::withdraw() at a loss increases the downside protected, here. Then, whenever someone deposits to borrow, option fees are added to the cumulative rate, which is calculated based on omniChainData.totalCdsDepositedAmountWithOptionFees - omniChainData.downsideProtected.
As it calculates the rate based on a decreased amount, but the rate is then multiplied by the full amount checkpointed at the cds deposit (normalized), extra option fees will be given to cds depositors.
Root Cause
In CDS.sol:680, downside protected is subtracted from totalCdsDepositedAmountWithOptionFees.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- Consider a eth price of 1000 USD / ETH.
- Cds deposits 1000 USDa.
- Borrower deposits 1 ETH and borrows 800 USDa.
- Price drops to 900 USD / ETH.
- Borrower withdraws, setting downside protected to 100.
Now, assume that the first borrower did not charge option fees, for simplicity, and the rate is 1 (ignore precision).
6. Another borrower deposits, charging 50 USD option fees given by uint128 percentageChange = _fees / netCDSPoolValue; = 50 / (1000 - 100) = 50 / 900. currentCumulativeRate = 1 + 50 / 900 = 950 / 900. Here is the downsideProtection subtracted and the percentage calculation here.
7. Cds depositor withdraws (after borrower withdraws or there is enough ratio), calculating option fees given by cdsDepositDetails.normalizedAmount * omniChainData.lastCumulativeRate) - cdsDepositDetails.depositedAmount, where cdsDepositDetails.normalizedAmount = 1000 / 1 = 1000, yielding 1000 / 1 * 950 / 900 - 1000 = 55.555, more than the 50 USD option fees.
Impact
Cds depositors gets more option fees than it should, stealing USDa from other users in the protocol, such as other cds depositors that will not be able to withdraw due to lack of liquidity.
PoC
See the calculations above.
Mitigation
The downside protection must not be taken into account when calculating the option fees.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the withdraw function increases downside protected when a borrower withdraws at a loss, and this increased value is subtracted from the total deposited amount when calculating option fees, leading to an inflated fee rate.
Impact
CDS depositors could receive more option fees than they should, stealing funds from other users and potentially causing liquidity shortages.
What the attacker needed
A CDS deposit exists; a borrower withdraws at a loss; another borrower deposits and pays option fees
The fix
The downside protection should not be subtracted when calculating option fees.
How it was found
- CDS depositor deposits 1000 USDa.
- Borrower deposits 1 ETH and borrows 800 USDa.
- ETH price drops from 1000 to 900 USD/ETH.
- Borrower withdraws, setting downside protected to 100.
- Another borrower deposits and pays 50 USD option fees, which are added to the cumulative rate calculated using the reduced net CDS pool value (1000 - 100 = 900).
- CDS depositor withdraws and receives option fees calculated with the inflated cumulative rate, getting 55.555 USD instead of 50 USD.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this DeFi protocol, users can deposit funds (CDS depositors) and borrowers can take loans. When a borrower withdraws at a loss, the system mistakenly increases a value called 'downside protected'. Later, when calculating fees owed to depositors, this inflated value is subtracted, making the fee rate appear higher than it should be. As a result, depositors get extra fees, taking money from other users.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.