Skip to main content

链间安全模块接口

Hyperlane通过通用智能合约接口模块化链间消息安全。实现负责使用一些证明元数据验证在目标链上传递的消息实际上是在源链上发送的。

消息接收者可以通过指定InterchainSecurityModule地址来指定自定义安全约束。这个实现可以根据应用程序的需要进行配置、组合和定制。

IInterchainSecurityModule Interface
// 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
}

/**
* @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);
}

验证

function verify(
bytes calldata _metadata,
bytes calldata _message
) external returns (bool);

在将邮件传递给收件人之前,邮箱将调用verify。如果verify返回false,消息将不会被传递。

  • _metadata由中继器提供的任意字节组成。通常,这些字节是针对ISM的。例如,对于Multisig ISM_metadata必须包含验证器签名。

__message 由正在验证的Hyperlane消息组成。ISMs可以使用它来检查正在验证的消息的详细信息。例如,Multisig ISM 可以根据消息的原始链更改验证器集。

模块类型

function moduleType() external view returns (uint8);

这是用来通知中继器如何编码 _metadata。ISMs 必须返回一个支持的模块类型。

enum Types {
UNUSED,
ROUTING,
AGGREGATION,
LEGACY_MULTISIG,
MERKLE_ROOT_MULTISIG,
MESSAGE_ID_MULTISIG,
NULL, // used with relayer carrying no metadata
CCIP_READ
}

指定ISM

为了指定他们想要使用的ISM,开发人员在任何通过handle()接收链间消息的合约中实现ISpecifiesInterchainSecurityModule接口。

interface ISpecifiesInterchainSecurityModule {
function interchainSecurityModule()
external
view
returns (IInterchainSecurityModule);
}

如果未指定ISM或指定的ISM为空地址,则将使用目的链上已配置为默认地址的ISM。

排序图

下面是在目标链上验证和传递链间消息的详细序列图。

info

如果收件人没有实现ISpecifiesInterchainSecurityModulerecipient.interchainSecurityModule()返回address(0),则使用邮箱上配置的默认ISM来验证消息。