# Function distribute() lacks access control allowing anyone to spam and disrupt the pool's accounting

LiquidationDistributor.distribute() lacked access control, letting anyone pass a fake principal token and corrupt Pool accounting for USDC/WETH.

- 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/64
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AH-03
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:accounting-error

**Target:** LiquidationDistributor.distribute() / Pool.loanLiquidation()
**Root cause:** distribute() has no caller restriction, and _handleLoanManagerCall omits principalAddress, so the Pool never validates the token before running _loanTermination accounting.
**Steps:**
1. Call LiquidationDistributor.distribute() directly with a crafted loan struct
2. Set loan.principalAddress to an arbitrary ERC20 token instead of the pool's USDC/WETH
3. distribute() transfers the token to the Pool and calls loanLiquidation() on the lender LoanManager
4. Pool treats the received token as its asset and runs _loanTermination accounting, corrupting balances
**How found:** Code reading: noticed distribute() lacked access control and that _handleLoanManagerCall does not pass principalAddress, so the Pool cannot validate the token before accounting.
**Exploitation:** Attacker calls distribute() with a random ERC20 as principalAddress; the token is transferred to the Pool, which mistakes it for its asset token and mis-accounts the liquidation, disrupting depositor accounting.
**Insight:** When a distributor calls back into a pool, check whether the token/asset identity is passed and validated; a missing principalAddress parameter means the pool trusts whatever token the caller supplies.

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

**loanLiquidation call missing principalAddress validation**

```
function _handleLoanManagerCall(IMultiSourceLoan.Tranche calldata _tranche, uint256 _sent) private {
    if (getLoanManagerRegistry.isLoanManager(_tranche.lender)) {
        LoanManager(_tranche.lender).loanLiquidation(
            _tranche.loanId,
            _tranche.principalAmount,
            _tranche.aprBps,
            _tranche.accruedInterest,
            0,
            _sent,
            _tranche.startTime
        );
    }
}
```

**loanLiquidation accounting logic in Pool**

```
function loanLiquidation(
    uint256 _loanId,
    uint256 _principalAmount,
    uint256 _apr,
    uint256,
    uint256 _protocolFee,
    uint256 _received,
    uint256 _startTime
) 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;
    // @audit Accounting logic
    _loanTermination(msg.sender, _loanId, _principalAmount, netApr, interestEarned, _received - fees);
}
```

