-
Notifications
You must be signed in to change notification settings - Fork 435
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
feat: CCIP hook and ism #5392
Changes from all commits
34919cf
a80c3a7
c166e1d
fe6d5f6
81715be
d9016a9
f1fea24
1c91152
c8f7d82
cae554f
9cb7896
171dac5
a36260c
9fc3df4
e69a84c
5f62405
e0b66ed
91e07ea
f081246
f869431
61c76ed
cc1858d
58e6191
017cd87
f12c4d6
0f0b3ee
b7a6533
6858140
46249a1
c2590fb
28d34b0
fc64b41
fa5a4bf
a08c4ea
b10b445
fb4d8ba
8f55894
56067e0
05c68b7
f5dc1c3
a23651d
a7a1e24
7934ffa
54b471c
3acd58d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperlane-xyz/core': minor | ||
--- | ||
|
||
Implement CCIP hook and ISM |
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; | ||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ 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: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
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); | ||
} | ||
} |
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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import 'solidity-coverage'; | |
*/ | ||
module.exports = { | ||
solidity: { | ||
version: '0.8.19', | ||
version: '0.8.22', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CCIP contracts impose |
||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
|
+193 −0 | CONTRIBUTING.md | |
+18 −2 | README.md | |
+2 −0 | foundry.toml | |
+1 −1 | package.json | |
+12 −1 | scripts/vm.py | |
+36 −1 | src/StdChains.sol | |
+17 −5 | src/StdCheats.sol | |
+9 −0 | src/StdInvariant.sol | |
+104 −0 | src/StdJson.sol | |
+1 −1 | src/StdStorage.sol | |
+104 −0 | src/StdToml.sol | |
+0 −17 | src/StdUtils.sol | |
+588 −76 | src/Vm.sol | |
+635 −608 | src/console.sol | |
+1 −1,555 | src/console2.sol | |
+2 −2 | src/interfaces/IERC4626.sol | |
+0 −234 | src/mocks/MockERC20.sol | |
+0 −231 | src/mocks/MockERC721.sol | |
+693 −4 | src/safeconsole.sol | |
+1 −5 | test/StdAssertions.t.sol | |
+22 −18 | test/StdChains.t.sol | |
+10 −10 | test/StdCheats.t.sol | |
+12 −12 | test/StdError.t.sol | |
+1 −1 | test/StdJson.t.sol | |
+4 −14 | test/StdMath.t.sol | |
+33 −8 | test/StdStorage.t.sol | |
+1 −1 | test/StdStyle.t.sol | |
+1 −1 | test/StdToml.t.sol | |
+12 −12 | test/StdUtils.t.sol | |
+9 −6 | test/Vm.t.sol | |
+0 −441 | test/mocks/MockERC20.t.sol | |
+0 −721 | test/mocks/MockERC721.t.sol |
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