Skip to content
Business logic Audit finding Intermediate

`AssetManager::withdraw` will not return false, when fail to send the withdraw amount

The AssetManager::withdraw function returns true even when it could not transfer the full requested amount, leaving a non-zero remainder. Callers such as UserManager and UToken trust the true result and update their accounting as if the full amount had been paid out, so users may receive less than they unstaked, borrowed or redeemed.

Ch_301 Follow with ctf_sec, cccz and 2 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-union-finance-judging/issues/27

Found by

Ch_301, ctf_sec, cccz, yixxas, lemonmon

Summary

When UserManager or UToken calls on AssetManager::withdraw, the given amount should be transferred to account, either from AssetManager itself or by moneyMarkets. However, when there is not enough asset to be transferred from AssetManager itself or from moneyMarkets, it returns true, without reverting.

Since other contracts, who is using the AssetManager::withdraw, assumes that the amount is transferred, it causes problems such as:

  • UserManager::unstake: the user might get less than the amount the user unstaked
  • UToken::borrow: the user might get less than the amount the user borrowed
  • UToken::redeem: the user might get less than the amount the user redeemed
  • UToken::removeReserves: the admin might transfer out less than intended
  • In some cases above will also result in accounting error

Vulnerability Detail

The AssetManager::withdraw function will transfer the given amount from AssetManager itself or from moneyMarket, since the values are distributed. The function keeps track of the remaining values to be transferred in remaining local variable. However, the function returns true even if there are some non zero remaining left to transfer.

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/asset/AssetManager.sol#L328-L370

Other contracts who can call the function AssetManager::withdraw are UserManager and UToken. They assume that if the return from AssetManager::withdraw is true, the whole amount is transferred to the recipient, and update accounting accordingly. As the result, it will cause some cases that less amount is transferred out, yet the transaction does not fail.

The functions who uses AssetManager::withdraw are following:

  • UserManager::unstake
    • the staker's stakedAmount will be decreased by amount, but the staker might get less than actually unstaked amount
  • UToken::borrow: the user might get less than the amount the user borrowed
    • the user's principal will be increased by the borrowed amount and fee, but the user might get less than the asked amount
  • UToken::redeem: the user might get less than the amount the user redeemed
    • the user's UToken is burned, but the user might get less than the burned amount.
  • UToken::removeReserves: the admin might transfer out less than intended
    • the receiver might get less than what admin intended. The totalReserves might be reduced more than what was transferred out.

Impact

Users might get less amount transferred from the AssetManager than they should get

Code Snippet

https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/asset/AssetManager.sol#L328-L370

Tool used

Manual Review

Recommendation

Check the remaining to be transferred and return false if it is bigger than zero

The original report as published on Sherlock, by Ch_301. 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 withdraw function tracks the untransferred remainder in a local variable but never checks it before returning true, so partial failures are reported as full success.

Impact

Users could receive less than the amount they unstaked, borrowed or redeemed, and the protocol's internal accounting may drift from the real token balances.

What the attacker needed

Insufficient liquidity in AssetManager or money markets

The fix

The function should check the remaining amount and return false when it is greater than zero, so callers do not treat a partial transfer as complete.

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 is supposed to move a certain amount of tokens to a user and report whether it worked. Here it reports success even when part of the money could not be moved, so the calling contract records the full payout while the user actually gets less. This is a logic mistake in how the success signal is used, not a break-in.

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 Ch_301

View all

39 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.