Skip to content

Commit 398ba38

Browse files
committed
Check for reserves overflow in verify() function
- Gas is not a concern anymore if we are moving from binary search - Removes need for separate overflow checks in constructor
1 parent 9e67c0c commit 398ba38

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/EulerSwap.sol

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ contract EulerSwap is IEulerSwap, EVCUtil {
6666
// EulerSwap params
6767

6868
require(params.fee < 1e18, BadParam());
69-
require(
70-
params.equilibriumReserve0 <= type(uint112).max && params.equilibriumReserve1 <= type(uint112).max,
71-
BadParam()
72-
);
73-
require(params.currReserve0 <= type(uint112).max && params.currReserve1 <= type(uint112).max, BadParam());
7469
require(curveParams.priceX > 0 && curveParams.priceY > 0, BadParam());
7570
require(curveParams.priceX <= 1e36 && curveParams.priceY <= 1e36, BadParam());
7671
require(curveParams.concentrationX <= 1e18 && curveParams.concentrationY <= 1e18, BadParam());
@@ -100,6 +95,7 @@ contract EulerSwap is IEulerSwap, EVCUtil {
10095

10196
// Validate reserves
10297

98+
require(verify(equilibriumReserve0, equilibriumReserve1), CurveViolation());
10399
require(verify(reserve0, reserve1), CurveViolation());
104100
require(!verify(reserve0 > 0 ? reserve0 - 1 : 0, reserve1 > 0 ? reserve1 - 1 : 0), CurveViolation());
105101

@@ -135,7 +131,6 @@ contract EulerSwap is IEulerSwap, EVCUtil {
135131
uint256 newReserve0 = reserve0 + amount0In - amount0Out;
136132
uint256 newReserve1 = reserve1 + amount1In - amount1Out;
137133

138-
require(newReserve0 <= type(uint112).max && newReserve1 <= type(uint112).max, Overflow());
139134
require(verify(newReserve0, newReserve1), CurveViolation());
140135

141136
reserve0 = uint112(newReserve0);
@@ -191,6 +186,8 @@ contract EulerSwap is IEulerSwap, EVCUtil {
191186

192187
/// @inheritdoc IEulerSwap
193188
function verify(uint256 newReserve0, uint256 newReserve1) public view returns (bool) {
189+
if (newReserve0 > type(uint112).max || newReserve1 > type(uint112).max) return false;
190+
194191
if (newReserve0 >= equilibriumReserve0) {
195192
if (newReserve1 >= equilibriumReserve1) return true;
196193
return

0 commit comments

Comments
 (0)