From 676eaf25bb82272e0418ee3afdf6d4a3361879e9 Mon Sep 17 00:00:00 2001 From: sujithsomraaj Date: Mon, 8 Jan 2024 13:39:57 +0530 Subject: [PATCH 1/2] feat: move extra data gen to ambs from paymentHelper --- .../hyperlane/HyperlaneImplementation.sol | 7 +++++- .../layerzero/LayerzeroImplementation.sol | 7 +++++- .../WormholeARImplementation.sol | 7 +++++- src/interfaces/IAmbImplementation.sol | 7 +++++- src/payments/PaymentHelper.sol | 15 +---------- test/utils/BaseSetup.sol | 25 ------------------- 6 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/crosschain-data/adapters/hyperlane/HyperlaneImplementation.sol b/src/crosschain-data/adapters/hyperlane/HyperlaneImplementation.sol index ce51f0743..d6484e020 100644 --- a/src/crosschain-data/adapters/hyperlane/HyperlaneImplementation.sol +++ b/src/crosschain-data/adapters/hyperlane/HyperlaneImplementation.sol @@ -17,7 +17,6 @@ import { StandardHookMetadata } from "src/vendor/hyperlane/StandardHookMetadata. /// @dev Allows state registries to use Hyperlane v3 for crosschain communication /// @author Zeropoint Labs contract HyperlaneImplementation is IAmbImplementation, IMessageRecipient { - using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -120,6 +119,12 @@ contract HyperlaneImplementation is IAmbImplementation, IMessageRecipient { ); } + /// @inheritdoc IAmbImplementation + function generateExtraData(uint256 gasLimit) external pure override returns (bytes memory extraData) { + /// @notice encoded dst gas limit + extraData = abi.encode(gasLimit); + } + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/crosschain-data/adapters/layerzero/LayerzeroImplementation.sol b/src/crosschain-data/adapters/layerzero/LayerzeroImplementation.sol index bf4ff4037..ffc135d78 100644 --- a/src/crosschain-data/adapters/layerzero/LayerzeroImplementation.sol +++ b/src/crosschain-data/adapters/layerzero/LayerzeroImplementation.sol @@ -16,7 +16,6 @@ import { ILayerZeroUserApplicationConfig } from "src/vendor/layerzero/ILayerZero /// @dev Allows state registries to use Layerzero for crosschain communication /// @author Zeropoint Labs contract LayerzeroImplementation is IAmbImplementation, ILayerZeroUserApplicationConfig, ILayerZeroReceiver { - using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -189,6 +188,12 @@ contract LayerzeroImplementation is IAmbImplementation, ILayerZeroUserApplicatio (fees,) = lzEndpoint.estimateFees(chainId, address(this), message_, false, extraData_); } + /// @inheritdoc IAmbImplementation + function generateExtraData(uint256 gasLimit) external pure override returns (bytes memory extraData) { + /// @notice encoded layerzero adapter params (version 2). Other values are not used atm. + extraData = abi.encodePacked(uint16(2), gasLimit, uint256(0), address(0)); + } + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/crosschain-data/adapters/wormhole/automatic-relayer/WormholeARImplementation.sol b/src/crosschain-data/adapters/wormhole/automatic-relayer/WormholeARImplementation.sol index 2c4d46354..b63d7baff 100644 --- a/src/crosschain-data/adapters/wormhole/automatic-relayer/WormholeARImplementation.sol +++ b/src/crosschain-data/adapters/wormhole/automatic-relayer/WormholeARImplementation.sol @@ -16,7 +16,6 @@ import "src/vendor/wormhole/Utils.sol"; /// @dev Allows state registries to use Wormhole AR's for crosschain communication /// @author Zeropoint Labs contract WormholeARImplementation is IAmbImplementation, IWormholeReceiver { - using DataLib for uint256; ////////////////////////////////////////////////////////////// @@ -125,6 +124,12 @@ contract WormholeARImplementation is IAmbImplementation, IWormholeReceiver { (fees,) = relayer.quoteEVMDeliveryPrice(dstChainId, dstNativeAirdrop, dstGasLimit); } + /// @inheritdoc IAmbImplementation + function generateExtraData(uint256 gasLimit) external pure override returns (bytes memory extraData) { + /// @notice encoded dst gas limit + extraData = abi.encode(0, gasLimit); + } + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/interfaces/IAmbImplementation.sol b/src/interfaces/IAmbImplementation.sol index 29e6ccf81..85eaf3a8c 100644 --- a/src/interfaces/IAmbImplementation.sol +++ b/src/interfaces/IAmbImplementation.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; /// @dev Interface for arbitrary message bridge (AMB) implementations /// @author ZeroPoint Labs interface IAmbImplementation { - ////////////////////////////////////////////////////////////// // EVENTS // ////////////////////////////////////////////////////////////// @@ -32,6 +31,12 @@ interface IAmbImplementation { view returns (uint256 fees); + /// @dev returns the extra data for the given gas request + /// @param gasLimit is the amount of gas limit in wei to override + /// @return extraData is the bytes encoded extra data + /// NOTE: this process is unique to the message bridge + function generateExtraData(uint256 gasLimit) external pure returns (bytes memory extraData); + ////////////////////////////////////////////////////////////// // EXTERNAL WRITE FUNCTIONS // ////////////////////////////////////////////////////////////// diff --git a/src/payments/PaymentHelper.sol b/src/payments/PaymentHelper.sol index 86dc43a77..5e9da56d4 100644 --- a/src/payments/PaymentHelper.sol +++ b/src/payments/PaymentHelper.sol @@ -713,20 +713,7 @@ contract PaymentHelper is IPaymentHelper { for (uint256 i; i < len; ++i) { uint256 gasReq = i != 0 ? totalDstGasReqInWeiForProof : totalDstGasReqInWei; - /// @dev amb id 1: layerzero - /// @dev amb id 2: hyperlane - /// @dev amb id 3: wormhole - - /// @notice id 1: encoded layerzero adapter params (version 2). Other values are not used atm. - /// @notice id 2: encoded dst gas limit - /// @notice id 3: encoded dst gas limit - if (ambIds_[i] == 1) { - extraDataPerAMB[i] = abi.encodePacked(uint16(2), gasReq, uint256(0), address(0)); - } else if (ambIds_[i] == 2) { - extraDataPerAMB[i] = abi.encode(gasReq); - } else if (ambIds_[i] == 3) { - extraDataPerAMB[i] = abi.encode(0, gasReq); - } + extraDataPerAMB[i] = IAmbImplementation(superRegistry.getAmbAddress(ambIds_[i])).generateExtraData(gasReq); } } diff --git a/test/utils/BaseSetup.sol b/test/utils/BaseSetup.sol index 942862b2a..40637e209 100644 --- a/test/utils/BaseSetup.sol +++ b/test/utils/BaseSetup.sol @@ -1374,31 +1374,6 @@ abstract contract BaseSetup is DSTest, StdInvariant, Test { GAS ESTIMATION & PAYLOAD HELPERS //////////////////////////////////////////////////////////////*/ - /// @dev Generates the extraData for each amb - /// @dev TODO - Sujith to comment further - function _generateExtraData(uint8[] memory selectedAmbIds) internal pure returns (bytes[] memory) { - bytes[] memory ambParams = new bytes[](selectedAmbIds.length); - - for (uint256 i; i < selectedAmbIds.length; ++i) { - /// @dev 1 = Lz - if (selectedAmbIds[i] == 1) { - ambParams[i] = bytes(""); - } - - /// @dev 2 = Hyperlane - if (selectedAmbIds[i] == 2) { - ambParams[i] = abi.encode(500_000); - } - - /// @dev 3 = Wormhole - if (selectedAmbIds[i] == 3) { - ambParams[i] = abi.encode(0, 500_000); - } - } - - return ambParams; - } - struct LocalAckVars { uint256 totalFees; uint256 ambCount; From c2d68875638bba98d6e3013273b346318818db07 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:48:31 +0000 Subject: [PATCH 2/2] chore(deps): update actions/cache action to v4 --- .github/workflows/CI.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a25e66193..b0c4a64d1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -45,7 +45,7 @@ jobs: run: "FOUNDRY_PROFILE=localdev forge build" - name: "Cache the build so that it can be re-used by the other jobs" - uses: "actions/cache/save@v3" + uses: "actions/cache/save@v4" with: key: "foundry-build-${{ github.sha }}" path: | @@ -71,7 +71,7 @@ jobs: uses: "foundry-rs/foundry-toolchain@v1" - name: "Restore the cached build" - uses: "actions/cache/restore@v3" + uses: "actions/cache/restore@v4" with: fail-on-cache-miss: true key: "foundry-build-${{ github.sha }}"