# triggerFee is stolen from other auctions during settleWithBuyout()

settleWithBuyout pays triggerFee from contract balance instead of the buyer, draining funds reserved for other parallel auctions and blocking their settlement.

- 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/50
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AH-05
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Auction settlement contract, settleWithBuyout()
**Root cause:** settleWithBuyout() transfers triggerFee to the originator via safeTransfer from the contract's own balance, but the buyer never transfers that fee in, so the fee is paid out of funds belonging to other auctions.
**Steps:**
1. Start multiple auctions in parallel so the contract holds balances for each.
2. Call `settleWithBuyout()` on one auction as the main lender; it repays other lenders and then executes `asset.safeTransfer(_auction.originator, totalOwed.mulDivDown(_auction.triggerFee, _BPS))` from contract balance.
3. Observe the triggerFee is deducted from pooled contract funds rather than from the caller.
4. Later auctions find insufficient balance and revert on settlement, or the caller's buyout reverts if balance is too low.
**How found:** Code reading of settleWithBuyout(): noticed only two transfers occur and no transferFrom of triggerFee from the sender, so the safeTransfer must draw from contract balance.
**Exploitation:** A main lender settles a buyout without funding the triggerFee; the fee is silently taken from the shared contract balance, reducing principal backing other concurrent auctions until they can no longer settle.
**Escalation:** With many parallel auctions, repeated buyout settlements drain the shared balance, causing the last auctions to revert and locking principal.
**Insight:** In settlement functions that pay fees to third parties, verify each outgoing transfer is matched by an incoming transfer from the payer; pooled contract balances let one auction's fee silently consume another's principal.

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

**settleWithBuyout pays triggerFee from contract balance**

```
function settleWithBuyout(
    ...
) external nonReentrant {
    ...
    // @note Repay other lenders
    ERC20 asset = ERC20(_auction.asset); 
    uint256 totalOwed;
    for (uint256 i; i < _loan.tranche.length;) {
        ...
    }
    IMultiSourceLoan(_auction.loanAddress).loanLiquidated(_auction.loanId, _loan);
    
    // @audit There is no fund in this contract to pay triggerFee
    asset.safeTransfer(_auction.originator, totalOwed.mulDivDown(_auction.triggerFee, _BPS));
```

