Skip to content

Commit

Permalink
better format doc and table; change terminology 'lite-data' to 'compact'
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Oct 3, 2024
1 parent 67456f7 commit c292962
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
4 changes: 0 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
* [2853](https://github.com/zeta-chain/node/pull/2853) - calling precompile through sc with sc state update
* [2925](https://github.com/zeta-chain/node/pull/2925) - add recover to init chainer to diplay informative message when starting a node from block 1

### Docs

* [2963](https://github.com/zeta-chain/node/pull/2963) - added doc for design of non-evm chain inbound memo format.

## v20.0.0

### Features
Expand Down
44 changes: 22 additions & 22 deletions docs/rfc/002_standard_memo_format.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 style="text-align: center;">A proposed standard memo format for non-EVM chains</h1>
# A proposed standard memo format for non-EVM chains
<br>

## The goal
Expand Down Expand Up @@ -26,10 +26,10 @@ event Deposited(
);
event Called(
address indexed sender,
address indexed receiver,
bytes payload,
RevertOptions revertOptions
address indexed sender,
address indexed receiver,
bytes payload,
RevertOptions revertOptions
);
```
<br><br>
Expand Down Expand Up @@ -72,8 +72,9 @@ The ASCII code `0x5A` of letter `'Z'` is used as the identifier of the standard
| | bit 5 ~ 7 | bit 3 ~ 4 | bit 0 ~ 2 |
|-----------------|---------------------------------|--------------------------------|----------------------------------------------------------|
| **Name** | version # | encoding flag | operation code |
| | | | No for non-contract chains; Ignored for contract chains |
| **Optional** | No (0b000 for now) | No (0b00 or 0b01 or 0b10) | The operation code is already differentiated by method names in contract based chains |
| **Optional** | No (0b000 for now) | No (0b00 or 0b01 or 0b10) | for non-contract chains; Ignored for contract chains. The operation code is already differentiated by method names in contract based |
<br>



### `byte-2`: Data Flags
Expand All @@ -91,23 +92,23 @@ The `operation code` is designed for the developers to explicitly specify the in
| 0b000 | 0b001 | 0b010 |
|------------|------------------|------------|
| deposit | deposit_and_call | call |

<br>


Supported `encoding flags`:
This flag is to tell `zetaclient` how the memo fields should be decoded. A 2-bit weight flag seems good enough and won’t change in future.
This flag is to tell `zetaclient` how the memo fields should be decoded. A 2-bit weight flag seems good enough and won’t change in future.<br>
Note: the `compact *` encoding is to minimizes length of memo data (compared to ABI) and will be explained in following sections.

| 0b00 | 0b01 | 0b10 |
|--------------|------------------|------------------|
| ABI encoded | lite-data short | lite-data long |
| 0b00 | 0b01 | 0b10 |
|--------------|----------------|--------------|
| ABI encoded | compact short | compact long |
<br><br>


## 4. The types

To decode/encode the memo fields with the lite-date format, we've defined a few types below.
To decode/encode the memo fields with ABI format, just follow the [ABI Spec](https://docs.soliditylang.org/en/develop/abi-spec.html).
To decode/encode the memo fields with `compact *` format, we've defined a few types below.
To decode/encode the memo fields with `ABI encoded` format, just follow the [ABI Spec](https://docs.soliditylang.org/en/develop/abi-spec.html).


| Field | Size (byte) | Description |
Expand All @@ -120,12 +121,11 @@ To decode/encode the memo fields with ABI format, just follow the [ABI Spec](htt

## 5. Byte layout of variable-length types

There are two ways to encode your the memo fields into raw bytes. The `ABI encoded` and `lite-data` encoded.

| Decoding flag | Format | Layout | Description | Rule |
|---------------|-------------------|-----------------------------------------|-----------------------------------------------|----------------------------------------------------------|
| 0b00 | ABI encoded | ABI encoded types | Types are packed/unpacked with ABI standard | [ABI Spec](https://docs.soliditylang.org/en/develop/abi-spec.html) |
| 0b01 | lite-data short | [1-byte length] + [data] | Carry up to 255 bytes of data. | A valid length must > 0 and match data length. |
| 0b10 | lite-data long | [2-byte length, little-endian] + [data] | Carry up to 65535 bytes (64KB) of data. | A valid length must > 0 and match data length. |

There are two ways to encode your the memo fields into raw bytes. The `ABI encoded` and `compact *` encoded.

| Decoding flag | Format | Layout | Description | Rule |
|---------------|---------------|-----------------------------------------|-----------------------------------------------|----------------------------------------------------------|
| 0b00 | ABI encoded | ABI encoded types | Types are packed/unpacked with ABI standard | [ABI Spec](https://docs.soliditylang.org/en/develop/abi-spec.html) |
| 0b01 | compact short | [1-byte length] + [data] | Carry up to 255 bytes of data. | A valid length must > 0 and match data length. |
| 0b10 | compact long | [2-byte length, little-endian] + [data] | Carry up to 65535 bytes (64KB) of data. | A valid length must > 0 and match data length. |
|

0 comments on commit c292962

Please sign in to comment.