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:
getMaxTranchesis not checked in some key flows where tranches can be added. These includingemitLoan(),refinancePartial()(->_addTrancheFromPartial()),refinanceFromLoanExecutionData().- Where
getMaxTranchesis checked, the check is invalid. Only_loan.tranche.length == getMaxTranchesis checked. But combined with (1), when number of tranches exceedsgetMaxTranchesin 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();
}
...
Recommended Mitigation Steps
Add missing checks on getMaxTranches for all flows that might add tranches. In addNewTranche, change into _loan.tranch.length >= getMaxTranches.
Check total tranches + min amount per tranche.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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.