From 868f5a7e3854939119f2579493e4f986f248905a Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:43:35 +0800 Subject: [PATCH 1/6] internal: s48 doc about on feeGrowth --- src/pool-cl/interfaces/ICLPoolManager.sol | 8 ++++++++ src/pool-cl/libraries/CLPool.sol | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/pool-cl/interfaces/ICLPoolManager.sol b/src/pool-cl/interfaces/ICLPoolManager.sol index 055d6bef..0505caa9 100644 --- a/src/pool-cl/interfaces/ICLPoolManager.sol +++ b/src/pool-cl/interfaces/ICLPoolManager.sol @@ -108,6 +108,11 @@ interface ICLPoolManager is IProtocolFees, IPoolManager, IExtsload { function getPoolBitmapInfo(PoolId id, int16 word) external view returns (uint256 tickBitmap); /// @notice Get the fee growth global for the given pool + /// @return feeGrowthGlobal0x128 The global fee growth for token0 + /// @return feeGrowthGlobal1x128 The global fee growth for token1 + /// @dev feeGrowthGlobal can be artificially inflated by a malicious actor and integrators should be careful using the value + /// For pools with a single liquidity position, actors can donate to themselves to freely inflate feeGrowthGlobal + /// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme function getFeeGrowthGlobals(PoolId id) external view @@ -135,6 +140,9 @@ interface ICLPoolManager is IProtocolFees, IPoolManager, IExtsload { /// @notice Modify the position for the given pool /// @return delta The total balance delta of the caller of modifyLiquidity. /// @return feeDelta The balance delta of the fees generated in the liquidity range. + /// @dev feeDelta can be artificially inflated by a malicious actor and integrators should be careful using the value + /// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feeDelta) + /// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData) external returns (BalanceDelta delta, BalanceDelta feeDelta); diff --git a/src/pool-cl/libraries/CLPool.sol b/src/pool-cl/libraries/CLPool.sol index 29e71d0f..73a4bd89 100644 --- a/src/pool-cl/libraries/CLPool.sol +++ b/src/pool-cl/libraries/CLPool.sol @@ -48,6 +48,10 @@ library CLPool { /// @notice Thrown by donate if there is currently 0 liquidity, since the fees will not go to any liquidity providers error NoLiquidityToReceiveFees(); + /// @notice The state of a pool + /// @dev feeGrowthGlobal can be artificially inflated + /// For pools with a single liquidity position, actors can donate to themselves to freely inflate feeGrowthGlobal + /// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme struct State { CLSlot0 slot0; /// @dev accumulated lp fees From df407cd4cdcc7cedd8b693baefd395735113fab9 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:59:57 +0800 Subject: [PATCH 2/6] feat: update forge-std dependency --- lib/forge-std | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/forge-std b/lib/forge-std index 52715a21..726a6ee5 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 52715a217dc51d0de15877878ab8213f6cbbbab5 +Subproject commit 726a6ee5fc8427a0013d6f624e486c9130c0e336 From 187a8280d07926d52bfd0a4bfe41c88a5b166593 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:09:03 +0800 Subject: [PATCH 3/6] internal: s49 add initi code hash --- snapshots/BinPoolManagerTest.json | 3 +++ snapshots/CLPoolManagerTest.json | 3 +++ snapshots/VaultTest.json | 3 +++ test/pool-bin/BinPoolManager.t.sol | 7 +++++++ test/pool-cl/CLPoolManager.t.sol | 10 +++++++--- test/vault/Vault.t.sol | 6 ++++++ 6 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 snapshots/BinPoolManagerTest.json create mode 100644 snapshots/CLPoolManagerTest.json create mode 100644 snapshots/VaultTest.json diff --git a/snapshots/BinPoolManagerTest.json b/snapshots/BinPoolManagerTest.json new file mode 100644 index 00000000..df31df1e --- /dev/null +++ b/snapshots/BinPoolManagerTest.json @@ -0,0 +1,3 @@ +{ + "binPoolManager initcode hash (without constructor params, as uint256)": "73425840329377707764016122574450195738786283045901954729586336840188059167782" +} \ No newline at end of file diff --git a/snapshots/CLPoolManagerTest.json b/snapshots/CLPoolManagerTest.json new file mode 100644 index 00000000..2ae2f814 --- /dev/null +++ b/snapshots/CLPoolManagerTest.json @@ -0,0 +1,3 @@ +{ + "clPoolManager initcode hash (without constructor params, as uint256)": "43498189724800683414039944409888665118981458752163755806370462274516389565331" +} \ No newline at end of file diff --git a/snapshots/VaultTest.json b/snapshots/VaultTest.json new file mode 100644 index 00000000..e21c1dfb --- /dev/null +++ b/snapshots/VaultTest.json @@ -0,0 +1,3 @@ +{ + "Vault initcode hash (without constructor params, as uint256)": "42285739453326546745334574088065442781095713906976306156700703402717362931041" +} \ No newline at end of file diff --git a/test/pool-bin/BinPoolManager.t.sol b/test/pool-bin/BinPoolManager.t.sol index 48897b46..423aaec5 100644 --- a/test/pool-bin/BinPoolManager.t.sol +++ b/test/pool-bin/BinPoolManager.t.sol @@ -120,6 +120,13 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { } } + function test_initcodeHash() public { + vm.snapshotValue( + "binPoolManager initcode hash (without constructor params, as uint256)", + uint256(keccak256(type(BinPoolManager).creationCode)) + ); + } + function testInitialize_gasCheck_withoutHooks() public { snapStart("BinPoolManagerTest#testInitialize_gasCheck_withoutHooks"); poolManager.initialize(key, activeId); diff --git a/test/pool-cl/CLPoolManager.t.sol b/test/pool-cl/CLPoolManager.t.sol index 7c3b856a..27f4b04a 100644 --- a/test/pool-cl/CLPoolManager.t.sol +++ b/test/pool-cl/CLPoolManager.t.sol @@ -82,6 +82,13 @@ contract CLPoolManagerTest is Test, NoIsolate, Deployers, TokenFixture, GasSnaps } } + function test_initcodeHash() public { + vm.snapshotValue( + "clPoolManager initcode hash (without constructor params, as uint256)", + uint256(keccak256(type(CLPoolManager).creationCode)) + ); + } + // ************** *************** // // ************** initialize *************** // // ************** *************** // @@ -1811,9 +1818,6 @@ contract CLPoolManagerTest is Test, NoIsolate, Deployers, TokenFixture, GasSnaps "" ); snapEnd(); - - console2.log("token0 balance: ", IERC20(Currency.unwrap(currency0)).balanceOf(address(vault))); - console2.log("token1 balance: ", IERC20(Currency.unwrap(currency1)).balanceOf(address(vault))); } function testSwap_failsIfNotInitialized(uint160 sqrtPriceX96) public { diff --git a/test/vault/Vault.t.sol b/test/vault/Vault.t.sol index ee6f9592..01ca1ac5 100644 --- a/test/vault/Vault.t.sol +++ b/test/vault/Vault.t.sol @@ -88,6 +88,12 @@ contract VaultTest is Test, NoIsolate, GasSnapshot, TokenFixture { } } + function test_initcodeHash() public { + vm.snapshotValue( + "Vault initcode hash (without constructor params, as uint256)", uint256(keccak256(type(Vault).creationCode)) + ); + } + function testRegisterPoolManager() public { assertEq(vault.isAppRegistered(address(unRegPoolManager)), false); assertEq(vault.isAppRegistered(address(poolManager1)), true); From 813cd54417134aaac7b58ad272ec7ae2c20316fe Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:11:20 +0800 Subject: [PATCH 4/6] gas: gas update after updating foundry --- .../BinPoolSwapTest#test_exactInputSingleBin_SwapForX.snap | 2 +- .../BinPoolSwapTest#test_exactInputSingleBin_SwapForY.snap | 2 +- .../BinPoolSwapTest#test_exactOutputSingleBin_SwapForX.snap | 2 +- .forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForX.snap b/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForX.snap index 08fa717e..a1399c20 100644 --- a/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForX.snap +++ b/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForX.snap @@ -1 +1 @@ -63109 \ No newline at end of file +63178 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForY.snap b/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForY.snap index ae3b9b1b..a2b6ed1d 100644 --- a/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForY.snap +++ b/.forge-snapshots/BinPoolSwapTest#test_exactInputSingleBin_SwapForY.snap @@ -1 +1 @@ -63078 \ No newline at end of file +63147 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolSwapTest#test_exactOutputSingleBin_SwapForX.snap b/.forge-snapshots/BinPoolSwapTest#test_exactOutputSingleBin_SwapForX.snap index 7411cb30..e5b3213f 100644 --- a/.forge-snapshots/BinPoolSwapTest#test_exactOutputSingleBin_SwapForX.snap +++ b/.forge-snapshots/BinPoolSwapTest#test_exactOutputSingleBin_SwapForX.snap @@ -1 +1 @@ -57403 \ No newline at end of file +57469 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap index f6f255f4..7e778e33 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap @@ -1 +1 @@ -148676 \ No newline at end of file +148674 \ No newline at end of file From f77c5879b9ea7bff6b8ac2ed20bdad52fa31e00c Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:24:16 +0800 Subject: [PATCH 5/6] internal: s52 update CI to usse foundry stable version --- .github/workflows/coverage.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 8fdf9af4..b1049428 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -15,7 +15,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: nightly + version: stable # install dependency - uses: actions/setup-node@v3 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5b0a7d1b..8f22de38 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,7 +27,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: nightly + version: stable - name: Compile run: yarn prettier-check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4273da55..677303d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: nightly-471e4ac317858b3419faaee58ade30c0671021e0 # Nightly (2024-10-03) + version: stable # If FOUNDRY_PROFILE is removed, test will not revert if exceed contract size limit - name: Run tests From 6afc404f8390f7476987bd3eb3c6387357eac6a1 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:46:47 +0800 Subject: [PATCH 6/6] test: revert test.yml foundry version --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 677303d7..4273da55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 with: - version: stable + version: nightly-471e4ac317858b3419faaee58ade30c0671021e0 # Nightly (2024-10-03) # If FOUNDRY_PROFILE is removed, test will not revert if exceed contract size limit - name: Run tests