Skip to main content

模块化的安全

Hyperlane由Interchain Security Modules (ISMs)保护。ISMs是一种智能合约,负责验证在目标链上传递的链间消息是否实际发送在原始链上。

Hyperlane开发人员可以通过指定一个应用专用的ISM,optionally overrideMailbox's的默认ISM,他们可以根据自己的应用程序的需求来配置、组合和定制。

配置

Hyperlane定义了一套预先构建的ISMs。开发人员可以部署任何这些“现成的”合约,并使用自己的参数配置它们。

例如,希望增加链间安全主权的应用程序开发人员可以部署一个Multisig ISM,其中配置了来自他们自己社区的验证器。

组合

ISMs就像“securitylegos”。开发人员可以混合和匹配不同的ISMs,以编码最适合他们需求的安全模型。

例如,希望获得额外安全性的应用程序开发人员可以部署一个Aggregation ISM,它需要由配置了Hyperlane社区验证器的Multisig ISM 和一个Wormhole ISM进行验证,后者验证了Wormhole验证器集的quorum验证了消息。

自定义

ISMs是完全可定制的。开发人员可以编写自己的ISMs,根据应用程序的需要进行调整。

例如,应用程序开发人员可以构建基于消息内容调整安全模型的ISMs。高价值和不频繁的消息(例如治理)可以通过安全模型进行验证,该模型将安全性优先于延迟和gas成本。更低的值和更频繁的消息可以通过将延迟和gas成本置于安全性之上的安全模型进行验证。

覆盖默认ISM

应用程序开发者可以通过在应用程序中实现isspecificesinterchainsecuritymodule接口来覆盖默认的ISM。

具体来说,这个接口必须在实现handle()的智能合约中实现。

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

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

通用接口

ISMs必须实现IInterchainSecurityModel()接口。该接口由两个函数组成。

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

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

验证

ISMs必须实现的主要功能是verify()Mailbox将在将消息传递给收件人之前调用IInterchainSecurityModule.verify()。如果verify()恢复或返回false,消息将不会被传递。

verify()函数接受两个参数。

第一个是_metadata,由Relayer提供的任意字节组成。通常,这些字节是特定于ISM的。例如,对于Multisig ISM_metadata必须包含验证者签名。

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

warning

有关传递给verify()的Hyperlane消息格式的更多信息,请参阅 message .sol库。

模块类型

ISMs必须实现的第二个函数是moduleType()。这是用来通知Relayer_metadata中包含什么。ISMs 必须返回支持的一种模块类型。

序列图

下面展示了在目标链上验证和交付链间消息的简化顺序图。

info

如果收件人没有实现isspecificesinterchainsecuritymodule或者recipient.interchainSecurityModule()返回address(0),将使用Mailbox上配置的默认ISM来验证消息。

为了清晰起见,在序列图中省略了这一点。