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: CCIP hook and ism #5392

Merged
merged 45 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
34919cf
added CCIP hooks for publishing & receiving message; added CCIP Ism
Raid5594 Dec 1, 2023
a80c3a7
merged Receiver and Sender Hooks, removed obsolete constructor from Ism
Raid5594 Dec 15, 2023
c166e1d
leaving extraArgs empty for CCIP send
Raid5594 Dec 15, 2023
fe6d5f6
remove getter and storage items for CCIP last message details
Raid5594 Dec 15, 2023
81715be
quickfix and formatting
Raid5594 Dec 15, 2023
d9016a9
unit tests for CCIP Ism & small fixes
Raid5594 Dec 16, 2023
f1fea24
refactor CCIP Hook and CCIP ISM, update test
Raid5594 Dec 28, 2023
1c91152
remove commented out code
Raid5594 Dec 29, 2023
c8f7d82
remove unused imports
Raid5594 Dec 29, 2023
cae554f
update formatting accroding to comments
Raid5594 Feb 25, 2024
9cb7896
Merge branch 'main' into feature/ccip-hook-and-ism
yorhodes Feb 7, 2025
171dac5
Refactor auth hook quote management
yorhodes Feb 7, 2025
a36260c
Use authorized hook pattern
yorhodes Feb 7, 2025
9fc3df4
Fix tests
yorhodes Feb 7, 2025
e69a84c
Unify compiler versions
yorhodes Feb 7, 2025
5f62405
Remove CCIP changes
yorhodes Feb 7, 2025
e0b66ed
Update deps
yorhodes Feb 7, 2025
91e07ea
Fix compiler warnings
yorhodes Feb 7, 2025
f081246
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 7, 2025
f869431
Fix tests
yorhodes Feb 7, 2025
61c76ed
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 7, 2025
cc1858d
Fix for only authorized router
yorhodes Feb 7, 2025
58e6191
Restore pjson
yorhodes Feb 7, 2025
017cd87
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 7, 2025
f12c4d6
Merge branch 'ccip-warp-route' into feature/ccip-hook-and-ism
yorhodes Feb 10, 2025
0f0b3ee
Merge branch 'ccip-warp-route' into auth-hook-quote
yorhodes Feb 10, 2025
b7a6533
Address pr comments
yorhodes Feb 10, 2025
6858140
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 10, 2025
46249a1
Add refunds to all hooks
yorhodes Feb 11, 2025
c2590fb
Add docstrings
yorhodes Feb 11, 2025
28d34b0
docs(changeset): Add refunds to all hooks
yorhodes Feb 11, 2025
fc64b41
Add more docstrings
yorhodes Feb 11, 2025
fa5a4bf
Ensure refunds are not burned
yorhodes Feb 11, 2025
a08c4ea
Revert broad hook changes
yorhodes Feb 11, 2025
b10b445
Update tricky-masks-hang.md
yorhodes Feb 11, 2025
fb4d8ba
Fix protocol fee tests
yorhodes Feb 11, 2025
8f55894
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 11, 2025
56067e0
Adjust auth hook with refunds
yorhodes Feb 11, 2025
05c68b7
Merge branch 'auth-hook-quote' into feature/ccip-hook-and-ism
yorhodes Feb 11, 2025
f5dc1c3
Fix CCIP Hook
yorhodes Feb 11, 2025
a23651d
Merge branch 'ccip-warp-route' into feature/ccip-hook-and-ism
yorhodes Feb 11, 2025
a7a1e24
Merge branch 'ccip-warp-route' into feature/ccip-hook-and-ism
yorhodes Feb 11, 2025
7934ffa
Address pr comments
yorhodes Feb 11, 2025
54b471c
Address pr comments
yorhodes Feb 11, 2025
3acd58d
docs(changeset): Implement CCIP hook and ISM
yorhodes Feb 11, 2025
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
5 changes: 5 additions & 0 deletions .changeset/mean-cherries-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/core': minor
---

Implement CCIP hook and ISM
83 changes: 83 additions & 0 deletions solidity/contracts/hooks/CCIPHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

Check notice

Code scanning / Olympix Integrated Security

Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma Low

Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma

/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/

// ============ Internal Imports ============
import {AbstractMessageIdAuthHook} from "./libs/AbstractMessageIdAuthHook.sol";
import {Message} from "../libs/Message.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";

