Skip to content
Business logic Audit finding Intermediate

`Treasury.noOfBorrowers` can be set to 0 by looping wei deposit<->withdrawals and DoS withdrawals and reset borrower debt

The Treasury contract increments its borrower counter only on a user's first deposit but decrements it whenever a user's deposited amount reaches zero, so a user who redeposits and withdraws repeatedly can drive the counter to zero. This causes withdrawals to underflow and revert and resets borrower debt to zero, denying withdrawals and wiping accrued debt.

0x23r0 Follow with 0x73696d616f, 0xbakeng and 5 others

Originally disclosed on Sherlock

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

Found by

0x23r0, 0x73696d616f, 0xbakeng, newspacexyz, pashap9990, santiellena, t.aksoy, volodya

Summary

Treasury.noOfBorrowers is increased when a user deposits for the first time, as the index is 0. Then, it is decreased when borrowing[borrower].depositedAmountInETH becomes 0, which happens when the last deposit of the user is withdrawn. The issue with this approach is that when the same user redeposits, noOfBorrowers will not be increased, as borrowing[user].hasDeposited is true, but when this same user withdraws, it is decreased. Thus, it's possible to reduce Treasury.noOfBorrowers to 0, regardless of the actual number of deposits.

Root Cause

In the Treasury, the number of borrowers is increased and decreased in different ways, leading to incorrect behaviour as explained above.

Internal pre-conditions

None.

External pre-conditions

None.

Attack Path

  1. Protocol is working correctly with some cds deposits and borrow deposits.
  2. Malicious user loops deposits and withdrawals of very small amounts to reduce treasury.noOfBorrowers to 0.
  3. Two things will happen: 1) users can not withdraw their borrow deposits, as treasury.noOfBorrowers underflows when they try and 2) the debt will be reset to 0 even though there are deposits that have accrued debt.

Impact

DoSed withdrawals and debt reset for all borrowers, taking the protocol the loss and users are DoSed.

PoC

None.

Mitigation

Increase and decrease the number of borrowers symmetrically.

The original report as published on Sherlock, by 0x23r0. 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

The borrower counter is incremented only on a user's first deposit (guarded by a hasDeposited flag) but decremented on every withdrawal that empties the user's deposited amount, so the two operations are not symmetric.

Impact

Withdrawals for all borrowers are denied of service and accrued debt is reset to zero, causing loss to the protocol and blocking users.

What the attacker needed

Ability to deposit and withdraw repeatedly; small deposit amounts

The fix

The number of borrowers should be increased and decreased symmetrically so the counter reflects actual borrowers.

How it was found

  1. Have the protocol running with some deposits and borrow deposits.
  2. Loop deposits and withdrawals of very small amounts to reduce the borrower counter to zero.
  3. Observe that withdrawals underflow and revert, and debt is reset to zero.

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.

A contract keeps a running count of how many people have borrowed. It adds one when someone deposits for the first time, but subtracts one every time someone withdraws everything. If a person deposits and withdraws tiny amounts over and over, the count can drop to zero even though real borrowers exist. Later withdrawals then fail because the count cannot go below zero, and some debt records get wiped.

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 0x23r0

View all

23 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.