Closed sherlock-admin closed 10 months ago
For the formula i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
when k = 1
Q2 = Q1/(1 - i* deltaB * Q1/Q0/Q0)
And deltaB
in the code is euqal to -deltaB
in the equation. Therefore the annotations are written as per the logic to be implemented by the contract
Q2=Q1/(1+ideltaBQ1/Q0/Q0)
temp = ideltaBQ1/Q0/Q0
which is the same as the code
uint256 temp = (idelta * V1) / (V0 * V0);
Tri-pathi
high
DODOMath._SolveQuadraticFunctionForTrade
is implemented incorrectSummary
DODOMath
is building block of all the computations. It computed complex mathematics operations like integration and Quadratic equations.DODOMath._SolveQuadraticFunctionForTarget
calculates the root of quadratic equation based on given params but using incorrect formula and so creating an array of issuesVulnerability Detail
From the comments and docs
As mentioned above
-b=(1-k)Q1-kQ0^2/Q1+i*deltaB
which is used to compute discriminant of the quadratic.https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/lib/DODOMath.sol#L116C2-L170C41
Also, from the comments it has been stated
ideltaB is actually -ideltaB in the equation
we need to modify the above computation terms in the same way But in same function at two instance delta has been used differently which is incorrectFirst one is in the calculation of
temp=ideltaBQ1/Q0/Q0
at Line 149 where deltaB is used as it is and Second at Line 159 where sign has been used differentlyImpact
DODOMath._SolveQuadraticFunctionForTarget
is used all over the place and Incorrect output will break all the trades/PMM.Code Snippet
https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/lib/DODOMath.sol#L116C2-L170C41
Tool used
Manual Review
Recommendation
First Write better comments and docs for Library since it's too confusing. A good mitigation will be taking delta input as int and use original formula to compute roots of the Quadratic equation