From e9958fd8e7859c3f49a78c1d799016a934e9d538 Mon Sep 17 00:00:00 2001 From: Alice Henshaw Date: Thu, 15 Aug 2024 16:47:01 +0100 Subject: [PATCH 1/4] revert l01 --- src/libraries/Pool.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Pool.sol b/src/libraries/Pool.sol index 1a3763547..d922859f3 100644 --- a/src/libraries/Pool.sol +++ b/src/libraries/Pool.sol @@ -319,7 +319,7 @@ library Pool { if (params.sqrtPriceLimitX96 >= slot0Start.sqrtPriceX96()) { PriceLimitAlreadyExceeded.selector.revertWith(slot0Start.sqrtPriceX96(), params.sqrtPriceLimitX96); } - if (params.sqrtPriceLimitX96 < TickMath.MIN_SQRT_PRICE) { + if (params.sqrtPriceLimitX96 <= TickMath.MIN_SQRT_PRICE) { PriceLimitOutOfBounds.selector.revertWith(params.sqrtPriceLimitX96); } } else { From 4838038864b475c0ae670708c256f339a1d05c11 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 27 Aug 2024 11:36:39 -0400 Subject: [PATCH 2/4] revert certora L-01 --- .forge-snapshots/poolManager bytecode size.snap | 2 +- .forge-snapshots/simple swap with native.snap | 2 +- .forge-snapshots/simple swap.snap | 2 +- .forge-snapshots/swap CA fee on unspecified.snap | 2 +- .forge-snapshots/swap against liquidity with native token.snap | 2 +- .forge-snapshots/swap against liquidity.snap | 2 +- .forge-snapshots/swap burn native 6909 for input.snap | 2 +- .forge-snapshots/swap mint output as 6909.snap | 2 +- .forge-snapshots/swap skips hook call if hook is caller.snap | 2 +- .forge-snapshots/swap with dynamic fee.snap | 2 +- .forge-snapshots/swap with hooks.snap | 2 +- .forge-snapshots/swap with lp fee and protocol fee.snap | 2 +- .forge-snapshots/swap with return dynamic fee.snap | 2 +- .forge-snapshots/update dynamic fee in before swap.snap | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.forge-snapshots/poolManager bytecode size.snap b/.forge-snapshots/poolManager bytecode size.snap index 87bbf127c..c8d27c225 100644 --- a/.forge-snapshots/poolManager bytecode size.snap +++ b/.forge-snapshots/poolManager bytecode size.snap @@ -1 +1 @@ -24066 \ No newline at end of file +24067 \ No newline at end of file diff --git a/.forge-snapshots/simple swap with native.snap b/.forge-snapshots/simple swap with native.snap index ce132b9c7..4af1b0eea 100644 --- a/.forge-snapshots/simple swap with native.snap +++ b/.forge-snapshots/simple swap with native.snap @@ -1 +1 @@ -108760 \ No newline at end of file +108763 \ No newline at end of file diff --git a/.forge-snapshots/simple swap.snap b/.forge-snapshots/simple swap.snap index 56bfb02c6..d4a79a852 100644 --- a/.forge-snapshots/simple swap.snap +++ b/.forge-snapshots/simple swap.snap @@ -1 +1 @@ -123603 \ No newline at end of file +123606 \ No newline at end of file diff --git a/.forge-snapshots/swap CA fee on unspecified.snap b/.forge-snapshots/swap CA fee on unspecified.snap index 940dc5b8a..1c33ea79c 100644 --- a/.forge-snapshots/swap CA fee on unspecified.snap +++ b/.forge-snapshots/swap CA fee on unspecified.snap @@ -1 +1 @@ -155043 \ No newline at end of file +155046 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity with native token.snap b/.forge-snapshots/swap against liquidity with native token.snap index 38fe333e5..10c0d1717 100644 --- a/.forge-snapshots/swap against liquidity with native token.snap +++ b/.forge-snapshots/swap against liquidity with native token.snap @@ -1 +1 @@ -105913 \ No newline at end of file +105916 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index e2037a491..7f7d1d362 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -117004 \ No newline at end of file +117007 \ No newline at end of file diff --git a/.forge-snapshots/swap burn native 6909 for input.snap b/.forge-snapshots/swap burn native 6909 for input.snap index 85254e28d..f4d4fa750 100644 --- a/.forge-snapshots/swap burn native 6909 for input.snap +++ b/.forge-snapshots/swap burn native 6909 for input.snap @@ -1 +1 @@ -118558 \ No newline at end of file +118561 \ No newline at end of file diff --git a/.forge-snapshots/swap mint output as 6909.snap b/.forge-snapshots/swap mint output as 6909.snap index c5fef4dec..733904e57 100644 --- a/.forge-snapshots/swap mint output as 6909.snap +++ b/.forge-snapshots/swap mint output as 6909.snap @@ -1 +1 @@ -155443 \ No newline at end of file +155446 \ No newline at end of file diff --git a/.forge-snapshots/swap skips hook call if hook is caller.snap b/.forge-snapshots/swap skips hook call if hook is caller.snap index 973274157..6d66df24f 100644 --- a/.forge-snapshots/swap skips hook call if hook is caller.snap +++ b/.forge-snapshots/swap skips hook call if hook is caller.snap @@ -1 +1 @@ -207011 \ No newline at end of file +207017 \ No newline at end of file diff --git a/.forge-snapshots/swap with dynamic fee.snap b/.forge-snapshots/swap with dynamic fee.snap index 3b5a40e04..f3912cac1 100644 --- a/.forge-snapshots/swap with dynamic fee.snap +++ b/.forge-snapshots/swap with dynamic fee.snap @@ -1 +1 @@ -139635 \ No newline at end of file +139638 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index 38464dd74..55d9c3a3b 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -132641 \ No newline at end of file +132644 \ No newline at end of file diff --git a/.forge-snapshots/swap with lp fee and protocol fee.snap b/.forge-snapshots/swap with lp fee and protocol fee.snap index 86a713ad9..a4d212073 100644 --- a/.forge-snapshots/swap with lp fee and protocol fee.snap +++ b/.forge-snapshots/swap with lp fee and protocol fee.snap @@ -1 +1 @@ -169379 \ No newline at end of file +169382 \ No newline at end of file diff --git a/.forge-snapshots/swap with return dynamic fee.snap b/.forge-snapshots/swap with return dynamic fee.snap index 9dd5c7ffd..d9d821c8a 100644 --- a/.forge-snapshots/swap with return dynamic fee.snap +++ b/.forge-snapshots/swap with return dynamic fee.snap @@ -1 +1 @@ -145961 \ No newline at end of file +145964 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index b6755140a..c06af2fcc 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -148238 \ No newline at end of file +148241 \ No newline at end of file From 4f0d7b887b0941580614ac5d41e69a0ef328305b Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Tue, 27 Aug 2024 16:54:38 -0400 Subject: [PATCH 3/4] sb-43 --- src/libraries/TickMath.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libraries/TickMath.sol b/src/libraries/TickMath.sol index 38f7fadc0..f9423e926 100644 --- a/src/libraries/TickMath.sol +++ b/src/libraries/TickMath.sol @@ -108,8 +108,8 @@ library TickMath { } } - /// @notice Calculates the greatest tick value such that getPriceAtTick(tick) <= price - /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getPriceAtTick may + /// @notice Calculates the greatest tick value such that getSqrtPriceAtTick(tick) <= sqrtPriceX96 + /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getSqrtPriceAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt price for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the price is less than or equal to the input price @@ -217,10 +217,10 @@ library TickMath { log_2 := or(log_2, shl(50, f)) } - int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number + int256 log_sqrt10001 = log_2 * 255738958999603826347141; // Q22.128 number - int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); - int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); + int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247209) >> 128); + int24 tickHi = int24((log_sqrt10001 + 291339464771989623025533689748046440464) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtPriceAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } From 7c0e7d7d48b6d27f9854a645514f607c187fd9f9 Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Tue, 27 Aug 2024 17:01:56 -0400 Subject: [PATCH 4/4] sb-44 --- src/libraries/TickMath.sol | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/TickMath.sol b/src/libraries/TickMath.sol index f9423e926..fd1bfa7d7 100644 --- a/src/libraries/TickMath.sol +++ b/src/libraries/TickMath.sol @@ -67,12 +67,13 @@ library TickMath { if (absTick > uint256(int256(MAX_TICK))) InvalidTick.selector.revertWith(tick); + // TODO: Update natspec if this PR is merged. // Equivalent to: // price = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; // or price = int(2**128 / sqrt(1.0001)) if (absTick & 0x1) else 1 << 128 uint256 price; assembly ("memory-safe") { - price := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594001), and(absTick, 0x1))) + price := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594002), and(absTick, 0x1))) } if (absTick & 0x2 != 0) price = (price * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) price = (price * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; @@ -85,14 +86,14 @@ library TickMath { if (absTick & 0x200 != 0) price = (price * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) price = (price * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) price = (price * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; - if (absTick & 0x1000 != 0) price = (price * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; + if (absTick & 0x1000 != 0) price = (price * 0xd097f3bdfd2022b8845ad8f792aa5826) >> 128; if (absTick & 0x2000 != 0) price = (price * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) price = (price * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) price = (price * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) price = (price * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; - if (absTick & 0x20000 != 0) price = (price * 0x5d6af8dedb81196699c329225ee604) >> 128; + if (absTick & 0x20000 != 0) price = (price * 0x5d6af8dedb81196699c329225ee605) >> 128; if (absTick & 0x40000 != 0) price = (price * 0x2216e584f5fa1ea926041bedfe98) >> 128; - if (absTick & 0x80000 != 0) price = (price * 0x48a170391f7dc42444e8fa2) >> 128; + if (absTick & 0x80000 != 0) price = (price * 0x48a170391f7dc42444e8fa3) >> 128; assembly ("memory-safe") { // if (tick > 0) price = type(uint256).max / price;