Skip to content
Business logic Audit finding Intermediate

user can drawDebt that is below dust amount

The protocol's minimum debt check only enforces the dust limit when there are fewer than 10 loans; with 10 or more loans it uses a lower average-based threshold. An attacker could create 10 accounts, each borrowing at the dust limit, so that the minimum debt becomes 10% of the dust limit, allowing further loans below the intended dust amount.

koxuan Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/70

Found by

koxuan

Summary

According to the protocol, drawDebt prevents user from drawing below the quoteDust_ amount. However, a logical error in the code can allow user to draw below dust amount.

Vulnerability Detail

_revertOnMinDebt is used in drawDebt to prevent dust loans. As you can see, the protocol wants to take the average of debt in the pool and make it the minimum if there are 10 or more loans. If it is lower than 10 loans, a quoteDust is used as the minimum. There is an edge case, whereby there are 10 loans in the pool, and the borrowers repay the loans till there is only 1 unit owed for each loan.(Might revert due to rounding error but it is describing a situation whereby repaying till a low amount of poolDebt can enable this). A new borrower can then drawDebt and because _revertOnMindebt only goes through the average loan amount check and not the quoteDust_ amount check, he/she is able to draw loan that is well below the quoteDust_ amount.

Solidity
    function _revertOnMinDebt(
        LoansState storage loans_,
        uint256 poolDebt_,
        uint256 borrowerDebt_,
        uint256 quoteDust_
    ) view {
        if (borrowerDebt_ != 0) {
            uint256 loansCount = Loans.noOfLoans(loans_);
            if (loansCount >= 10) {
                if (borrowerDebt_ < _minDebtAmount(poolDebt_, loansCount)) revert AmountLTMinDebt();
            } else {
                if (borrowerDebt_ < quoteDust_)                            revert DustAmountNotExceeded();
            }
        }
    }

Solidity
    function _minDebtAmount(
        uint256 debt_,
        uint256 loansCount_
    ) pure returns (uint256 minDebtAmount_) {
        if (loansCount_ != 0) {
            minDebtAmount_ = Maths.wdiv(Maths.wdiv(debt_, Maths.wad(loansCount_)), 10**19);
        }
    }

Impact

A minimum loan amount is used to deter dust loans, which can diminish user experience.

Code Snippet

BorrowerActions.sol#173 RevertsHelper.sol#L61-L75 PoolHelper.sol#L100-L107

Tool used

Manual Review

Recommendation

Recommend checking that loan amount is more than quoteDust_ regardless of the loan count.

Solidity
    function _revertOnMinDebt(
        LoansState storage loans_,
        uint256 poolDebt_,
        uint256 borrowerDebt_,
        uint256 quoteDust_
    ) view {
        if (borrowerDebt_ != 0) {
            uint256 loansCount = Loans.noOfLoans(loans_);
            if (loansCount >= 10) {
                if (borrowerDebt_ < _minDebtAmount(poolDebt_, loansCount)) revert AmountLTMinDebt();
            } 
            if (borrowerDebt_ < quoteDust_) revert DustAmountNotExceeded();
            
        }
    }

Discussion

EdNoepel

Edge case discussed in the fourth sentence is invalid. Repayment performs a check to ensure remaining debt is also above the minimum debt amount (or 0). As such, there is no way for _minDebtAmount to return a number smaller than the dust amount.

However, since _minDebtAmount is 10% of the average, one could game the system. Upon pool creation, the attacker creates 10 EOAs, and draws debt at the dust limit from each of them. Now the pool is in a state where the minimum debt is 10% of the dust limit.

I do not see how this would give the attacker a material advantage, but agree it should be remedied regardless.

The original report as published on Sherlock, by koxuan. 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 minimum debt check uses an either/or condition: when the loan count is 10 or more it only checks against the average-based minimum and skips the dust amount check entirely.

Impact

The minimum loan amount intended to deter dust loans can be bypassed, potentially diminishing user experience, though the reporter notes no material advantage was identified.

What the attacker needed

Ability to create multiple accounts; pool with fewer than 10 existing loans

The fix

The check should enforce that the loan amount is above the dust limit regardless of the loan count.

How it was found

  1. Create 10 externally owned accounts (EOAs).
  2. Each account draws debt at the dust limit.
  3. The pool now has 10 loans, so the minimum debt becomes 10% of the dust limit.
  4. A new borrower can then draw debt below the dust amount.

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 dust loan is a very small loan that is not worth the cost of processing. The protocol tries to stop these by setting a minimum loan size. But the check has a gap: when there are many loans, it uses a different, lower minimum, so someone can borrow less than intended.

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 koxuan

View all

7 more disclosed reports, best first.

More from Ajna #2

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.