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.
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
- Navigate to https://github.com/code-423n4/2021-10-union/blob/main/contracts/asset/AssetManager.sol
- 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);
}
...
}
- If this function was called with unsupported market token then
isMarketSupported(token)will result in false. Although remaining remains true. This meanspoolToken.safeTransferFrom(msg.sender, address(this), amount);will get executed and user money will be debited
if (remaining) {
poolToken.safeTransferFrom(msg.sender, address(this), amount);
}
- 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;
}
- As User is trying to withdraw unsupported market token so
isMarketSupportedfunction 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)
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
- Call the deposit function with an unsupported market token.
- The deposit function transfers the token from the user to the contract.
- Attempt to withdraw the same unsupported token using the withdraw function.
- 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.