Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dynamic slot selection for guardian set override #27

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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)
WormholeSpecializedRelayerHelperTest:testCustomOrderingWormhole() (gas: 595375)
WormholeSpecializedRelayerHelperTest:testFancyWormhole() (gas: 330260)
WormholeSpecializedRelayerHelperTest:testMultiDstWormhole() (gas: 631627)
WormholeSpecializedRelayerHelperTest:testSimpleWormhole() (gas: 333052)
11 changes: 8 additions & 3 deletions src/wormhole/specialized-relayer/WormholeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down