From f75179e738cef2c2d25bafcb8a804e4f25ae1206 Mon Sep 17 00:00:00 2001 From: sujithsomraaj Date: Mon, 4 Sep 2023 17:40:19 +0530 Subject: [PATCH 1/2] feat: add dynamic slot selection for guardian set override --- .gas-snapshot | 16 ++++++++-------- .../specialized-relayer/WormholeHelper.sol | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 8370844..b40455b 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -3,10 +3,10 @@ AxelarHelperTest:testFancyAxelar() (gas: 234946) AxelarHelperTest:testMultiDstAxelar() (gas: 390512) AxelarHelperTest:testSimpleAxelar() (gas: 189522) CelerHelperTest:testCustomOrderingCeler() (gas: 108322) -CelerHelperTest:testFancyCeler() (gas: 117841) +CelerHelperTest:testFancyCeler() (gas: 122514) CelerHelperTest:testMultiDstCeler() (gas: 151149) CelerHelperTest:testSimpleCeler() (gas: 71938) -CelerHelperTest:testSimpleCelerWithEstimates() (gas: 72328) +CelerHelperTest:testSimpleCelerWithEstimates() (gas: 76856) HyperlaneHelperTest:testCustomOrderingHL() (gas: 145179) HyperlaneHelperTest:testFancyHL() (gas: 146237) HyperlaneHelperTest:testMultiDstHL() (gas: 193359) @@ -16,16 +16,16 @@ LayerZeroHelperTest:testCustomOrderingLZ() (gas: 339820) LayerZeroHelperTest:testFancyLZ() (gas: 295097) LayerZeroHelperTest:testMultiDstLZ() (gas: 475776) LayerZeroHelperTest:testSimpleLZ() (gas: 245549) -LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 246017) +LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 309922) StargateHelperTest:testCustomOrderingSG() (gas: 797976) StargateHelperTest:testFancySG() (gas: 589535) StargateHelperTest:testSimpleSG() (gas: 537570) -StargateHelperTest:testSimpleSGWithEstimates() (gas: 538082) +StargateHelperTest:testSimpleSGWithEstimates() (gas: 603229) WormholeAutomaticRelayerHelperTest:testCustomOrderingWormhole() (gas: 287323) WormholeAutomaticRelayerHelperTest:testFancyWormhole() (gas: 226022) WormholeAutomaticRelayerHelperTest:testMultiDstWormhole() (gas: 349780) WormholeAutomaticRelayerHelperTest:testSimpleWormhole() (gas: 179638) -WormholeSpecializedRelayerHelperTest:testCustomOrderingWormhole() (gas: 591017) -WormholeSpecializedRelayerHelperTest:testFancyWormhole() (gas: 327851) -WormholeSpecializedRelayerHelperTest:testMultiDstWormhole() (gas: 626734) -WormholeSpecializedRelayerHelperTest:testSimpleWormhole() (gas: 330643) \ No newline at end of file +WormholeSpecializedRelayerHelperTest:testCustomOrderingWormhole() (gas: 595375) +WormholeSpecializedRelayerHelperTest:testFancyWormhole() (gas: 330260) +WormholeSpecializedRelayerHelperTest:testMultiDstWormhole() (gas: 631627) +WormholeSpecializedRelayerHelperTest:testSimpleWormhole() (gas: 333052) \ No newline at end of file diff --git a/src/wormhole/specialized-relayer/WormholeHelper.sol b/src/wormhole/specialized-relayer/WormholeHelper.sol index 6ebfe7f..b7d109c 100644 --- a/src/wormhole/specialized-relayer/WormholeHelper.sol +++ b/src/wormhole/specialized-relayer/WormholeHelper.sol @@ -154,14 +154,19 @@ contract WormholeHelper is Test { } /// @dev overrides the guardian set by choosing slot - /// TODO: slot works till the guardianSetIndex is 3 + /// @notice overrides the current guardian set with a set of known guardian set function _prepareWormhole(address dstWormhole) internal { IWormhole wormhole = IWormhole(dstWormhole); - bytes32 lastSlot = 0x2fc7941cecc943bf2000c5d7068f2b8c8e9a29be62acd583fe9e6e90489a8c82; + + uint32 currentGuardianSet = wormhole.getCurrentGuardianSetIndex(); + bytes32 guardianSetSlot = keccak256(abi.encode(currentGuardianSet, 2)); + uint256 numGuardians = uint256(vm.load(address(wormhole), guardianSetSlot)); + + bytes32 lastSlot = bytes32(uint256(keccak256(abi.encodePacked(guardianSetSlot)))); uint256 lastKey = 420; /// @dev updates the storage slot to update the guardian set - for (uint256 i; i < 19; i++) { + for (uint256 i; i < numGuardians; i++) { vm.store(address(wormhole), bytes32(lastSlot), TypeCasts.addressToBytes32(vm.addr(lastKey))); lastSlot = bytes32(uint256(lastSlot) + 1); ++lastKey; From ce056cc8e0cf1bf627b610f107a3bb8921ff16fc Mon Sep 17 00:00:00 2001 From: sujithsomraaj Date: Mon, 4 Sep 2023 17:46:22 +0530 Subject: [PATCH 2/2] fix: gas snapshot --- .gas-snapshot | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index b40455b..f0ffec6 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -3,10 +3,10 @@ AxelarHelperTest:testFancyAxelar() (gas: 234946) AxelarHelperTest:testMultiDstAxelar() (gas: 390512) AxelarHelperTest:testSimpleAxelar() (gas: 189522) CelerHelperTest:testCustomOrderingCeler() (gas: 108322) -CelerHelperTest:testFancyCeler() (gas: 122514) +CelerHelperTest:testFancyCeler() (gas: 117841) CelerHelperTest:testMultiDstCeler() (gas: 151149) CelerHelperTest:testSimpleCeler() (gas: 71938) -CelerHelperTest:testSimpleCelerWithEstimates() (gas: 76856) +CelerHelperTest:testSimpleCelerWithEstimates() (gas: 72328) HyperlaneHelperTest:testCustomOrderingHL() (gas: 145179) HyperlaneHelperTest:testFancyHL() (gas: 146237) HyperlaneHelperTest:testMultiDstHL() (gas: 193359) @@ -16,11 +16,11 @@ LayerZeroHelperTest:testCustomOrderingLZ() (gas: 339820) LayerZeroHelperTest:testFancyLZ() (gas: 295097) LayerZeroHelperTest:testMultiDstLZ() (gas: 475776) LayerZeroHelperTest:testSimpleLZ() (gas: 245549) -LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 309922) +LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 246017) StargateHelperTest:testCustomOrderingSG() (gas: 797976) StargateHelperTest:testFancySG() (gas: 589535) StargateHelperTest:testSimpleSG() (gas: 537570) -StargateHelperTest:testSimpleSGWithEstimates() (gas: 603229) +StargateHelperTest:testSimpleSGWithEstimates() (gas: 538082) WormholeAutomaticRelayerHelperTest:testCustomOrderingWormhole() (gas: 287323) WormholeAutomaticRelayerHelperTest:testFancyWormhole() (gas: 226022) WormholeAutomaticRelayerHelperTest:testMultiDstWormhole() (gas: 349780)