Submitted by prapandey031
The protocol provides a function to increment a positions liquidity:
It is present in the SeawaterAmm.sol:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/sol/SeawaterAMM.sol#L464
It calls a function in lib.rs:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/lib.rs#L914
This calls an internal function in lib.rs:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/lib.rs#L730
This function calls a function in pool.rs:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/pool.rs#L253
In the above function at LOC-265, we have:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/pool.rs#L265
Instead of:
This passes not the current price but the price of the current tick to the get_liquidity_for_amounts() function.
The following is a step-by-step PoC that explains the issue in detail. Lets say there exists a pool with the following configuration:
The current tick of a pool is determined by:
Note: please see scenario in wardens original submission.
Now, a user A, owner of the position stated above, calls the function:
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/sol/SeawaterAMM.sol#L464
Ultimately, the adjust_position() in pool.rs is called. In this function, at LOC-265, the following is set:
This means that sqrt_ratio_x_96 would have 1 (or 2^96) as the curr_tick is 0. Now, get_liquidity_for_amounts() function is called:
This function checks at LOC-312 that:
and calls:
This is wrong as the current price of the pool (= 1.00005) is in the price range of the position ([1, (1.0001)^5]).
Basically, the main liquidity formula used by the protocol currently is:
Note: please see scenario in wardens original submission.
The calculation is also wrong. Lets assume that A calls the function with:
The present calculation would result in an amount0 that would be ~899.98 or 900 which is 90% of amount0Desired and thus, is less than amount0Min. Therefore, this transaction would revert.
The protocol mentions We should follow Uniswap V3s math faithfully as one of its core invariants. This must not break. However, as this report explains, this invariant stands broken.
If the amount0Desired and amount0Min (also applicable to amount1) are very close to each other, then the transaction to incrPositionC3AC7CAA() function reverts. So, the severity is High.
Desmos scientific calculator.
Replace the following in the adjust_position() function below:
Math
0xsomeone (judge) commented:
prapandey031 (warden) commented:
0xsomeone (judge) commented:
prapandey031 (warden) commented:
0xsomeone (judge) decreased severity to Medium and commented:
af-afk (Superposition) confirmed 
