# Function settleWithBuyout() does not call LoanManager.loanLiquidation() during a buyout

Gondi's settleWithBuyout repays non-largest tranche lenders directly but skips LoanManager.loanLiquidation(), leaving Gondi Pool accounting stale and mispricing shares.

- Payout: Audit contest
- Severity: high
- Program: Gondi
- Found by: minhquanym
- Disclosed: 2024-07-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-gondi-findings/issues/49
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AH-06
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** MultiSourceLoan.settleWithBuyout / Pool.loanLiquidation accounting
**Root cause:** settleWithBuyout transfers owed principal+interest to each non-largest tranche lender directly and only calls loanLiquidated on the loan contract, never invoking the lender Pool's loanLiquidation() hook that updates queue accounting and outstanding values.
**Steps:**
1. Deploy Gondi Pool (ERC4626) as a lender tranche in a MultiSourceLoan.
2. Borrower defaults; auction settles via `settleWithBuyout()` where the largest lender buys out the loan.
3. Observe loop over `_loan.tranche` transfers owed amounts to non-largest lenders via `asset.safeTransferFrom(msg.sender, thisTranche.lender, owed)` without calling `LoanManager.loanLiquidation()`.
4. Only `IMultiSourceLoan(_auction.loanAddress).loanLiquidated(_auction.loanId, _loan)` is invoked.
5. Pool's `_loanTermination` accounting (interestEarned, fees, outstanding) never runs, so Pool state diverges from actual funds received.
**How found:** Code review of settleWithBuyout's tranche repayment loop against the LoanManager interface: noticed loanRepayment/loanLiquidation are the only hooks updating Pool accounting, and buyout path calls neither for the Pool lender.
**Exploitation:** A borrower/lender can trigger buyout settlement where the Pool tranche is repaid but its internal accounting is never updated; the Pool retains stale outstanding/queue values, allowing mispriced ERC4626 share minting/redeeming or double-counting of receivables to extract value from other depositors.
**Insight:** When a protocol has multiple settlement paths (repay, liquidate, buyout), enumerate every path that moves funds to a lender and verify each invokes the lender's accounting hook; buyout-style paths that pay lenders directly are a common place to miss the hook.

## Proof of concept (copied exactly from the original report)

**settleWithBuyout loop repaying lenders without loanLiquidation**

```
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);
```

