Skip to content
Business logic Audit finding Advanced

distribute() when can’t repay all lenders, may lack of notification to LoanManager for accounting

The distribute function stops iterating over tranches once proceeds reach zero, so a later LoanManager lender is not notified via loanLiquidation. This can cause accounting inaccuracies in totalAssets and allow interest to keep accruing on debt that should be shared among current users.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

The LiquidationDistributor is used to distribute funds after an auction. When the auction amount is insufficient, lenders are repaid in sequence.

    function distribute(uint256 _proceeds, IMultiSourceLoan.Loan calldata _loan) external {
...
        if (_proceeds > totalPrincipalAndPaidInterestOwed + totalPendingInterestOwed) {
            for (uint256 i = 0; i < _loan.tranche.length;) {
                IMultiSourceLoan.Tranche calldata thisTranche = _loan.tranche[i];
                _handleTrancheExcess(
                    _loan.principalAddress,
                    thisTranche,
                    msg.sender,
                    _proceeds,
                    totalPrincipalAndPaidInterestOwed + totalPendingInterestOwed
                );
                unchecked {
                    ++i;
                }
            }
        } else {
@>          for (uint256 i = 0; i < _loan.tranche.length && _proceeds > 0;) {
                IMultiSourceLoan.Tranche calldata thisTranche = _loan.tranche[i];
                _proceeds = _handleTrancheInsufficient(
                    _loan.principalAddress, thisTranche, msg.sender, _proceeds, owedPerTranche[i]
                );
                unchecked {
                    ++i;
                }
            }
        }
    }

The code snippet above introduces a condition _proceeds > 0 to terminate the loop when there’s no remaining balance in _proceeds, thereby preventing further execution of _handleTrancheInsufficient().

However, this approach creates an issue. If the subsequent lender is a LoanManager, it won’t be notified for accounting via _handleTrancheInsufficient() -> _handleLoanManagerCall() -> LoanManager(_tranche.lender).loanLiquidation().

Although no funds can be repaid, accounting is still necessary to notice and prevent incorrect accounting, causing inaccuracies in totalAssets() and continued accumulation of interest. This outstanding debt should be shared among current users and prevent it from persisting as bad debt.

Impact

Failure to notify LoanManager.loanLiquidation() may result in accounting inaccuracies.

Recommended Mitigation

    function distribute(uint256 _proceeds, IMultiSourceLoan.Loan calldata _loan) external {
...
        } else {
-           for (uint256 i = 0; i < _loan.tranche.length && _proceeds > 0;) {
+           for (uint256 i = 0; i < _loan.tranche.length;) {
                IMultiSourceLoan.Tranche calldata thisTranche = _loan.tranche[i];
                _proceeds = _handleTrancheInsufficient(
                    _loan.principalAddress, thisTranche, msg.sender, _proceeds, owedPerTranche[i]
                );
                unchecked {
                    ++i;
                }
            }
        }
    }

Assessed type

Context

0xend (Gondi) confirmed

Gondi mitigated:

Always call loanManager (even if 0 proceeds).

Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.


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

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 loop condition `_proceeds > 0` exits before calling `_handleTrancheInsufficient` for remaining tranches, so the LoanManager notification is skipped when proceeds are exhausted.

Impact

Accounting in LoanManager may become inaccurate, with totalAssets overstated and interest continuing to accrue on debt that should be shared among current users.

What the attacker needed

Auction proceeds insufficient to repay all lenders; a later tranche lender is a LoanManager

The fix

The loop should iterate over all tranches regardless of remaining proceeds, so the LoanManager is always notified; the project mitigated by always calling loanManager even with zero proceeds.

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.

When a loan is liquidated, money from the auction is split among lenders in order. If the money runs out, the code stops early and never tells a later lender (a LoanManager) that its loan was liquidated. That lender's records then stay wrong, showing assets it no longer has and charging interest that should have stopped.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Gondi Invitational

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.