Skip to content

Commit

Permalink
Merge pull request #38 from exp-table/wormhole-helper-patch
Browse files Browse the repository at this point in the history
chore: remove storage in wormhole helper
  • Loading branch information
sujithsomraaj committed May 29, 2024
2 parents 11743db + 6cba034 commit 68c8c4d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 51 deletions.
72 changes: 36 additions & 36 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
AxelarHelperTest:testCustomOrderingAxelar() (gas: 341418)
AxelarHelperTest:testFancyAxelar() (gas: 235044)
AxelarHelperTest:testMultiDstAxelar() (gas: 390668)
AxelarHelperTest:testSimpleAxelar() (gas: 189620)
CelerHelperTest:testCustomOrderingCeler() (gas: 108266)
CelerHelperTest:testFancyCeler() (gas: 117863)
CelerHelperTest:testMultiDstCeler() (gas: 151193)
CelerHelperTest:testSimpleCeler() (gas: 71872)
CelerHelperTest:testSimpleCelerWithEstimates() (gas: 72350)
HyperlaneHelperTest:testCustomOrderingHL() (gas: 145211)
HyperlaneHelperTest:testFancyHL() (gas: 146259)
HyperlaneHelperTest:testMultiDstHL() (gas: 193293)
HyperlaneHelperTest:testSimpleHL() (gas: 98262)
HyperlaneHelperTest:testSimpleHLWithEstimates() (gas: 98880)
LayerZeroHelperTest:testCustomOrderingLZ() (gas: 339755)
LayerZeroHelperTest:testFancyLZ() (gas: 295099)
LayerZeroHelperTest:testMultiDstLZ() (gas: 475768)
LayerZeroHelperTest:testSimpleLZ() (gas: 245432)
LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 246032)
LayerZeroV2HelperTest:testCustomEventSelector() (gas: 341391)
LayerZeroV2HelperTest:testMultipleDestinations() (gas: 648749)
LayerZeroV2HelperTest:testMultipleDestinationsCustomEventSelector() (gas: 648860)
LayerZeroV2HelperTest:testSingleDestination() (gas: 344129)
StargateHelperTest:testCustomOrderingSG() (gas: 798098)
StargateHelperTest:testFancySG() (gas: 589613)
StargateHelperTest:testSimpleSG() (gas: 537621)
StargateHelperTest:testSimpleSGWithEstimates() (gas: 538154)
WormholeAutomaticRelayerHelperTest:testCustomOrderingWormhole() (gas: 281508)
WormholeAutomaticRelayerHelperTest:testFancyWormhole() (gas: 223380)
WormholeAutomaticRelayerHelperTest:testMultiDstWormhole() (gas: 344783)
WormholeAutomaticRelayerHelperTest:testMultiDstWormholeWithAdditionalVAA() (gas: 374508)
WormholeAutomaticRelayerHelperTest:testSimpleWormhole() (gas: 176992)
WormholeSpecializedRelayerHelperTest:testCustomOrderingWormhole() (gas: 598867)
WormholeSpecializedRelayerHelperTest:testFancyWormhole() (gas: 332021)
WormholeSpecializedRelayerHelperTest:testMultiDstWormhole() (gas: 635152)
WormholeSpecializedRelayerHelperTest:testSimpleWormhole() (gas: 334813)
AxelarHelperTest:testCustomOrderingAxelar() (gas: 341805)
AxelarHelperTest:testFancyAxelar() (gas: 236169)
AxelarHelperTest:testMultiDstAxelar() (gas: 391397)
AxelarHelperTest:testSimpleAxelar() (gas: 189999)
CelerHelperTest:testCustomOrderingCeler() (gas: 108685)
CelerHelperTest:testFancyCeler() (gas: 118987)
CelerHelperTest:testMultiDstCeler() (gas: 151884)
CelerHelperTest:testSimpleCeler() (gas: 72229)
CelerHelperTest:testSimpleCelerWithEstimates() (gas: 72704)
HyperlaneHelperTest:testCustomOrderingHL() (gas: 145598)
HyperlaneHelperTest:testFancyHL() (gas: 147384)
HyperlaneHelperTest:testMultiDstHL() (gas: 194040)
HyperlaneHelperTest:testSimpleHL() (gas: 98641)
HyperlaneHelperTest:testSimpleHLWithEstimates() (gas: 99256)
LayerZeroHelperTest:testCustomOrderingLZ() (gas: 340154)
LayerZeroHelperTest:testFancyLZ() (gas: 296242)
LayerZeroHelperTest:testMultiDstLZ() (gas: 476527)
LayerZeroHelperTest:testSimpleLZ() (gas: 245817)
LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 246414)
LayerZeroV2HelperTest:testCustomEventSelector() (gas: 341769)
LayerZeroV2HelperTest:testMultipleDestinations() (gas: 649473)
LayerZeroV2HelperTest:testMultipleDestinationsCustomEventSelector() (gas: 649584)
LayerZeroV2HelperTest:testSingleDestination() (gas: 344507)
StargateHelperTest:testCustomOrderingSG() (gas: 798922)
StargateHelperTest:testFancySG() (gas: 591061)
StargateHelperTest:testSimpleSG() (gas: 538333)
StargateHelperTest:testSimpleSGWithEstimates() (gas: 538863)
WormholeAutomaticRelayerHelperTest:testCustomOrderingWormhole() (gas: 281916)
WormholeAutomaticRelayerHelperTest:testFancyWormhole() (gas: 224571)
WormholeAutomaticRelayerHelperTest:testMultiDstWormhole() (gas: 345623)
WormholeAutomaticRelayerHelperTest:testMultiDstWormholeWithAdditionalVAA() (gas: 372929)
WormholeAutomaticRelayerHelperTest:testSimpleWormhole() (gas: 177400)
WormholeSpecializedRelayerHelperTest:testCustomOrderingWormhole() (gas: 599240)
WormholeSpecializedRelayerHelperTest:testFancyWormhole() (gas: 332394)
WormholeSpecializedRelayerHelperTest:testMultiDstWormhole() (gas: 635874)
WormholeSpecializedRelayerHelperTest:testSimpleWormhole() (gas: 335186)
2 changes: 1 addition & 1 deletion lib/solady
Submodule solady updated 162 files
35 changes: 22 additions & 13 deletions src/wormhole/automatic-relayer/WormholeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ contract WormholeHelper is Test {
/// @dev is the default event selector if not specified by the user
bytes32 constant MESSAGE_EVENT_SELECTOR = 0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2;

uint256[] public indicesCache;

//////////////////////////////////////////////////////////////
// EXTERNAL FUNCTIONS //
//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -151,6 +149,9 @@ contract WormholeHelper is Test {
bytes[] additionalVAAs;
uint256 currIndex;
uint256 deliveryIndex;
uint256 currLen;
uint256 totalLen;
uint256[] indicesCache;
DeliveryInstruction instruction;
}

