Skip to content
Business logic Audit finding Intermediate

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.

yixxas Follow with Jeiwan

Originally disclosed on Sherlock

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

AssetManager.sol#L440:

Solidity
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();
    }
}

AssetManager.sol#L396:

Solidity
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).

The original report as published on Sherlock, by yixxas. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by yixxas

View all

13 more disclosed reports, best first.

More from Union Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.