Skip to content

Latest commit

 

History

History
79 lines (39 loc) · 4.61 KB

056.md

File metadata and controls

79 lines (39 loc) · 4.61 KB

Shambolic Pink Jay

Medium

Wrong Accounting in updateParticipation will wrongly update users token amount

Summary

Currency token is used to add to, or subtract from, the users token amount. userTokens stores the amount of requested tokens that the user has, but instead of updating with the new amount of tokens after the update, it uses the currencyAmount (not the token amount) to add / subtract from that balance, causing wrong accounting.

Root Cause

In updateParticipation a user can increase or reduce the amount of requested tokens they will have. The price difference of these tokens is calculated by comparing the new amount of tokens to the previous amount of tokens -> and their respective value in currency. The difference in currency is then transferred to the user or transferred from the user .

It is important to note that these are 2 different tokens, and the amount of tokens does not equal the amount of currency, as the amount of currency is the price of the tokens.

The price difference between the new amount of tokens from the previous amount of tokens happens here: The same method is used for whether a user increasing and decreasing their token amount.

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L345-L353

The problem exists here where the userTokens -> which is strictly used for token amounts and not currency amounts, is updated with the price difference of the token amounts, instead of being updated with the new token amount.

** for decreasing token amount **

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L360-L361

** for addition token amount **

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L373-L374

This leads to an accounting error, because the amount used for the update is the currency price difference of the token amounts. So essentially, userTokens -> which is supposed to represent the amount of requested tokens for a user will have the price difference of the token amounts (in currency) added or subtracted from their previous token amount. This can be drastically different from what it should be, which is their new token amount.

The function then populates the users new ParticipationRequest struct with their new token amount, a very different value that will be stored in userTokens.

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L384C1-L384C51

Internal Pre-conditions

None.

External Pre-conditions

None.

Attack Path

None, this is a flaw which leads to innaccurate accounting.

Impact

Unexpected actions and functionality can result from this, as the internal accounting for a user will be wrong and depending on the price of tokens, can be drastically wrong, leading to unintended functionality for the protocol and user.

PoC

To illustrate how userTokens is only used for storing the token amount and never any amounts in currency, i will show where the valeu is updated and used in several different functions, and its reliance on that amount strictly representing the requested token amount.

  1. In participate - userToken amount is retrieved, and the amount of tokens the user is requesting is added to the variable - not the currency amount.

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L243-L244 https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L251-L252 https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L292-L293

  1. In cancelParticipation - userToken amount is retrieved and then the amount of tokens in the cancellation is subtracted from that value, not the currency amount of the cancelled tokens.

https://github.com/sherlock-audit/2025-02-rova/blob/main/rova-contracts/src/Launch.sol#L434-L447

The price difference of the tokens is not used in cancelParticipation for the updating of userTokens - only the token amount to be removed is used. This maintains userTokens only representing the actual token amount for a user.

The currency price difference should never be used for userTokens, it relies on ONLY representing the token amount.

Mitigation

The method used in cancelParticipation to update userTokens should be followed and used and maintain consistency in the accounting throughout the protocol.

  1. Calculate the difference of token amounts and then depending on whether the user is updating to increase their token amount or decrease their token amount, add or subtract the difference to their current token value in userTokens