08-wasm 之间的关系。
API
08-wasm 轻客户端代理会通过 Wasm VM 调用 Wasm 轻客户端。调用时需要输入 JSON 编码的负载消息,这些消息分为接下来各节中描述的三类。
InstantiateMessage
这是发送到合约 instantiate 入口点的消息。它包含底层轻客户端的客户端状态和共识状态的 protobuf 编码字节,这两者都由 MsgCreateClient 提供。请注意,JSON 消息中的字节会表示为 base64 编码字符串。
QueryMsg
QueryMsg 是一种带判别字段的联合类型,用于编码发送到合约 query 入口点的消息。该类型的字段在任一时刻只能设置一个,这样其余字段会在编码后的 JSON 中被省略,并且负载才能被正确转换为 Rust 中枚举的对应元素。
- 对于
StatusMsg,参见Status方法。 - 对于
TimestampAtHeightMsg,参见GetTimestampAtHeight方法。 - 对于
VerifyClientMessageMsg,参见VerifyClientMessage。 - 对于
CheckForMisbehaviourMsg,参见CheckForMisbehaviour方法。
SudoMsg
SudoMsg 是一种带判别字段的联合类型,用于编码发送到合约 sudo 入口点的消息。该类型的字段在任一时刻只能设置一个,这样其余字段会在编码后的 JSON 中被省略,并且负载才能被正确转换为 Rust 中枚举的对应元素。
sudo 入口点能够在带有客户端前缀的存储中执行会修改状态的写入。
- 对于
UpdateStateMsg,参见UpdateState。 - 对于
UpdateStateOnMisbehaviourMsg,参见UpdateStateOnMisbehaviour。 - 对于
VerifyUpgradeAndUpdateStateMsg,参见GetTimestampAtHeight方法。 - 对于
VerifyMembershipMsg,参见VerifyMembership方法。 - 对于
VerifyNonMembershipMsg,参见VerifyNonMembership方法。 - 对于
MigrateClientStoreMsg,参见实现CheckSubstituteAndUpdateState。
迁移
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
The08-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.
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.
- For
StatusMsg, see the sectionStatusmethod. - For
TimestampAtHeightMsg, see the sectionGetTimestampAtHeightmethod. - For
VerifyClientMessageMsg, see the sectionVerifyClientMessage. - For
CheckForMisbehaviourMsg, see the sectionCheckForMisbehaviourmethod.
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.
- For
UpdateStateMsg, see the sectionUpdateState. - For
UpdateStateOnMisbehaviourMsg, see the sectionUpdateStateOnMisbehaviour. - For
VerifyUpgradeAndUpdateStateMsg, see the sectionGetTimestampAtHeightmethod. - For
VerifyMembershipMsg, see the sectionVerifyMembershipmethod. - For
VerifyNonMembershipMsg, see the sectionVerifyNonMembershipmethod. - For
MigrateClientStoreMsg, see the section ImplementingCheckSubstituteAndUpdateState.
Migration
The08-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
The08-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.
08-wasm that will abort the transaction.