diff --git a/lib/forge-std b/lib/forge-std index 705263c..52715a2 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 705263c95892a906d7af65f0f73ce8a4a0c80b80 +Subproject commit 52715a217dc51d0de15877878ab8213f6cbbbab5 diff --git a/lib/solady b/lib/solady index b8428c8..bfff552 160000 --- a/lib/solady +++ b/lib/solady @@ -1 +1 @@ -Subproject commit b8428c89d01cb13c9b602160130130d5754f3095 +Subproject commit bfff552c0d282c15258cab9377a7d4c5247d0434 diff --git a/src/wormhole/automatic-relayer/WormholeHelper.sol b/src/wormhole/automatic-relayer/WormholeHelper.sol index 22a313f..c66733b 100644 --- a/src/wormhole/automatic-relayer/WormholeHelper.sol +++ b/src/wormhole/automatic-relayer/WormholeHelper.sol @@ -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 // ////////////////////////////////////////////////////////////// @@ -151,6 +149,9 @@ contract WormholeHelper is Test { bytes[] additionalVAAs; uint256 currIndex; uint256 deliveryIndex; + uint256 currLen; + uint256 totalLen; + uint256[] indicesCache; DeliveryInstruction instruction; } @@ -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)); @@ -282,9 +294,6 @@ contract WormholeHelper is Test { ); } - /// @dev reset indices cache - delete indicesCache; - vm.stopBroadcast(); vm.selectFork(v.prevForkId); }