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:
- Assume we have
currentBalance = 500,baseRateBalance = 1000 usdcandprincipalAmount = 700 usdc. - Since the current contract balance is insufficient (500
<700),reallocate()will be called with input:
reallocate(currentBalance, principalAmount - currentBalance, true)
reallocate(500, 200, true)
- In function
reallocate()shown in the code snippet below, we can see that in case_currentIdle > _targetIdle, the contract even deposits more funds toAavePoolinstead 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.
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.
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
- Set currentBalance = 500, baseRateBalance = 1000 USDC, and principalAmount = 700 USDC.
- Since currentBalance < principalAmount, validateOffer() calls reallocate(500, 200, true).
- In reallocate(), because _currentIdle (500) > _targetIdle (200), it transfers 300 USDC from the pool and deposits it into Aave, reducing the pool balance further.
- 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.