Removed adapter can still hold funds, removed token can still be deposited to a market
The contract's removeAdapter and removeToken functions do not check whether the adapter or token still holds funds. An attacker could cause funds to be locked or removed from total TVL by triggering removal of an adapter or token that still holds assets.
Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/126
Found by
yixxas, Jeiwan
Summary
Removed adapter can still hold funds, removed token can still be deposited to a market.
Vulnerability Detail
When removing an adapter, there's no check for whether it's still holding funds (AssetManager.sol#L440). The same is true for tokens: when removing a token, there's no check for whether any of the supported adapters is still holding assets in this token.
Impact
In case an adapter that's being removed still holds funds, these funds will be removed from the total TVL until the removed adapter is re-added. And if there's no plans to re-add the adapter, the remaining funds will be locked in the adapter indefinitely. Similarly to tokens: if any of the supported markets is still holding a token that's being removed, the token assets held by the market will be removed from the total TVL and users won't be able to get their funds.
Code Snippet
function removeAdapter(address adapterAddress) external override onlyAdmin {
bool isExist = false;
uint256 index;
uint256 moneyMarketsLength = moneyMarkets.length;
for (uint256 i = 0; i < moneyMarketsLength; i++) {
if (adapterAddress == address(moneyMarkets[i])) {
isExist = true;
index = i;
break;
}
}
if (isExist) {
moneyMarkets[index] = moneyMarkets[moneyMarketsLength - 1];
moneyMarkets.pop();
}
}
function removeToken(address tokenAddress) external override onlyAdmin {
bool isExist = false;
uint256 index;
uint256 supportedTokensLength = supportedTokensList.length;
for (uint256 i = 0; i < supportedTokensLength; i++) {
if (tokenAddress == address(supportedTokensList[i])) {
isExist = true;
index = i;
break;
}
}
if (isExist) {
supportedTokensList[index] = supportedTokensList[supportedTokensLength - 1];
supportedTokensList.pop();
supportedMarkets[tokenAddress] = false;
}
}
Tool used
Manual Review
Recommendation
In the removeAdapter function, check market's supply by calling moneyMarket.getSupply(token) before removing an adapter. In the removeToken function, iterate over all supported adapters and check if they're still holding the token by calling moneyMarket.getSupply(token).
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 removal functions lack a check for remaining balances in the adapter or token before deletion.
Impact
Funds held by a removed adapter or token could be locked indefinitely or removed from total TVL, preventing users from accessing their funds.
What the attacker needed
Admin calls removeAdapter or removeToken; adapter or token still holds funds
The fix
The removeAdapter function should check the market's supply before removal, and removeToken should iterate over all supported adapters to check if they still hold the token.
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 an admin function can remove an adapter or token without first checking if it still holds money. If removed while holding funds, those funds become stuck or disappear from the total value calculation, so users may not be able to get their money back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.