Open hats-bug-reporter[bot] opened 3 weeks ago
There is not concept of a "unit" in the contract, they operator on the native representation of the tokens. Merely sayign that this is "incorrect" is not really a helpful description of the issue.
Can you provide a sceneario or PoC where a depositor recieves an "unexpected aount of lp tokens" as described in the title?
Github username: -- Twitter username: -- Submission hash (on-chain): 0x3461aba3368837af526e8e7b19af55f42b038c0ac523dfc34d5bf7072fe17865 Severity: medium
Description: Description\ the
calc_token_amount()
function in StableSwapTwoPool.sol contract Calculates addition or reduction in token supply from a deposit or withdrawal and it returns the expected amount of LP tokens received.but here the function did not consider for the decimals of tokens(like lets say coin 1 with 18 decimals and token 2 with 6 decimals)here this function directly adds or sub the amount without considering for precision.i.e this function does not explicitly handle precision differences between tokens with varying decimals places.Attack Scenario\
lets understand the issue with example below
Attachments
Scenario
Initial State
Balances:
Token B: 2,000 units (which is 2,000 * 10^6 in actual token units)
Total Supply of LP Tokens: 3,000
User Action
A user wants to deposit:
Current Implementation (Without Precision Handling)
Balances Update:
Problem
The current implementation treats 1 unit of Token A and 1 unit of Token B as equivalent, which is incorrect due to their different decimal places. This results in an inaccurate calculation of the pool's invariant and, consequently, the LP tokens.
Expected Implementation (With Precision Handling)
Token A: 1,000 10^18 + 1 10^18 = 1,001 10^18 Token B: 2,000 10^6 + 1 10^12 = 2,001 10^6