# Size uses wrong source to query available liquidity on Aave, resulting in borrow and lend operations being bricked upon mainnet deployment

Size queried USDC balance of Aave Pool instead of AToken for liquidity, so borrow/lend always reverted on mainnet.

- Payout: Audit contest
- Severity: medium
- Program: Size
- Found by: JCN
- Disclosed: 2024-09-16
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-06-size-findings/issues/218
- Library page: https://bugbountylibrary.com/r/c4%3A2024-06-size%3AM-03
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:misconfiguration

**Target:** Aave integration liquidity check in CapsLibrary
**Root cause:** validateVariablePoolHasEnoughLiquidity reads underlyingBorrowToken.balanceOf(variablePool), but real Aave Pools hold no underlying; liquidity sits in the AToken contract, so the check sees 0 and reverts.
**Steps:**
1. Read CapsLibrary.validateVariablePoolHasEnoughLiquidity: `liquidity = underlyingBorrowToken.balanceOf(address(variablePool))`
2. Compare to Aave v3 SupplyLogic.executeSupply which transfers underlying to reserveCache.aTokenAddress, and AToken.burn which transfers from AToken
3. Note Size's PoolMock transfers underlying to itself, masking the bug in tests
4. Add assertion in test: `usdc.balanceOf(address(variablePool)) == 100e6` and `usdc.balanceOf(aToken) == 0`
5. On mainnet, variablePool balance is 0, so any buyCreditMarket/sellCreditMarket reverts NOT_ENOUGH_BORROW_ATOKEN_LIQUIDITY
**How found:** Code-reading of the liquidity check against real Aave v3 source; noticed the mock's supply/withdraw logic diverged from Aave's AToken-based custody, meaning tests never exercised real Pool balances.
**Insight:** When a protocol integrates an external lending pool, verify the mock's token custody matches the real implementation's; Aave v3 holds underlying in ATokens, not the Pool, so balance checks against the Pool address always read zero.

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

**Test asserting USDC sits in PoolMock not AToken**

```
address aToken = variablePool.getReserveData(address(usdc)).aTokenAddress;
+        assertEq(usdc.balanceOf(address(variablePool)), 100e6);
+        assertEq(usdc.balanceOf(aToken), 0);
```

**PoolMock supply/withdraw transfers underlying to pool itself**

```
function supply(address asset, uint256 amount, address onBehalfOf, uint16) external {
68:        Data memory data = datas[asset];
69:        IERC20Metadata(asset).transferFrom(msg.sender, address(this), amount); // @audit: underlying transferred from supplier to PoolMock contract
70:        data.aToken.mint(address(this), onBehalfOf, amount, data.reserveIndex);
71:    }
72:
73:    function withdraw(address asset, uint256 amount, address to) external returns (uint256) {
74:        Data memory data = datas[asset];
75:        data.aToken.burn(msg.sender, address(data.aToken), amount, data.reserveIndex); // @audit: no assets transferred from AToken
76:        IERC20Metadata(asset).safeTransfer(to, amount); // @audit: underlying transferred from PoolMock contract to supplier
```

