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

Pool.validateOffer passes wrong args to reallocate, depositing instead of withdrawing Aave funds, leaving balance insufficient and reverting the loan.

- Payout: Audit contest
- Severity: medium
- 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/63
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AM-04
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:solidity vuln:business-logic vuln:dos

**Target:** Pool contract / Aave reallocate logic
**Root cause:** validateOffer calls reallocate(currentBalance, principalAmount - currentBalance, true), so when currentIdle > targetIdle the allocator deposits more to Aave instead of withdrawing the shortfall.
**Steps:**
1. Set currentBalance=500, baseRateBalance=1000, principalAmount=700
2. principalAmount > currentBalance triggers reallocate(500, 200, true)
3. In reallocate, _currentIdle(500) > _targetIdle(200), so it transfers 300 from pool to Aave and deposits
4. Pool balance remains insufficient for the 700 loan, so the offer acceptance reverts
**How found:** Code reading of validateOffer's reallocate call and comparing argument semantics against reallocate's _currentIdle/_targetIdle branch logic.
**Insight:** When auditing allocator/rebalancer calls, verify the idle/target argument order matches the callee's branch semantics; swapped args can invert deposit vs withdraw direction.

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

**Buggy reallocate call in validateOffer**

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

**PoC reallocate call with wrong args**

```
reallocate(currentBalance, principalAmount - currentBalance, true)
reallocate(500, 200, true)
```

**reallocate implementation showing deposit instead of withdraw**

```
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);
    }
```

