Skip to content
DoS Audit finding Intermediate

Function Pool.validateOffer() does not work correctly in case principalAmount > currentBalance

The Pool contract's validateOffer() function incorrectly calls reallocate() with wrong parameters when the principal amount exceeds the current balance, causing the contract to deposit more funds instead of withdrawing. This can leave the contract with insufficient balance to fund the loan, resulting in a denial of service under certain conditions.

minhquanym Follow with oakcobalt and bin2chen

Originally disclosed on Code4rena

Submitted by minhquanym, also found by oakcobalt and bin2chen

In the Pool contract, undeployed funds could be deposited to Aave or Lido to earn base yield. When an offer of Pool is accepted from MultiSourceLoan, the function validateOffer() is called to validate the terms and also to pull the undeployed funds back in case the contract balance is insufficient.

if (principalAmount > undeployedAssets) {
    revert InsufficientAssetsError();
} else if (principalAmount > currentBalance) {
    IBaseInterestAllocator(getBaseInterestAllocator).reallocate(
        currentBalance, principalAmount - currentBalance, true // @audit Incorrect
    );
}

However, the input params of reallocate() are incorrect, resulting in the contract balance might still be insufficient for the loan after calling the function.

Proof of Concept

Consider the scenario:

  1. Assume we have currentBalance = 500, baseRateBalance = 1000 usdc and principalAmount = 700 usdc.
  2. Since the current contract balance is insufficient (500 < 700), reallocate() will be called with input:
reallocate(currentBalance, principalAmount - currentBalance, true)
reallocate(500, 200, true)
  1. In function reallocate() shown in the code snippet below, we can see that in case _currentIdle > _targetIdle, the contract even deposits more funds to AavePool instead of withdrawing.
function reallocate(uint256 _currentIdle, uint256 _targetIdle, bool) external {
    address pool = _onlyPool();
    if (_currentIdle > _targetIdle) {
        uint256 delta = _currentIdle - _targetIdle;
        ERC20(_usdc).transferFrom(pool, address(this), delta);
        IAaveLendingPool(_aavePool).deposit(_usdc, delta, address(this), 0);
    } else {
        uint256 delta = _targetIdle - _currentIdle;
        IAaveLendingPool(_aavePool).withdraw(_usdc, delta, address(this));
        ERC20(_usdc).transfer(pool, delta);
    }

    emit Reallocated(_currentIdle, _targetIdle);
}

Recommended Mitigation Steps

Call reallocate(0, principalAmount - currentBalance, true) instead.

0xA5DF (judge) decreased severity to Medium and commented:

If I understand correctly, the impact is DoS that occurs only under certain conditions; in that case, I think severity should be Medium.

0xend (Gondi) confirmed and commented:

Agree on the issue. I think it’s Medium, not High.

Gondi mitigated:

Changed to reallocate (currentBalance, principalAmount, true) instead of proposed solution (same result) to be compliant with the interface.

Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.


The original report as published on Code4rena, by minhquanym. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 arguments to reallocate() were swapped: the function expects the current idle balance and the target idle balance, but the code passes currentBalance as the current idle and principalAmount - currentBalance as the target, which is lower, so it deposits instead of withdraws.

Impact

The contract may still have insufficient balance to fund the loan, causing a denial of service for loan acceptance under certain conditions.

What the attacker needed

PrincipalAmount > currentBalance; undeployed funds exist in Aave or Lido

The fix

The fix was to change the reallocate call to use currentBalance and principalAmount as arguments, which was mitigated and confirmed.

How it was found

  1. Set currentBalance = 500, baseRateBalance = 1000 USDC, and principalAmount = 700 USDC.
  2. Since currentBalance < principalAmount, validateOffer() calls reallocate(500, 200, true).
  3. In reallocate(), because _currentIdle (500) > _targetIdle (200), it transfers 300 USDC from the pool and deposits it into Aave, reducing the pool balance further.
  4. The pool balance becomes 200 USDC, which is still less than the required 700 USDC, so the loan cannot be funded.

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.

This is a smart contract bug where a function that is supposed to move funds from a yield-earning pool back into the main contract does the opposite: it sends even more funds away. As a result, the contract may not have enough money to complete a loan, so the loan fails. The mistake is simply passing the wrong numbers to the reallocation function.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by minhquanym

View all

28 more disclosed reports, best first.

More from Gondi Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.