// ============ External Imports ============
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/**
* @title CCIPHook
* @notice Message hook to inform the CCIP of messages published through CCIP.
*/
contract CCIPHook is AbstractMessageIdAuthHook {
using Message for bytes;
using TypeCasts for bytes32;

IRouterClient internal immutable ccipRouter;
uint64 public immutable ccipDestination;

// ============ Constructor ============

constructor(
address _ccipRouter,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
uint64 _ccipDestination,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
address _mailbox,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
uint32 _destination,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
bytes32 _ism

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
) AbstractMessageIdAuthHook(_mailbox, _destination, _ism) {
ccipDestination = _ccipDestination;
ccipRouter = IRouterClient(_ccipRouter);
}

// ============ Internal functions ============

function _buildCCIPMessage(
bytes calldata message
) internal view returns (Client.EVM2AnyMessage memory) {
// Create an EVM2AnyMessage struct in memory with necessary information for sending a cross-chain message
return
Client.EVM2AnyMessage({
receiver: abi.encode(ism),
data: abi.encode(message.id()),
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we hardcode extraArgs? In their best practices, it says this should be mutable to 1) set the gas limits outside of the 200k default, and 2) set out of order execution if it’s required for certain chains

When allowOutOfOrderExecution is Required:
You must set allowOutOfOrderExecution to true. This setting acknowledges that messages may be executed out of order. If set to false, the message will revert and will not be processed.

feeToken: address(0)
});
}

function _quoteDispatch(
bytes calldata /*metadata*/,
bytes calldata message
) internal view override returns (uint256) {
Client.EVM2AnyMessage memory ccipMessage = _buildCCIPMessage(message);

return ccipRouter.getFee(ccipDestination, ccipMessage);
}

function _sendMessageId(
bytes calldata /*metadata*/,
bytes calldata message
) internal override {
Client.EVM2AnyMessage memory ccipMessage = _buildCCIPMessage(message);

ccipRouter.ccipSend{value: msg.value}(ccipDestination, ccipMessage);
}
}
70 changes: 70 additions & 0 deletions solidity/contracts/isms/hook/CCIPIsm.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

Check notice

Code scanning / Olympix Integrated Security

Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma Low

Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma

/*@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@ HYPERLANE @@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@@
@@@@@@@@@ @@@@@@@@*/

// ============ Internal Imports ============

import {IInterchainSecurityModule} from "../../interfaces/IInterchainSecurityModule.sol";
import {Message} from "../../libs/Message.sol";
import {TypeCasts} from "../../libs/TypeCasts.sol";
import {AbstractMessageIdAuthorizedIsm} from "./AbstractMessageIdAuthorizedIsm.sol";

// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";

/**
* @title CCIPIsm
* @notice Uses CCIP hook to verify interchain messages.
*/
contract CCIPIsm is AbstractMessageIdAuthorizedIsm, CCIPReceiver {

Check failure

Code scanning / Olympix Integrated Security

Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether Critical

Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether
using TypeCasts for bytes32;

// ============ Constants ============

uint8 public constant moduleType =
uint8(IInterchainSecurityModule.Types.NULL);

uint64 public immutable ccipOrigin;

// ============ Storage ============
constructor(
address _ccipRouter,

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
uint64 _ccipOrigin

Check notice

Code scanning / Olympix Integrated Security

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low

Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
) CCIPReceiver(_ccipRouter) {
ccipOrigin = _ccipOrigin;
}

// ============ Internal functions ============
function _ccipReceive(
Client.Any2EVMMessage memory any2EvmMessage
) internal override {
require(
ccipOrigin == any2EvmMessage.sourceChainSelector,
"Unauthorized origin"
);

bytes32 sender = abi.decode(any2EvmMessage.sender, (bytes32));
require(sender == authorizedHook, "Unauthorized hook");

bytes32 messageId = abi.decode(any2EvmMessage.data, (bytes32));
preVerifyMessage(messageId, msg.value);
}

function _isAuthorized() internal view override returns (bool) {
return msg.sender == getRouter();
}
}
2 changes: 1 addition & 1 deletion solidity/hardhat.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'solidity-coverage';
*/
module.exports = {
solidity: {
version: '0.8.19',
version: '0.8.22',
Copy link
Member Author

@yorhodes yorhodes Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CCIP contracts impose ^0.8.20

settings: {
optimizer: {
enabled: true,
Expand Down
1 change: 1 addition & 0 deletions solidity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "5.11.3",
"dependencies": {
"@arbitrum/nitro-contracts": "^1.2.1",
"@chainlink/contracts-ccip": "^1.5.0",
"@eth-optimism/contracts": "^0.6.0",
"@hyperlane-xyz/utils": "8.6.1",
"@layerzerolabs/lz-evm-oapp-v2": "2.0.2",
Expand Down
1 change: 1 addition & 0 deletions solidity/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@eth-optimism=../node_modules/@eth-optimism
@layerzerolabs=../node_modules/@layerzerolabs
@openzeppelin=../node_modules/@openzeppelin
@chainlink=../node_modules/@chainlink
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
fx-portal/=lib/fx-portal/
Loading
Loading