Skip to content
Business logic Audit finding Intermediate

Invalid maxTranches check can result in maxTranche cap to be exceeded

The smart contract did not enforce a maximum number of tranches in several functions that add tranches, and the existing check used equality instead of a greater-than-or-equal comparison. An attacker could exceed the intended cap, potentially causing unexpected behaviour or denial of service.

oakcobalt Follow with minhquanym and bin2chen

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by minhquanym and bin2chen

In src/lib/loans/MultiSourceLoan.sol, there’s max cap for the number of tranches in a loan as defined as getMaxTranches. This cap can be exceeded.

There are two main vulnerabilities:

  1. getMaxTranches is not checked in some key flows where tranches can be added. These including emitLoan(), refinancePartial()(-> _addTrancheFromPartial()), refinanceFromLoanExecutionData().
  2. Where getMaxTranches is checked, the check is invalid. Only _loan.tranche.length == getMaxTranches is checked. But combined with (1), when number of tranches exceeds getMaxTranches in other flows, this check is invalid.
//src/lib/loans/MultiSourceLoan.sol
    function addNewTranche(
        RenegotiationOffer calldata _renegotiationOffer,
        Loan memory _loan,
        bytes calldata _renegotiationOfferSignature
    ) external nonReentrant returns (uint256, Loan memory) {
...
          //@audit change to _loan.tranch.length >= getMaxTranches
|>        if (_loan.tranche.length == getMaxTranches) {
            revert TooManyTranchesError();
        }
...

https://github.com/code-423n4/2024-04-gondi/blob/b9863d73c08fcdd2337dc80a8b5e0917e18b036c/src/lib/loans/MultiSourceLoan.sol#L359

Recommended Mitigation Steps

Add missing checks on getMaxTranches for all flows that might add tranches. In addNewTranche, change into _loan.tranch.length >= getMaxTranches.

0xend (Gondi) confirmed

Gondi mitigated:

Check total tranches + min amount per tranche.

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


The original report as published on Code4rena, by oakcobalt. 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

Likely missing checks in functions that add tranches and an equality check instead of a greater-than-or-equal check in addNewTranche.

What the attacker needed

None

The fix

The project mitigated the issue by checking the total number of tranches against a minimum amount per tranche.

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 tranche is a portion of a loan provided by a different lender. The contract was supposed to limit how many tranches a loan can have, but some functions that add tranches did not check the limit, and the one check that existed only triggered when the count exactly equalled the maximum. This meant a loan could end up with more tranches than allowed.

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 oakcobalt

View all

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