Borrower deposit, withdraw, deposit will reinit `omniChainData.cdsPoolValue`, getting profit stuck for cds depositors
A borrower deposit after all previous borrowers have withdrawn resets the CDS pool value, discarding accumulated profits. This causes a CDS depositor's withdrawal to underflow, locking their profit and potentially their entire deposit.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/919
Found by
0x73696d616f
Summary
BorrowLib::calculateRatio() sets omniChainData.cdsPoolValue to previousData.totalCDSPool + netPLCdsPool, disregarding any past value of omniChainData.cdsPoolValue, when the noOfDeposits is null.
noOfDeposits is omniChainData.totalNoOfDepositIndices, which is increased and decrease on borrower deposit and withdraw, respectively. Hence, it's possible to make it null again while still having cds depositors and positive long contributions to omniChainData.cdsPoolValue.
Root Cause
In BorrowLib:199, omniChainData.cdsPoolValue is overwritten.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- Consider a cds depositor of 1000 USDa and a ETH price of 1000 USD / ETH.
- Borrower deposits 1 ETH and borrows 800 USDa (consider no option fees). Strike price is 1050 USD / ETH.
- Price goes up to 1050 USD / ETH.
- Consider that no interest on the debt accrued and the borrower withdraws.
omniChainData.cdsPoolValuewill increase to1000 + 1 * (1050 - 1000) = 1050. The cumulative value in cds is updated, adding1 * (1050 - 1000) / 1000 = 0.05. - Another borrower comes in, deposits 1 wei of ETH. Note that it will calculate the ratio, and
omniChainData.totalNoOfDepositIndicesis 0 now. So,previousData.cdsPoolValue = currentCDSPoolValue;is set, andcurrentCDSPoolValue = previousData.totalCDSPool + netPLCdsPool = 1000 + 0 = 1000.netPLCdsPool == 0because the price is 1050 now and has not changed. - Cds depositor withdraws (ignore 1 wei borrow, it's irrelevant), with a profit of
1000 * 0.05 = 50USD, butpreviousData.cdsPoolValueis 1000 USD, as the cds depositor tries to withdraw 1050 USD, it underflows.
Impact
Cds depositor can not withdraw 50 USDa profit (and whole deposit, until someone else deposits cds and this user steals cds from the next depositor).
PoC
See above explanation.
Mitigation
Consider track if there is pending net cds pool.
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 function calculateRatio overwrites omniChainData.cdsPoolValue without preserving the existing value when noOfDeposits is zero.
What the attacker needed
CDS depositor has deposited funds; A borrower deposits and later withdraws; Another borrower makes a tiny deposit
The fix
The code should be fixed to track pending net CDS pool value so that the pool value is not overwritten when there are no deposits.
How it was found
- A CDS depositor deposits 1000 USDa and the ETH price is 1000 USD/ETH.
- A borrower deposits 1 ETH and borrows 800 USDa with a strike price of 1050 USD/ETH.
- The ETH price rises to 1050 USD/ETH.
- The borrower withdraws, increasing omniChainData.cdsPoolValue to 1050 and updating cumulative value.
- Another borrower deposits 1 wei of ETH, which resets omniChainData.cdsPoolValue to 1000 because totalNoOfDepositIndices is 0.
- The CDS depositor tries to withdraw 1050 USDa but the transaction underflows due to the reset pool value.
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.
The CDS pool tracks how much money depositors have put in and any profit earned. When a new borrower deposits after all previous borrowers have left, the pool's value is recalculated from scratch, ignoring the profit that had built up. This means a depositor trying to withdraw their profit finds the contract thinks there isn't enough money, so the withdrawal fails.
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.