`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.
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 unstakedUToken::borrow: the user might get less than the amount the user borrowedUToken::redeem: the user might get less than the amount the user redeemedUToken::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.
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
stakedAmountwill be decreased byamount, but the staker might get less than actually unstaked amount
- the staker's
UToken::borrow: the user might get less than the amount the user borrowed- the user's
principalwill be increased by the borrowedamountandfee, but the user might get less than the askedamount
- the user's
UToken::redeem: the user might get less than the amount the user redeemed- the user's
UTokenis burned, but the user might get less than the burned amount.
- the user's
UToken::removeReserves: the admin might transfer out less than intended- the receiver might get less than what admin intended. The
totalReservesmight be reduced more than what was transferred out.
- the receiver might get less than what admin intended. The
Impact
Users might get less amount transferred from the AssetManager than they should get
Code Snippet
Tool used
Manual Review
Recommendation
Check the remaining to be transferred and return false if it is bigger than zero
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.