Skip to content
Business logic Audit finding Intermediate

User Fund loss in case of Unsupported Market token deposit

The deposit function accepts tokens from unsupported markets and transfers them into the contract, but the withdraw function cannot process those same tokens, so the funds become stuck. An attacker or user could deposit an unsupported token and then be unable to withdraw it, causing a loss of funds.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain

Impact

User funds can be lost as current logic cannot withdraw unsupported market token even though deposit can be done for same

Proof of Concept

  1. Navigate to https://github.com/code-423n4/2021-10-union/blob/main/contracts/asset/AssetManager.sol
  2. Check the function deposit
function deposit(address token, uint256 amount)
    external
    override
    whenNotPaused
    onlyAuth(token)
    nonReentrant
    returns (bool)
{
    ...

    bool remaining = true;
    if (isMarketSupported(token)) {
        ...
    }

    if (remaining) {
        poolToken.safeTransferFrom(msg.sender, address(this), amount);
    }

    ...
}
  1. If this function was called with unsupported market token then isMarketSupported(token) will result in false. Although remaining remains true. This means poolToken.safeTransferFrom(msg.sender, address(this), amount); will get executed and user money will be debited
if (remaining) {
    poolToken.safeTransferFrom(msg.sender, address(this), amount);
}
  1. Lets say user decides to withdraw using withdraw function
function withdraw(
    address token,
    address account,
    uint256 amount
) external override whenNotPaused nonReentrant onlyAuth(token) returns (bool) {
    ...

    if (isMarketSupported(token)) {
        ...
    }

    if (!_isUToken(msg.sender, token)) {
        balances[msg.sender][token] = balances[msg.sender][token] - amount + remaining;
        totalPrincipal[token] = totalPrincipal[token] - amount + remaining;
    }

    emit LogWithdraw(token, account, amount, remaining);

    return true;
}
  1. As User is trying to withdraw unsupported market token so isMarketSupported function will return false. This means user wont be able to withdraw the funds

Recommended Mitigation Steps

Deposit function should revert in case of non supported market tokens

kingjacob (Union) acknowledged and disagreed with severity

GalloDaSballo (judge) commented:

Agree with the adjusted severity of Medium, this is a loss of funds that can happen under specific conditions

That said, the finding is valid, a simple mitigation would be to return / stop the execution if the token is not supported (or revert if you prefer that)

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

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 deposit function does not check whether the token is supported before transferring it, while the withdraw function only handles supported tokens.

What the attacker needed

User deposits an unsupported token

The fix

The deposit function should revert or stop execution if the token is not supported.

How it was found

  1. Call the deposit function with an unsupported market token.
  2. The deposit function transfers the token from the user to the contract.
  3. Attempt to withdraw the same unsupported token using the withdraw function.
  4. The withdraw function fails to process the unsupported token, leaving the funds stuck.

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 lets people deposit tokens, but it only knows how to handle certain tokens. If someone deposits a token the contract does not support, the contract still takes the money but has no way to give it back. This means the money is stuck forever.

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 Anurag Jain

View all

63 more disclosed reports, best first.

More from Union Finance contest

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.