Function distribute() lacks access control allowing anyone to spam and disrupt the pool’s accounting
The distribute() function in the LiquidationDistributor contract lacks access control, allowing anyone to call it with malicious data. An attacker could set the loan's principal address to a random ERC20 token, causing the Pool to incorrectly account for that token as its asset token.
minhquanym Follow with zhaojie
Originally disclosed on Code4rena
Submitted by minhquanym, also found by zhaojie
The LiquidationDistributor contract manages the distribution of funds after a liquidation auction is settled. It distributes the received funds to the lenders of the loan. If the lender has implemented the LoanManager interface, it will also call loanLiquidation() on the lender’s address. The Pool, when loanLiquidation() is called, will conduct an accounting process to ensure that the received funds are fairly distributed to the depositors.
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);
}
However, the distribute() function lacks access control. Consequently, an attacker could directly call it with malicious data, leading to incorrect accounting in the Pool.
Proof of Concept
Observe how the loanLiquidation() function is called:
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
);
}
}
As shown above, the principalAddress is not passed in, meaning it will not be validated by the Pool. Therefore, an attacker can simply call the distribute() function with loan.principalAddress set to a random ERC20 token. This token will still be transferred to the Pool. However, the Pool will mistake this token as its asset token (USDC/WETH) and perform the accounting accordingly.
Recommended Mitigation Steps
Only allow Loan contracts to call the distribute() function.
Assessed type
Access Control
Added caller check to avoid anyone calling
distribute.
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 distribute() function did not verify that the caller was an authorised Loan contract, so anyone could invoke it with arbitrary parameters.
Impact
An attacker could spam the function and disrupt the Pool's accounting, potentially causing incorrect distribution of funds.
What the attacker needed
None
The fix
The issue was fixed by adding a caller check to prevent anyone from calling distribute().
How it was found
- Identify that distribute() has no caller restriction.
- Call distribute() with a crafted loan object where principalAddress is a random ERC20 token.
- The token is transferred to the Pool, which then performs accounting as if it were the Pool's asset token.
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 smart contract function that should only be callable by certain contracts was open to anyone. This let an attacker feed it fake data, making the system record the wrong token as if it were the real asset, which could mess up balances and accounting.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.