Skip to content
Business logic Audit finding Advanced

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.

0x73696d616f Follow

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

  1. Consider a cds depositor of 1000 USDa and a ETH price of 1000 USD / ETH.
  2. Borrower deposits 1 ETH and borrows 800 USDa (consider no option fees). Strike price is 1050 USD / ETH.
  3. Price goes up to 1050 USD / ETH.
  4. Consider that no interest on the debt accrued and the borrower withdraws. omniChainData.cdsPoolValue will increase to 1000 + 1 * (1050 - 1000) = 1050. The cumulative value in cds is updated, adding 1 * (1050 - 1000) / 1000 = 0.05.
  5. Another borrower comes in, deposits 1 wei of ETH. Note that it will calculate the ratio, and omniChainData.totalNoOfDepositIndices is 0 now. So, previousData.cdsPoolValue = currentCDSPoolValue; is set, and currentCDSPoolValue = previousData.totalCDSPool + netPLCdsPool = 1000 + 0 = 1000. netPLCdsPool == 0 because the price is 1050 now and has not changed.
  6. Cds depositor withdraws (ignore 1 wei borrow, it's irrelevant), with a profit of 1000 * 0.05 = 50 USD, but previousData.cdsPoolValue is 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.

The original report as published on Sherlock, by 0x73696d616f. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. A CDS depositor deposits 1000 USDa and the ETH price is 1000 USD/ETH.
  2. A borrower deposits 1 ETH and borrows 800 USDa with a strike price of 1050 USD/ETH.
  3. The ETH price rises to 1050 USD/ETH.
  4. The borrower withdraws, increasing omniChainData.cdsPoolValue to 1050 and updating cumulative value.
  5. Another borrower deposits 1 wei of ETH, which resets omniChainData.cdsPoolValue to 1000 because totalNoOfDepositIndices is 0.
  6. 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.

More by 0x73696d616f

View all

172 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.