`userTokens` accounting in `Launch.sol::updateParticipation` is updated incorrectly and can lead to loss of user funds, DOS and a broken invariant
The `userTokens` mapping in `Launch.sol` is updated incorrectly when a user reduces their participation, subtracting the refund amount instead of the token difference. This can cause underflows in `processRefund` and cancellation, leading to locked funds and denial of service for users trying to claim refunds or cancel.
Source: https://github.com/sherlock-audit/2025-02-rova-judging/issues/312
Found by
0rpse, 0xbakeng, 0xc0ffEE, 10ap17, Boy2000, IvanFitro, John44, KlosMitSoss, Limbooo, X0sauce, ZdravkoHr., farismaulana, rokinot, zzykxx
Summary
When a user reduces their participation tokens in the launch group sale,userTokens in the _userTokensByLaunchGroup mapping is updated incorrectly which can lead to loss of user funds for any user trying to claim a refund, this vulnerability can lead to other undesireble behaviours such as users being constantly DOS'd when they try to cancel participation.
Root Cause
In Launch.sol:312 when a user reduces their stake in the participation, after the if statement block passes, the userTokens mapping value is incorrectly updated by subtracting refundCurrencyAmount from userTokenAmount which is grossly incorrect, see below:
// Update total tokens requested for user for launch group
userTokens.set(request.userId, userTokenAmount - refundCurrencyAmount);
It should be the difference between the current requested token amount and the previous token amount, i.e (userTokens.set(request.userId, userTokenAmount - (prevInfo.tokenAmount - request.tokenAmount));
This error can lead to a number of different undesirable outcomes and this report will explore the outcome of stuck funds when user tries to claim refund.
Internal Pre-conditions
- For the token on sale to have the same decimal precision as one of the accepted payment currencies, such as the ERC20 Move token.
External Pre-conditions
N/A
Vulnerability Path
Scenario: Let us assume the price of 1 token is 1.5 MOVE which also has 8 decimals and the token on sale also has 8 decimal precision.
Path 1:
- User creates a participation requesting the max amount of tokens allowed for a user, lets assume 10k tokens costing 15k MOVE.
- User tries to reduce their requested tokens by half, i.e (10000 * 10^8) -> (5000 * 10^8) Tokens, the refund is calculated coming up to 7.5k MOVE.
- The update would go like so -> (10000 * 10^8) - (7500 * 10^8) = (2500 * 10^8), which updates
userTokensincorrectly assigning the user with half the amount of tokens they are supposed to be left with in the mapping storage that tracks their total Tokens in the launch group, althoughnewInfo.tokenAmount = request.tokenAmount;would be updated correctly this creates a number of undesirable outcomes depending on what a user does next.
Path 2:
- The user decides to cancel participation for whatever reason, which then code runs into an underflow here:
} else {
// Subtract cancelled participation token amount from total tokens requested for user
userTokens.set(request.userId, userTokenAmount - info.tokenAmount);
}
The leaves the user unable to cancel the participation and get back their funded payment currency.
Impact
As users do not have much control for how the sales turn out, in a scenario where a user is issued a refund, when they try to claim their refund, processRefund() would underflow due to this part of the code in the function userTokens.set(info.userId, userTokenAmount - info.tokenAmount); as info.tokenAmount would have a higher amount stored than userTokenAmountretrieved fromuserTokens`, thus causing locked userfunds for users trying to claim refunds. This is a significant impact being caused by this error that can trickle down to other key functions in this contract such as users being DOS'd when trying to cancel participation in other instances.
PoC
See vulnerability path.
Mitigation
Use the correct value/variable which should be the difference between the previous tokenAmount and the new requested tokenAmount.
- userTokens.set(request.userId, userTokenAmount - refundCurrencyAmount);
+ uint256 tokenDelta = prevInfo.tokenAmount - request.tokenAmount;
+ (userTokens.set(request.userId, userTokenAmount - tokenDelta);
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 code subtracts the refund currency amount from the user's token amount instead of the difference between the previous and new token amounts.
Impact
Users may be unable to claim refunds or cancel participation due to underflows, resulting in locked funds and denial of service.
What the attacker needed
Token on sale has same decimals as payment currency; User reduces participation amount
The fix
The code should be fixed to subtract the difference between the previous and new token amounts from `userTokens`.
How it was found
- User creates a participation requesting the maximum allowed tokens.
- User reduces their requested tokens by half, triggering a refund.
- The contract updates `userTokens` by subtracting the refund amount from the token amount, resulting in an incorrect lower value.
- User attempts to cancel participation, causing an underflow in `userTokens.set(request.userId, userTokenAmount - info.tokenAmount)`.
- User is unable to cancel and retrieve their funds.
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 keeps track of how many tokens each user has requested. When a user lowers their request, the contract mistakenly subtracts the refund amount (in payment currency) from the token count, making the recorded token count too low. Later, when the user tries to cancel or claim a refund, the contract tries to subtract a larger number from a smaller one, which fails and locks their funds.
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.