了解 Wasm 轻客户端合约的预期行为以及它与 08-wasm 之间的关系。

API

08-wasm 轻客户端代理会通过 Wasm VM 调用 Wasm 轻客户端。调用时需要输入 JSON 编码的负载消息,这些消息分为接下来各节中描述的三类。

InstantiateMessage

这是发送到合约 instantiate 入口点的消息。它包含底层轻客户端的客户端状态和共识状态的 protobuf 编码字节,这两者都由 MsgCreateClient 提供。请注意,JSON 消息中的字节会表示为 base64 编码字符串。
type InstantiateMessage struct {
    ClientState    []byte `json:"client_state"`
	ConsensusState []byte `json:"consensus_state"`
	Checksum       []byte `json:"checksum"
}
Wasm 轻客户端合约应将客户端状态和共识状态存储到带有客户端前缀的存储中的对应键下。

QueryMsg

QueryMsg 是一种带判别字段的联合类型,用于编码发送到合约 query 入口点的消息。该类型的字段在任一时刻只能设置一个,这样其余字段会在编码后的 JSON 中被省略,并且负载才能被正确转换为 Rust 中枚举的对应元素。
type QueryMsg struct {
    Status               *StatusMsg               `json:"status,omitempty"`
  TimestampAtHeight    *TimestampAtHeightMsg    `json:"timestamp_at_height,omitempty"`
  VerifyClientMessage  *VerifyClientMessageMsg  `json:"verify_client_message,omitempty"`
  CheckForMisbehaviour *CheckForMisbehaviourMsg `json:"check_for_misbehaviour,omitempty"`
}
#[cw_serde]
pub enum QueryMsg {
  Status(StatusMsg),
  TimestampAtHeight(TimestampAtHeightMsg),
  VerifyClientMessage(VerifyClientMessageRaw),
  CheckForMisbehaviour(CheckForMisbehaviourMsgRaw),
}
如需了解 Wasm 轻客户端合约在处理每种消息时应满足的预期,请阅读轻客户端开发者指南中的对应章节:

SudoMsg

SudoMsg 是一种带判别字段的联合类型,用于编码发送到合约 sudo 入口点的消息。该类型的字段在任一时刻只能设置一个,这样其余字段会在编码后的 JSON 中被省略,并且负载才能被正确转换为 Rust 中枚举的对应元素。 sudo 入口点能够在带有客户端前缀的存储中执行会修改状态的写入。
type SudoMsg struct {
    UpdateState                 *UpdateStateMsg                 `json:"update_state,omitempty"`
  UpdateStateOnMisbehaviour   *UpdateStateOnMisbehaviourMsg   `json:"update_state_on_misbehaviour,omitempty"`
  VerifyUpgradeAndUpdateState *VerifyUpgradeAndUpdateStateMsg `json:"verify_upgrade_and_update_state,omitempty"`
  VerifyMembership            *VerifyMembershipMsg            `json:"verify_membership,omitempty"`
  VerifyNonMembership         *VerifyNonMembershipMsg         `json:"verify_non_membership,omitempty"`
  MigrateClientStore          *MigrateClientStoreMsg          `json:"migrate_client_store,omitempty"`
}
#[cw_serde]
pub enum SudoMsg {
  UpdateState(UpdateStateMsgRaw),
  UpdateStateOnMisbehaviour(UpdateStateOnMisbehaviourMsgRaw),
  VerifyUpgradeAndUpdateState(VerifyUpgradeAndUpdateStateMsgRaw),
  VerifyMembership(VerifyMembershipMsgRaw),
  VerifyNonMembership(VerifyNonMembershipMsgRaw),
  MigrateClientStore(MigrateClientStoreMsgRaw),
}
如需了解 Wasm 轻客户端合约在处理每种消息时应满足的预期,请阅读轻客户端开发者指南中的对应章节:

迁移

08-wasm 代理轻客户端暴露了 MigrateContract RPC 端点,可用于将某个 Wasm 轻客户端合约(由客户端标识符指定)迁移到新的 Wasm 字节码(由字节码哈希指定)。该 RPC 端点的预期用途是:当当前字节码被发现存在缺陷或漏洞时,使合约能够迁移到新的字节码。合约要迁移到的 Wasm 字节码必须事先通过 MsgStoreCode 上传,并且必须实现 migrate 入口点。有关此 RPC 端点请求消息的信息,请参见MsgMigrateContract一节。

预期行为

08-wasm 代理轻客户端模块在执行会修改状态的写入消息时,要求 Wasm 轻客户端合约满足以下行为:
  • 合约不得从存储中删除客户端状态。
  • 合约不得将客户端状态更改为另一种类型的客户端状态。
  • 合约不得更改客户端状态中的校验和。
违反上述任何规则都会导致 08-wasm 返回错误,并中止该交易。
Learn about the expected behaviour of Wasm light client contracts and the between with 08-wasm.

API

The 08-wasm light client proxy performs calls to the Wasm light client via the Wasm VM. The calls require as input JSON-encoded payload messages that fall in the three categories described in the next sections.

InstantiateMessage

This is the message sent to the contract’s instantiate entry point. It contains the bytes of the protobuf-encoded client and consensus states of the underlying light client, both provided in MsgCreateClient. Please note that the bytes contained within the JSON message are represented as base64-encoded strings.
type InstantiateMessage struct {
    ClientState    []byte `json:"client_state"`
	ConsensusState []byte `json:"consensus_state"`
	Checksum       []byte `json:"checksum"
}
The Wasm light client contract is expected to store the client and consensus state in the corresponding keys of the client-prefixed store.

