覆盖默认的 ISM
开发者可以通过在其应用程序中实现 ISpecifiesInterchainSecurityModule
接口来指定或覆盖默认的 ISM。
如果未指定 ISM,或者指定的 ISM 是空地址,则将使用目标链的邮箱中配置的默认 ISM。
ISM 接口
ISM 必须实现 IInterchainSecurityModule
接口。该实现可以根据应用程序的需求进行配置、组合和自定义。
具体来说,该接口必须在实现 handle()
的同一智能合约中实现。
该接口由两个函数组成:verify
和 moduleType
。
IInterchainSecurityModule
接口
- Solidity
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
interface IInterchainSecurityModule {
enum Types {
UNUSED,
ROUTING,
AGGREGATION,
LEGACY_MULTISIG,
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
NULL, // used with relayer carrying no metadata
CCIP_READ,
ARB_L2_TO_L1,
WEIGHTED_MERKLE_ROOT_MULTISIG,
WEIGHTED_MESSAGE_ID_MULTISIG,
OP_L2_TO_L1
}
/**
* @notice Returns an enum that represents the type of security model
* encoded by this ISM.
* @dev Relayers infer how to fetch and format metadata.
*/
function moduleType() external view returns (uint8);
/**
* @notice Defines a security model responsible for verifying interchain
* messages based on the provided metadata.
* @param _metadata Off-chain metadata provided by a relayer, specific to
* the security model encoded by the module (e.g. validator signatures)
* @param _message Hyperlane encoded interchain message
* @return True if the message was verified
*/
function verify(
bytes calldata _metadata,
bytes calldata _message
) external returns (bool);
}
interface ISpecifiesInterchainSecurityModule {
function interchainSecurityModule()
external
view
returns (IInterchainSecurityModule);
}
验证
/**
* @notice Defines a security model responsible for verifying interchain
* messages based on the provided metadata.
* @param _metadata Off-chain metadata provided by a relayer, specific to
* the security model encoded by the module (e.g. validator signatures)
* @param _message Hyperlane encoded interchain message
* @return True if the message was verified
*/
function verify(
bytes calldata _metadata,
bytes calldata _message
) external returns (bool);
ISM 必须实现的主要功能是 verify()
。邮箱将会在将消息发送给接收者之前调用 IInterchainSecurityModule.verify()
。如果 verify()
失败或返回 false
,则消息将不会被发送。
参数:
-
_metadata
:由 Relayer 提供的任意字节。通常,这些字节是特定于 ISM 的。例如,针对 Multisig ISM 的_metadata
必须包含验证者签名。 -
_message
:由正在验证的 Hyperlane 消息组成。ISM 可以使用此信息检查有关正在验证的消息的详细信息。例如,针对 Multisig ISM,可以根据消息的来源链更改验证者集。
有关传递给 verify()
的 Hyperlane 消息格式的更多信息,请参见 Message.sol
库。
模块类型
ISM 必须实现的第二个功能是 moduleType()
。
/**
* @notice Returns an enum that represents the type of security model
* encoded by this ISM.
* @dev Relayers infer how to fetch and format metadata.
*/
function moduleType() external view returns (uint8);
这用于向 Relayer 指示在 _metadata
中包含什么。ISM 必须 返回支持的模块类型之一。
enum Types {
UNUSED,
ROUTING,
AGGREGATION,
LEGACY_MULTISIG,
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
NULL, // used with relayer carrying no metadata
CCIP_READ,
ARB_L2_TO_L1,
WEIGHTED_MERKLE_ROOT_MULTISIG,
WEIGHTED_MESSAGE_ID_MULTISIG,
OP_L2_TO_L1
}
-
所有 ISM 合约必须实现 ISM 接口,这要求定义
moduleType
。 该类型由 Relayer 分支,以确定该 ISM 所需的元数据。 有关模块类型及其元数据格式的更多信息,请参见 协议。 -
有关可用模块类型及其各自元数据的更多信息,请访问本节中概述的 ISM 文档,例如 Multisig ISM。