Submitted by JCN, also found by mt030d, 0xpiken, silver_eth, grearlake, elhaj, zarkk01, trachev, ilchovski, bin2chen, VAD37, and SpicyMeatball
Size queries the underlyingBorrowToken balance of the variablePool during borrowing and lending actions in order to check available liquidity. If there is not enough available liquidity for the new borrower to withdraw the borrowed assets, the function call will revert:
Size::buyCreditMarket
Size::sellCreditMarket
CapsLibrary::validateVariablePoolHasEnoughLiquidity
However, Aave actual holds all liquidity in the AToken contracts, not the Pool contracts. Therefore, the liquidity check above will always fail when the variablePool references a live instance of an actual Aave Pool. This is due to the fact that the variablePool balance will be 0 (does not hold any liquidity), causing borrowing and lending actions to revert on line 70 in CapsLibrary.sol.
The below code snippets are taken from out of scope contracts, but are shown to further explain why the test suite did not detect this vulnerability:
SupplyLogic::executeSupply
As shown above, the actual implementation of the Aave pool will transfer supplied assets to the aTokenAddress on supplies. The Aave pool implementation will then transfer the assets from the AToken to the recipient during withdraws, since the liquidity is stored in the AToken contract:
SupplyLogic::executeWithdraw
AToken::burn
However, Size uses a PoolMock contract for their test suite, which implements logic that differs from actual Aave Pool contracts:
PoolMock.sol#L67-L78
As shown above, the PoolMock contract transfers all supplied assets to the PoolMock contract itself, not the AToken contract. This differs from how actual Aave Pools handle liquidity on live networks.
Borrow (sellCreditMarket) and lend (buyCreditMarket) operations will be bricked when Size is deployed and integrates with Aave on a live network. This report is labeled as High due to the fact that the main functionalities of this lending protocol will be unusable upon deployment.
The following PoC simply showcases the fact that the AToken does not hold the liquidity in the test suite. See here to observe that ATokens are the contracts that hold liquidity for Aave in live networks.
Modify the file below and run with forge test --mc BuyCreditLimitTest --mt test_BuyCreditLimit_buyCreditLimit_adds_loanOffer_to_orderbook:
When checking available liquidity on Aave, Size should query the underlyingBorrowToken balance of the AToken instead of the variablePool:
aviggiano (Size) confirmed and commented:
samuraii77 (warden) commented:
hansfriese (judge) decreased severity to Medium and commented:
