Function settleWithBuyout() does not call LoanManager.loanLiquidation() during a buyout
The settleWithBuyout function repays other lenders directly but fails to call loanLiquidation on the Gondi Pool, so the pool's accounting is not updated. This leads to incorrect internal accounting for the pool.
minhquanym Follow with bin2chen
Originally disclosed on Code4rena
Submitted by minhquanym, also found by bin2chen
Lenders in the Gondi protocol could be EOA and Gondi Pool. Gondi Pool, an ERC4626, allows anyone to deposit funds and earn yield from lending on Gondi. Gondi Pool implemented the LoanManager interfaces, which include the validateOffer(), loanRepayment(), and loanLiquidation() functions. The functions loanRepayment() and loanLiquidation() are called when a borrower repays the loan or the loan is liquidated, i.e., when the Pool receives funds back from MultiSourceLoan. Both functions is used to update the queue accounting and the outstanding values of the Pool.
ERC20 asset = ERC20(_auction.asset);
uint256 totalOwed;
// @audit Repay lender but not call LoanManager.loanLiquidation()
for (uint256 i; i < _loan.tranche.length;) {
if (i != largestTrancheIdx) {
IMultiSourceLoan.Tranche calldata thisTranche = _loan.tranche[i];
uint256 owed = thisTranche.principalAmount + thisTranche.accruedInterest
+ thisTranche.principalAmount.getInterest(thisTranche.aprBps, block.timestamp - thisTranche.startTime);
totalOwed += owed;
asset.safeTransferFrom(msg.sender, thisTranche.lender, owed);
}
unchecked {
++i;
}
}
IMultiSourceLoan(_auction.loanAddress).loanLiquidated(_auction.loanId, _loan);
In the settleWithBuyout() function, the main lender buys out the loan by repaying all other lenders directly. However, loanLiquidation() is not called, leading to incorrect accounting in the Pool.
Proof of Concept
The loanLiquidation() function handles accounting in the pool.
function loanLiquidation(
...
) external override onlyAcceptedCallers {
uint256 netApr = _netApr(_apr, _protocolFee);
uint256 interestEarned = _principalAmount.getInterest(netApr, block.timestamp - _startTime);
uint256 fees = IFeeManager(getFeeManager).processFees(_received, 0);
getCollectedFees += fees;
_loanTermination(msg.sender, _loanId, _principalAmount, netApr, interestEarned, _received - fees);
}
Recommended Mitigation Steps
Consider checking and calling loanLiquidation() in settleWithBuyout() to ensure accurate accounting in the pool.
0xend (Gondi) confirmed and commented:
Changing interest paid to use the end of the loan (this appears in another issue since this delta in time otherwise breaks the
maxSeniorRepaymentconcept).
Added
loanLiquidationcall.
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 the settleWithBuyout function omitted the call to loanLiquidation that other repayment paths make, so the pool's accounting was not updated.
Impact
The pool's accounting could become incorrect, which may affect its internal balances and yield calculations.
What the attacker needed
A loan with multiple lenders; a buyout by the main lender
The fix
The issue was fixed by adding a loanLiquidation call in settleWithBuyout.
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.
In a lending pool, when a loan is repaid or liquidated, the pool must update its records to reflect the money coming back. Here, a special buyout function skipped that update, so the pool's records became wrong.
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.