Loss of User Funds in VirtualToken’s cashIn Function Due to Incorrect Amount Minting
The cashIn function in VirtualToken mints virtual tokens using msg.value instead of the amount parameter when the underlying token is an ERC20. As a result, users who deposit ERC20 tokens receive zero virtual tokens and lose their deposited funds.
aldarion Follow with 056Security, 0xaudron and 48 others
Originally disclosed on Code4rena
Submitted by aldarion, also found by 056Security, 0xaudron, 0xbrett8571, 0xGondar, 0xgremlincat, 0xiehnnkta, 0xiehnnkta, 0xKann, 0xLasadie, 0xleadwizard, 0xLeveler, 0xMitev, 0xMosh, 4B, 4rdiii, Agontuk, Akay, anonymousjoe, ast3ros, aster, aua_oo7, Bauchibred, BenRai, BenRai, Bryan_Conquer, bumbleb33, c0pp3rscr3w3r, chaduke, Coldless, Coldless, CrazyMoose, crmx_lom, dd0x7e8, dhank, DharkArtz, dic0de, EchoKly, eLSeR17, EPSec, ETHworker, Evo, FalseGenius, farismaulana, favelanky, Fitro, Fon, franfran20, gkrastenov, Gosho, harry_cryptodev, honey-k12, hyuunn, icy_petal, Infect3d, inh3l, IzuMan, jaraxxus, jesusrod15, Jiri123, jkk812812, John_Femi, jrstrunk, jyjh, KiteWeb3, KKaminsk, komorebi, KupiaSec, lanyi2023, Le_Rems, Le_Rems, LeFy, LordAdhaar, m4k2, m4k2, macart224, Matin, mgf15, montecristo, Moyinmaala, MrPotatoMagic, mrudenko, newspacexyz, NexusAudits, OpaBatyo, Oxsadeeq, parishill24, pfapostol, pontifex, prapandey031, Prosperity, PumpkingWok, rare_one, Rhaydden, rilwan99, Robinx33, rouhsamad, rspadi, saikumar279, Shubham, silver_eth, Silverwind, slowbugmayor, SpicyMeatball, Stingo, stuart_the_minion, Summer, TenderBeastJr, threadmodeling, tpiliposian, tusharr1411, Tychai0s, typicalHuman, udo, Vagabond, Vasquez, viking71, vladi319, web3km, willycode20, X0sauce, xiao, YoanYJD, zaevlad, zaevlad, ZhengZuo999, zxriptor, and zzebra83
In the VirtualToken contract cashIn() function uses msg.value instead of amount for minting tokens when dealing with ERC20 tokens. This causes users to lose their deposited ERC20 tokens as they receive 0 virtual tokens in return.
Proof of Concept
The root cause is the incorrect usage of msg.value in the minting logic. While the function correctly handles the token transfer with the amount parameter, it incorrectly uses msg.value for minting, which is probably 0 for ERC20 token transactions. They receive 0 virtual tokens in return (since msg.value is 0 for ERC20 transactions)
function cashIn(uint256 amount) external payable onlyWhiteListed {
if (underlyingToken == LaunchPadUtils.NATIVE_TOKEN) {
require(msg.value == amount, "Invalid ETH amount");
} else {
_transferAssetFromUser(amount);
}
// @audit Critical: Using msg.value instead of amount
_mint(msg.sender, msg.value); // Will be 0 for ERC20 tokens
emit CashIn(msg.sender, msg.value);
}
Recommended mitigation steps
function cashIn(uint256 amount) external payable onlyWhiteListed {
if (underlyingToken == LaunchPadUtils.NATIVE_TOKEN) {
require(msg.value == amount, "Invalid ETH amount");
} else {
_transferAssetFromUser(amount);
}
_mint(msg.sender, amount); // Use amount instead of msg.value
}
Shaneson (Lambo.win) confirmed and commented:
VirtualToken should support USDT, USDC in the future, so cashIn should use amount instead of msg.value. This is the fixed PR, please review.
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 minting logic uses msg.value instead of the amount parameter, which is zero for ERC20 token transactions.
Impact
Users who deposit ERC20 tokens lose their tokens and receive zero virtual tokens in return.
What the attacker needed
Whitelisted user; ERC20 underlying token
The fix
The function was fixed to mint using the amount parameter instead of msg.value.
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 a function that accepts both ETH and ERC20 tokens mistakenly uses the ETH amount (msg.value) to decide how many new tokens to create. For ERC20 deposits, msg.value is always zero, so the user gets nothing back even though their tokens were taken. The fix is to use the amount parameter instead.
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.