QueryMsg

QueryMsg acts as a discriminated union type that is used to encode the messages that are sent to the contract’s query entry point. Only one of the fields of the type should be set at a time, so that the other fields are omitted in the encoded JSON and the payload can be correctly translated to the corresponding element of the enumeration in Rust.
type QueryMsg struct {
    Status               *StatusMsg               `json:"status,omitempty"`
  TimestampAtHeight    *TimestampAtHeightMsg    `json:"timestamp_at_height,omitempty"`
  VerifyClientMessage  *VerifyClientMessageMsg  `json:"verify_client_message,omitempty"`
  CheckForMisbehaviour *CheckForMisbehaviourMsg `json:"check_for_misbehaviour,omitempty"`
}
#[cw_serde]
pub enum QueryMsg {
  Status(StatusMsg),
  TimestampAtHeight(TimestampAtHeightMsg),
  VerifyClientMessage(VerifyClientMessageRaw),
  CheckForMisbehaviour(CheckForMisbehaviourMsgRaw),
}
To learn what it is expected from the Wasm light client contract when processing each message, please read the corresponding section of the Light client developer guide:

SudoMsg

SudoMsg acts as a discriminated union type that is used to encode the messages that are sent to the contract’s sudo entry point. Only one of the fields of the type should be set at a time, so that the other fields are omitted in the encoded JSON and the payload can be correctly translated to the corresponding element of the enumeration in Rust. The sudo entry point is able to perform state-changing writes in the client-prefixed store.
type SudoMsg struct {
    UpdateState                 *UpdateStateMsg                 `json:"update_state,omitempty"`
  UpdateStateOnMisbehaviour   *UpdateStateOnMisbehaviourMsg   `json:"update_state_on_misbehaviour,omitempty"`
  VerifyUpgradeAndUpdateState *VerifyUpgradeAndUpdateStateMsg `json:"verify_upgrade_and_update_state,omitempty"`
  VerifyMembership            *VerifyMembershipMsg            `json:"verify_membership,omitempty"`
  VerifyNonMembership         *VerifyNonMembershipMsg         `json:"verify_non_membership,omitempty"`
  MigrateClientStore          *MigrateClientStoreMsg          `json:"migrate_client_store,omitempty"`
}
#[cw_serde]
pub enum SudoMsg {
  UpdateState(UpdateStateMsgRaw),
  UpdateStateOnMisbehaviour(UpdateStateOnMisbehaviourMsgRaw),
  VerifyUpgradeAndUpdateState(VerifyUpgradeAndUpdateStateMsgRaw),
  VerifyMembership(VerifyMembershipMsgRaw),
  VerifyNonMembership(VerifyNonMembershipMsgRaw),
  MigrateClientStore(MigrateClientStoreMsgRaw),
}
To learn what it is expected from the Wasm light client contract when processing each message, please read the corresponding section of the Light client developer guide:

Migration

The 08-wasm proxy light client exposes the MigrateContract RPC endpoint that can be used to migrate a given Wasm light client contract (specified by the client identifier) to a new Wasm byte code (specified by the hash of the byte code). The expected use case for this RPC endpoint is to enable contracts to migrate to new byte code in case the current byte code is found to have a bug or vulnerability. The Wasm byte code that contracts are migrated have to be uploaded beforehand using MsgStoreCode and must implement the migrate entry point. See sectionMsgMigrateContract for information about the request message for this RPC endpoint.

Expected behaviour

The 08-wasm proxy light client modules expects the following behaviour from the Wasm light client contracts when executing messages that perform state-changing writes:
  • The contract must not delete the client state from the store.
  • The contract must not change the client state to a client state of another type.
  • The contract must not change the checksum in the client state.
Any violation of these rules will result in an error returned from 08-wasm that will abort the transaction.