Skip to content
Business logic Audit finding Advanced

Borrower withdrawing at a loss will cause losses for cds depositors that only withdraw after the price recovers

A CDS depositor can withdraw their full deposit after a price drop and recovery, leaving later depositors unable to withdraw because the shared accounting variable underflows. The attacker gains at the expense of other users.

0x73696d616f Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/734

Found by

0x73696d616f

Summary

Borrowers withdrawing at a loss get downside protection from cds depositors. If these cds depositors withdraw at the same price as the borrower withdrawal that triggered the loss, it works correctly. However, if they do not withdraw, but wait for the price to come back up, they will get their full cds amount back at the expense of other users in the protocol, such as cds depositors that deposit after the price recovers.

Root Cause

In BorrowLib.sol:874, the downside protection is increased. In CDS.sol:328, the downside protection loss is realized. In CDS.sol:343, the return amount will be calculated after the price goes down and then up, returning the full amount to the cds depositor.

Internal pre-conditions

None.

External pre-conditions

None.

Attack Path

  1. Cds depositor deposits 1000 usda.
  2. Borrower borrows 800 usda for a deposit of 1 ETH at a price of 1000 USD / ETH.
  3. Price drops to 900 USD / ETH.
  4. Borrower withdraws, adding to the cumulative value a loss of 1 * (1000 - 900) / 1000 = 0.1, where 1000 - 900 is the price diff, 1 is the vault balance (1 ETH deposited to borrow) and 1000 in the denominator is the cds deposit made. It also adds 100 downside protected.
  5. New borrower deposits 1 ETH at a price of 900 USD / ETH.
  6. Price comes back up to 1000 USD / ETH
  7. CDS depositor deposits 1000 USDa, which triggers the increase of the cumulative value gain by 1 * (1000 - 900) / 1000 = 0.1, effectively bringing the cumulative value to 0 (it was -0.1. before). Note that it divides by 1000 and not 900, as the downside protection is applied later. The cds deposited amount becomes 1000 + 1000 - 100 = 1900, where the first 1000 is from the first cds depositor, 1000 from this cds deposit and 100 reduced from the downside protection.
  8. First cds depositor withdraws their 1000 USDa, at a cumulative value of 0 both now and at the time of the deposit as it went down and up, bringing the cds deposited amount to 900.
  9. Second cds depositor can not withdraw 1000 cds, because the cds deposited variable is only 900, underflowing by 100. This happens even though the price is exactly the same for the second depositor and no lossy withdrawal happened in the meantime.

Impact

Second cds depositor is not able to withdraw their cds deposit as the first cds depositor took 900 USDa even though it contributed to the downside protection, not the second one. This will also happen on a larger scale in case more borrows / depositors participate, the presented scenario was just an example.

PoC

POC described in the attack path section.

Mitigation

There are a few options:

  1. Consider enforcing the loss on the first cds depositor as the downside protection was applied when it was in the protocol.
  2. Or, increase the cds deposited amount variable when the price comes back up, even if it was down before.

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 cumulative value is not updated correctly when the price recovers, so a depositor who withdraws after recovery receives their full amount even though they should bear the loss, causing the cds deposited variable to underflow for later depositors.

Impact

The second CDS depositor cannot withdraw their full deposit, losing 100 USDA, and this can happen on a larger scale with more participants.

What the attacker needed

CDS depositor deposits before price drop; Borrower withdraws after price drop; Price recovers; New CDS depositor deposits after recovery

The fix

The protocol should enforce the loss on the first CDS depositor or increase the cds deposited amount when the price recovers.

How it was found

  1. CDS depositor deposits 1000 USDA.
  2. Borrower borrows 800 USDA against 1 ETH at 1000 USD/ETH.
  3. Price drops to 900 USD/ETH.
  4. Borrower withdraws, recording a loss and adding downside protection.
  5. New borrower deposits 1 ETH at 900 USD/ETH.
  6. Price recovers to 1000 USD/ETH.

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 protocol, borrowers are protected from price drops by a pool of depositors. When a borrower withdraws after a price drop, the loss is recorded in a shared value. If the price later recovers, a depositor who withdraws then gets their full amount back, but the shared value is not adjusted correctly, so later depositors cannot withdraw their full deposit.

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.