-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The get_amounts_for_delta()
function at sqrt_price_math.rs
is implemented incorrectly.
#48
Comments
The submission has identified a flaw in the I believe a medium-risk severity rating is appropriate and the referenced finding provides great insight into properly assessing the severity of the issue. |
alex-ppg marked the issue as selected for report |
alex-ppg marked the issue as satisfactory |
Hi @alex-ppg Thank you for judging this contest. The
This is not correct. Uniswap v3 team published a blog post to describe the relationship between current_sqrt_price and current_tick. The relation is as follows: If the current_tick is The Uniswap v3 liquidity equations are: This report talks about the edge of cases 1 and 2 where Let us examine case-1 range So, case-1 range The case-2 range is So, case-2 range At the point when This is exactly what happens in Case-1 formula for The only difference that this report prescribes is the use of the case-2 formula when Uniswap v3 uses ticks to separate the range for using different liquidity formulas. Superposition protocol uses sqrt prices. If one carefully converts the tick ordering to sqrt price ordering (with the relationship specified in this blog) then one would know that At max, this issue deserves a QA level severity. Thank you. |
Dear Judge, I believe the issue referenced in the Sherlock contest was misjudged. The same issue was later submitted in a more recent contest on Code4rena, where another Judge reviewed and confirmed it to be invalid. I strongly recommend reviewing all the comments on the issue: To summarize, the issue is invalid because using |
Hey @Ys-Prakash and @DadeKuma, greatly appreciate your PJQA feedback! After reviewing all comments, assessing the call-chain of this particular finding, and evaluating the precedence set forth within C4 I am inclined to consider this submission as invalid due to the results of the function being mathematically equivalent regardless of how the branching logic is implemented. |
alex-ppg marked the issue as unsatisfactory: |
Lines of code
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/maths/sqrt_price_math.rs#L252
Vulnerability details
Impact
The function
get_amounts_for_delta()
at thesqrt_price_math.rs
contract is used to compute the quantity oftoken0
andtoken1
to add to the position given a delta of liquidity. These quantities depend on the delta of liquidity, the current tick and the ticks of the range boundaries. Actually,get_amounts_for_delta()
uses the sqrt prices instead of the ticks, but they are equivalent since each tick represents a sqrt price.There exists 3 cases:
The current tick is outside the range from the left, this means only
token0
should be added.The current tick is within the range, this means both
token0
andtoken1
should be added.The current tick is outside the range from the right, this means only
token1
should be added.When the current price is equal to the left boundary of the range, the uniswap pool will request both
token0
andtoken1
, but this implementation will only request from the usertoken0
so the pool will lose sometoken1
if it has enough to cover it.Reference finding: sherlock-audit/2023-06-arrakis-judging#8
Proof of concept
If we look at the function
get_amounts_for_delta()
:The implementation says that if the current price is equal to the price of the lower tick, it means that it is outside of the range and hence only
token0
should be added to the position.But for the UniswapV3 implementation, the current price must be lower in order to consider it outside:
Tools Used
Manual Review
Recommendation
We recommend to change to the following:
Assessed type
Uniswap
The text was updated successfully, but these errors were encountered: