Closed code423n4 closed 1 year ago
0xRobocop marked the issue as duplicate of #143
0xRobocop marked the issue as low quality report
0xRobocop marked the issue as not a duplicate
0xRobocop marked the issue as primary issue
Invalid.
Running the following in Z3 using python, says that discriminant cannot be negative if reserves have positive values.
from z3 import *
a = Real('a')
b = Real('b')
x = Real('x')
y = Real('y')
s = Solver()
s.add(y > 0, x > 0, (a*y + b*x)**2 < 4*(a*b - 1)*(x*y))
for c in s.assertions() :
print(c)
print(s.check())
print(s.model())
JustDravee marked the issue as unsatisfactory: Insufficient proof
Lines of code
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L831-L834 https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L716
Vulnerability details
Impact
The
EvolvingProteus._getUtility
function is used to calculate theutility
value of the pool at the time of the function call. Theutilitiy
is calculated using a quadratic formula which is shown below:Above quadratic equation when solved gives us two solutions which differ based on the sign of the
discriminant
. Thediscriminant
is calculated in the function as shown below:This issue here is with the
uint256((bQuad**2 - (aQuad.muli(cQuad)*4)))
phrase. Since we are taking the square root of the result of the above phrase we are casting its result intouint256
.Now consider the following scenario:
(bQuad**2 - (aQuad.muli(cQuad)*4))
phrase results in anegative value
.aQuad.muli(cQuad)*4) > bQuad**2
.uint256
it will result in a large positive value (since negative int256 is represented in two's complement format).aQuad.muli(cQuad)*4) > bQuad**2
this condition occurred the transaction should have reverted.utility
value thus providing a wrongutility
value.Proof of Concept
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L831-L834
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L716
Tools Used
VSCode and Manual Review
Recommended Mitigation Steps
Hence it is recommended to revert the transaction when
aQuad.muli(cQuad)*4) > bQuad**2
occurs. This can be done by implementing arequire
statement (beforeint256 disc
value is calculated) as shown below:Assessed type
Under/Overflow