Expand Down Expand Up @@ -237,33 +238,44 @@ contract WormholeHelper is Test {
Vm.Log memory log;
console.log("Total Log Length:", logs.length);

/// @dev calculates the valid indices length
for (uint256 i; i < logs.length; i++) {
log = logs[i];
if (log.topics[0] == eventSelector) v.totalLen++;
}

v.indicesCache = new uint256[](v.totalLen);

/// @dev calculates the valid indices
for (uint256 i; i < logs.length; i++) {
log = logs[i];
if (log.topics[0] == eventSelector) indicesCache.push(i);
if (log.topics[0] == eventSelector) {
v.indicesCache[v.currLen] = i;
v.currLen++;
}
}

/// @dev if valid indices > 1, then it has additional VAAs to be delivered
/// @dev constructs the additional VAAs in that case
v.additionalVAAs = new bytes[](indicesCache.length - 1);
v.additionalVAAs = new bytes[](v.indicesCache.length - 1);
v.currIndex;

console.log("Total matching VAAs:", indicesCache.length);
console.log("Total matching VAAs:", v.indicesCache.length);

if (indicesCache.length > 1 && expDstAddress != address(0)) {
for (uint256 j; j < indicesCache.length; j++) {
log = logs[indicesCache[j]];
if (v.indicesCache.length > 1 && expDstAddress != address(0)) {
for (uint256 j; j < v.indicesCache.length; j++) {
log = logs[v.indicesCache[j]];

if (TypeCasts.bytes32ToAddress(log.topics[1]) != dstRelayer) {
v.additionalVAAs[v.currIndex] = _generateSignedVAA(srcChainId, dstWormhole, log.topics[1], log.data);
v.currIndex++;
} else {
v.deliveryIndex = indicesCache[j];
v.deliveryIndex = v.indicesCache[j];
}
}
}

log = logs[v.currIndex == 0 ? indicesCache[0] : v.deliveryIndex];
log = logs[v.currIndex == 0 ? v.indicesCache[0] : v.deliveryIndex];

(v.sequence, v.nonce, v.payload,) = abi.decode(log.data, (uint64, uint32, bytes, uint8));

Expand All @@ -282,9 +294,6 @@ contract WormholeHelper is Test {
);
}

/// @dev reset indices cache
delete indicesCache;

vm.stopBroadcast();
vm.selectFork(v.prevForkId);
}
Expand Down

0 comments on commit 68c8c4d

Please sign in to comment.