code-423n4 / 2024-05-predy-validation

0 stars 0 forks source link

Incorrect calculation of Amount Token 0 #684

Closed c4-bot-3 closed 3 months ago

c4-bot-3 commented 3 months ago

Lines of code

https://github.com/code-423n4/2024-05-predy/blob/a9246db5f874a91fb71c296aac6a66902289306a/src/libraries/Perp.sol#L768

Vulnerability details

Impact

Improper calculation of token 0 will return an erroneous output for the required amounts of token 0 .

Proof of Concept

Based on the documentation the amount of token 0 is calculated as L(1/sqrt(pb) but this is incorrect as it would not lead to2L(sqrt(x)`. the calculation of the sqrt is as follows https://docs.predy.finance/predy-v6/dev/squart where equation 1 is added to equation 4 but it is L(x/sqrt(pb) that is used within the equation.

Recommended Mitigation Steps

Check the uniswap pool for the given pair and return the current price X and use it in the calculation for token 0 Amt.

Assessed type

Math