Skip to content

Commit

Permalink
docs: rename code hash to checksum in 08-wasm docs (#5133)
Browse files Browse the repository at this point in the history
* docs: rename code hash to checksum in 08-wasm docs

* Rename last reference in code.

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
  • Loading branch information
Carlos Rodriguez and DimitrisJim authored Nov 20, 2023
1 parent 482b6b2 commit 99fbe68
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/docs/03-light-clients/04-wasm/02-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `08-wasm` module is not a regular light client in the same sense as, for exa
The `08-wasm`'s `ClientState` data structure contains three fields:

- `Data` contains the bytes of the Protobuf-encoded client state of the underlying light client implemented as a Wasm contract. For example, if the Wasm light client contract implements the GRANDPA light client algorithm, then `Data` will contain the bytes for a [GRANDPA client state](https://github.com/ComposableFi/composable-ibc/blob/02ce69e2843e7986febdcf795f69a757ce569272/light-clients/ics10-grandpa/src/proto/grandpa.proto#L35-L60).
- `CodeHash` is the sha256 hash of the Wasm contract's byte code. This hash is used as an identifier to call the right contract.
- `Checksum` is the sha256 hash of the Wasm contract's byte code. This hash is used as an identifier to call the right contract.
- `LatestHeight` is the latest height of the counterparty state machine (i.e. the height of the blockchain), whose consensus state the light client tracks.

```go
Expand All @@ -27,7 +27,7 @@ type ClientState struct {
// light client implemented as a Wasm contract
Data []byte
// sha256 hash of Wasm contract byte code
CodeHash []byte
Checksum []byte
// latest height of the counterparty ledger
LatestHeight types.Height
}
Expand Down
22 changes: 11 additions & 11 deletions docs/docs/03-light-clients/04-wasm/04-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This message is expected to fail if:

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 code hash 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`](https://github.com/cosmos/ibc-go/blob/v7.2.0/proto/ibc/core/client/v1/tx.proto#L25-L37) with 08-wasm's `ClientState`, the client state includes the code hash of the Wasm byte code that should be called. Then 02-client calls [08-wasm's implementation of `Initialize` function](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34) (which is an interface function part of `ClientState`), and it will check that the code hash in the client state matches one of the code hashes in the allow list. If a match is found, the light client is initialized; otherwise, the transaction is aborted.
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`](https://github.com/cosmos/ibc-go/blob/v7.2.0/proto/ibc/core/client/v1/tx.proto#L25-L37) 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](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34) (which is an interface function part of `ClientState`), 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`

Expand All @@ -40,7 +40,7 @@ type MsgMigrateContract struct {
// the client id of the contract
ClientId string
// the SHA-256 hash of the new wasm byte code for the contract
CodeHash []byte
Checksum []byte
// the json-encoded migrate msg to be passed to the contract on migration
Msg []byte
}
Expand All @@ -50,26 +50,26 @@ 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`.
- `CodeHash` is not exactly 32 bytes long or it is not found in the list of allowed code hashes (a new code hash is added to the list when executing `MsgStoreCode`), or it matches the current code hash of the contract.
- `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 code hash for the contract will be updated with the new code hash.
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.

## `MsgRemoveCodeHash`
## `MsgRemoveChecksum`

Removing a code hash from the list of allowed code hashes is achieved by means of `MsgRemoveCodeHash`:
Removing a checksum from the list of allowed checksums is achieved by means of `MsgRemoveChecksum`:

```go
type MsgRemoveCodeHash struct {
type MsgRemoveChecksum struct {
// signer address
Signer string
// code hash to be removed from the store
CodeHash []byte
// 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.
- `CodeHash` is not exactly 32 bytes long or it is not found in the list of allowed code hashes (a new code hash is added to the list when executing `MsgStoreCode`).
- `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 code hash is removed from the list of allowed code hashes, then the corresponding Wasm byte code will not be available for instantiation in [08-wasm's implementation of `Initialize` function](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34).
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](https://github.com/cosmos/ibc-go/blob/v7.2.0/modules/core/02-client/keeper/client.go#L34).
16 changes: 8 additions & 8 deletions docs/docs/03-light-clients/04-wasm/05-governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Alternatively, the process of submitting the proposal may be simpler if you use

## Migrating an existing Wasm light client contract

If governance is the allowed authority, the governance v1 proposal that needs to be submitted to migrate an existing new Wasm light client contract should contain the message [`MsgMigrateContract`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L51-L63) with the code hash of the Wasm byte code to migrate to. Use the following CLI command and JSON as an example:
If governance is the allowed authority, the governance v1 proposal that needs to be submitted to migrate an existing new Wasm light client contract should contain the message [`MsgMigrateContract`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L51-L63) with the checksum of the Wasm byte code to migrate to. Use the following CLI command and JSON as an example:

```shell
simd tx gov submit-proposal <path/to/proposal.json> --from <key_or_address>
Expand All @@ -85,7 +85,7 @@ where `proposal.json` contains:
"@type": "/ibc.lightclients.wasm.v1.MsgMigrateContract",
"signer": "cosmos1...", // the authority address (e.g. the gov module account address)
"client_id": "08-wasm-1", // client identifier of the Wasm light client contract that will be migrated
"new_code_hash": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code to migrate to, previously stored with MsgStoreCode
"checksum": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code to migrate to, previously stored with MsgStoreCode
"msg": "{}" // JSON-encoded message to be passed to the contract on migration
}
],
Expand All @@ -96,9 +96,9 @@ where `proposal.json` contains:

To learn more about the `submit-proposal` CLI command, please check out [the relevant section in Cosmos SDK documentation](https://docs.cosmos.network/main/modules/gov#submit-proposal).

## Removing an existing code hash
## Removing an existing checksum

If governance is the allowed authority, the governance v1 proposal that needs to be submitted to remove a specific code hash from the -list of allowed code hashes should contain the message [`MsgRemoveCodeHash`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L38-L46) with the code hash (of a corresponding Wasm byte code). Use the following CLI command and JSON as an example:
If governance is the allowed authority, the governance v1 proposal that needs to be submitted to remove a specific checksum from the list of allowed checksums should contain the message [`MsgRemoveChecksum`](https://github.com/cosmos/ibc-go/blob/729cb090951b1e996427b2258cf72c49787b885a/proto/ibc/lightclients/wasm/v1/tx.proto#L38-L46) with the checksum (of a corresponding Wasm byte code). Use the following CLI command and JSON as an example:

```shell
simd tx gov submit-proposal <path/to/proposal.json> --from <key_or_address>
Expand All @@ -108,13 +108,13 @@ where `proposal.json` contains:

```json
{
"title": "Remove code hash of Wasm light client byte code",
"summary": "Remove code hash",
"title": "Remove checksum of Wasm light client byte code",
"summary": "Remove checksum",
"messages": [
{
"@type": "/ibc.lightclients.wasm.v1.MsgRemoveCodeHash",
"@type": "/ibc.lightclients.wasm.v1.MsgRemoveChecksum",
"signer": "cosmos1...", // the authority address (e.g. the gov module account address)
"code_hash": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code that should be removed from the list of allowed code hashes
"checksum": "a8ad...4dc0", // SHA-256 hash of the Wasm byte code that should be removed from the list of allowed checksums
}
],
"metadata": "AQ==",
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/03-light-clients/04-wasm/06-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ The `08-wasm` module emits the following events:

| Type | Attribute Key | Attribute Value |
|------------------|----------------|------------------------|
| store_wasm_code | wasm_code_hash | {hex.Encode(codeHash)} |
| store_wasm_code | wasm_checksum | {hex.Encode(checksum)} |
| message | module | 08-wasm |

## `MsgMigrateContract`

| Type | Attribute Key | Attribute Value |
|------------------|----------------|---------------------------|
| migrate_contract | client_id | {clientId} |
| migrate_contract | wasm_code_hash | {hex.Encode(codeHash)} |
| migrate_contract | new_code_hash | {hex.Encode(newCodeHash)} |
| migrate_contract | wasm_checksum | {hex.Encode(checksum)} |
| migrate_contract | new_checksum | {hex.Encode(newChecksum)} |
| message | module | 08-wasm |
2 changes: 1 addition & 1 deletion docs/docs/03-light-clients/04-wasm/07-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ The `08-wasm` proxy light client modules expects the following behaviour from th

- 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 code hash in the client state.
- 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.
26 changes: 13 additions & 13 deletions docs/docs/03-light-clients/04-wasm/08-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ The `query` commands allow users to query `08-wasm` state.
simd query ibc-wasm --help
```

#### `code-hashes`
#### `checksums`

The `code-hashes` command allows users to query the list of code hashes of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`. The code hashes are hex-encoded.
The `checksums` command allows users to query the list of checksums of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`. The checksums are hex-encoded.

```shell
simd query ibc-wasm code-hashes [flags]
simd query ibc-wasm checksums [flags]
```

Example:

```shell
simd query ibc-wasm code-hashes
simd query ibc-wasm checksums
```

Example Output:

```shell
code_hashes:
checksums:
- c64f75091a6195b036f472cd8c9f19a56780b9eac3c3de7ced0ec2e29e985b64
pagination:
next_key: null
Expand All @@ -63,7 +63,7 @@ pagination:

#### `code`

The `code` command allows users to query the Wasm byte code of a light client contract given the provided input code hash.
The `code` command allows users to query the Wasm byte code of a light client contract given the provided input checksum.

```shell
./simd q ibc-wasm code
Expand All @@ -85,12 +85,12 @@ code: AGFzb...AqBBE=

A user can query the `08-wasm` module using gRPC endpoints.

### `CodeHashes`
### `Checksums`

The `CodeHashes` endpoint allows users to query the list of code hashes of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`.
The `Checksums` endpoint allows users to query the list of checksums of Wasm light client contracts stored in the Wasm VM via the `MsgStoreCode`.

```shell
ibc.lightclients.wasm.v1.Query/CodeHashes
ibc.lightclients.wasm.v1.Query/Checksums
```

Example:
Expand All @@ -99,14 +99,14 @@ Example:
grpcurl -plaintext \
-d '{}' \
localhost:9090 \
ibc.lightclients.wasm.v1.Query/CodeHashes
ibc.lightclients.wasm.v1.Query/Checksums
```

Example output:

```shell
{
"codeIds": [
"checksums": [
"c64f75091a6195b036f472cd8c9f19a56780b9eac3c3de7ced0ec2e29e985b64"
],
"pagination": {
Expand All @@ -117,7 +117,7 @@ Example output:

### `Code`

The `Code` endpoint allows users to query the Wasm byte code of a light client contract given the provided input code hash.
The `Code` endpoint allows users to query the Wasm byte code of a light client contract given the provided input checksum.

```shell
ibc.lightclients.wasm.v1.Query/Code
Expand All @@ -127,7 +127,7 @@ Example:

```shell
grpcurl -plaintext \
-d '{"code_hash":"c64f75091a6195b036f472cd8c9f19a56780b9eac3c3de7ced0ec2e29e985b64"}' \
-d '{"checksum":"c64f75091a6195b036f472cd8c9f19a56780b9eac3c3de7ced0ec2e29e985b64"}' \
localhost:9090 \
ibc.lightclients.wasm.v1.Query/Code
```
Expand Down

0 comments on commit 99fbe68

Please sign in to comment.