`AssetManager.rebalance()` will revert when the balance of `tokenAddress` in the money market is 0
The rebalance function in AssetManager calls withdrawAll on every money market adapter, even when the adapter holds a zero balance of the token. Because Aave V3 rejects withdrawals of zero amount, the entire rebalance transaction reverts if any single money market has no balance.
hansfriese Follow with ctf_sec
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/75
Found by
hansfriese, ctf_sec
Summary
AssetManager.rebalance() will revert when the balance of tokenAddress in the money market is 0.
Vulnerability Detail
AssetManager.rebalance() tries to withdraw tokens from each money market for rebalancing here.
// Loop through each money market and withdraw all the tokens
for (uint256 i = 0; i < moneyMarketsLength; i++) {
IMoneyMarketAdapter moneyMarket = moneyMarkets[i];
if (!moneyMarket.supportsToken(tokenAddress)) continue;
moneyMarket.withdrawAll(tokenAddress, address(this));
supportedMoneyMarkets[supportedMoneyMarketsSize] = moneyMarket;
supportedMoneyMarketsSize++;
}
When the balance of the tokenAddress is 0, we don't need to call moneyMarket.withdrawAll() but it still tries to call.
But this will revert because Aave V3 doesn't allow to withdraw 0 amount here.
function validateWithdraw(
DataTypes.ReserveCache memory reserveCache,
uint256 amount,
uint256 userBalance
) internal pure {
require(amount != 0, Errors.INVALID_AMOUNT);
So AssetManager.rebalance() will revert if one money market has zero balance of tokenAddress.
Impact
The money markets can't be rebalanced if there is no balance in at least one market.
Code Snippet
Tool used
Manual Review
Recommendation
I think we can modify AaveV3Adapter.withdrawAll() to work only when the balance is positive.
function withdrawAll(address tokenAddress, address recipient)
external
override
onlyAssetManager
checkTokenSupported(tokenAddress)
{
address aTokenAddress = tokenToAToken[tokenAddress];
IERC20Upgradeable aToken = IERC20Upgradeable(aTokenAddress);
uint256 balance = aToken.balanceOf(address(this));
if (balance > 0) {
lendingPool.withdraw(tokenAddress, type(uint256).max, recipient);
}
}
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
The adapter calls the lending pool's withdraw function unconditionally, without checking whether the adapter actually holds a positive balance of the token.
Impact
The money markets cannot be rebalanced if there is no balance in at least one market, blocking a core fund-management operation.
What the attacker needed
At least one money market has zero balance
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.
A smart contract function that moves funds between lending pools tries to empty every pool, even pools that already hold nothing. One of those pools refuses to process an empty withdrawal, so the whole operation fails. This means the protocol cannot rebalance its funds whenever any pool happens to be empty.
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.