MsgStoreCode

通过 MsgStoreCode 将 Wasm 轻客户端合约上传到 Wasm VM 存储中:
type MsgStoreCode struct {
  / signer address
  Signer string
  / wasm byte code of light client contract. It can be raw or gzip compressed
  WasmByteCode []byte
}
在以下情况下,此消息预计会失败:
  • Signer 是无效的 Bech32 地址,或者与指定的 authority 地址不匹配。
  • WasmByteCode 为空,或者超过最大大小限制,当前限制为 3MB。
只有通过 MsgStoreCode 存储的轻客户端合约才允许被实例化。若尝试基于通过其他方式上传的合约创建轻客户端(例如当该模块与 08-wasm 共享同一个 Wasm VM 实例时,通过 x/wasm 上传的合约),将会失败。由于 Wasm VM 的 StoreCode 函数具有幂等性,因此同一份字节码可以被多次存储。 当 MsgStoreCode 执行成功时,合约的校验和(即合约字节码的 sha256 哈希)会被存入允许列表。当 relayer 携带 08-wasm 的 ClientState 提交 MsgCreateClient 时,客户端状态中会包含应被调用的 Wasm 字节码校验和。随后,02-client 会调用 08-wasm 对 Initialize 函数的实现(这是 LightClientModule 的一个接口函数),并检查客户端状态中的校验和是否与允许列表中的某个校验和匹配。如果找到匹配项,则初始化该轻客户端;否则,中止该交易。

MsgMigrateContract

通过 MsgMigrateContract 将合约迁移到新的 Wasm 字节码:
type MsgMigrateContract struct {
  / signer address
  Signer string
  / the client id of the contract
  ClientId string
  / the SHA-256 hash of the new wasm byte code for the contract
  Checksum []byte
  / the json-encoded migrate msg to be passed to the contract on migration
  Msg []byte
}
在以下情况下,此消息预计会失败:
  • Signer 是无效的 Bech32 地址,或者与指定的 authority 地址不匹配。
  • ClientId 不是以 08-wasm 为前缀的有效标识符。
  • Checksum 的长度不正好为 32 字节,或者未在允许的校验和列表中找到(执行 MsgStoreCode 时会向该列表新增校验和),或者它与该合约当前的校验和相同。
当 Wasm 轻客户端合约迁移到新的 Wasm 字节码后,该合约的校验和会更新为新的校验和。

MsgRemoveChecksum

通过 MsgRemoveChecksum 将某个校验和从允许的校验和列表中移除:
type MsgRemoveChecksum struct {
  / signer address
  Signer string
  / Wasm byte code checksum to be removed from the store
  Checksum []byte
}
在以下情况下,此消息预计会失败:
  • Signer 是无效的 Bech32 地址,或者与指定的 authority 地址不匹配。
  • Checksum 的长度不正好为 32 字节,或者未在允许的校验和列表中找到(执行 MsgStoreCode 时会向该列表新增校验和)。
当某个校验和从允许的校验和列表中被移除后,对应的 Wasm 字节码将无法在 08-wasm 对 Initialize 函数的实现 中用于实例化。

MsgStoreCode

Uploading the Wasm light client contract to the Wasm VM storage is achieved by means of MsgStoreCode:
type MsgStoreCode struct {
  / signer address
  Signer string
  / wasm byte code of light client contract. It can be raw or gzip compressed
  WasmByteCode []byte
}
This message is expected to fail if:
  • Signer is an invalid Bech32 address, or it does not match the designated authority address.
  • WasmByteCode is empty or it exceeds the maximum size, currently set to 3MB.
Only light client contracts stored using MsgStoreCode are allowed to be instantiated. An attempt to create a light client from contracts uploaded via other means (e.g. through x/wasm if the module shares the same Wasm VM instance with 08-wasm) will fail. Due to the idempotent nature of the Wasm VM’s StoreCode function, it is possible to store the same byte code multiple times. When execution of MsgStoreCode succeeds, the checksum of the contract (i.e. the sha256 hash of the contract’s byte code) is stored in an allow list. When a relayer submits MsgCreateClient with 08-wasm’s ClientState, the client state includes the checksum of the Wasm byte code that should be called. Then 02-client calls 08-wasm’s implementation of Initialize function (which is an interface function part of LightClientModule), and it will check that the checksum in the client state matches one of the checksums in the allow list. If a match is found, the light client is initialized; otherwise, the transaction is aborted.

MsgMigrateContract

Migrating a contract to a new Wasm byte code is achieved by means of MsgMigrateContract:
type MsgMigrateContract struct {
  / signer address
  Signer string
  / the client id of the contract
  ClientId string
  / the SHA-256 hash of the new wasm byte code for the contract
  Checksum []byte
  / the json-encoded migrate msg to be passed to the contract on migration
  Msg []byte
}
This message is expected to fail if:
  • Signer is an invalid Bech32 address, or it does not match the designated authority address.
  • ClientId is not a valid identifier prefixed by 08-wasm.
  • Checksum is not exactly 32 bytes long or it is not found in the list of allowed checksums (a new checksum is added to the list when executing MsgStoreCode), or it matches the current checksum of the contract.
When a Wasm light client contract is migrated to a new Wasm byte code the checksum for the contract will be updated with the new checksum.

MsgRemoveChecksum

Removing a checksum from the list of allowed checksums is achieved by means of MsgRemoveChecksum:
type MsgRemoveChecksum struct {
  / signer address
  Signer string
  / Wasm byte code checksum to be removed from the store
  Checksum []byte
}
This message is expected to fail if:
  • Signer is an invalid Bech32 address, or it does not match the designated authority address.
  • Checksum is not exactly 32 bytes long or it is not found in the list of allowed checksums (a new checksum is added to the list when executing MsgStoreCode).
When a checksum is removed from the list of allowed checksums, then the corresponding Wasm byte code will not be available for instantiation in 08-wasm’s implementation of Initialize function.