Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New messaging specification (replacing old deposit/withdrawal spec) #318

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
485e72f
Replaced deposit ID concept with message ID
pixelcircuits May 20, 2022
13324bf
Update message ID generation
pixelcircuits May 23, 2022
0a1eaa7
Added owner and amount to messageID
pixelcircuits May 24, 2022
8e5ebfb
Added InputMessage and OutputMessage
pixelcircuits May 24, 2022
5259dc5
Updated with MessageInput/Output
pixelcircuits May 24, 2022
e06bcb5
fixed markdown link
pixelcircuits May 24, 2022
53dead2
fixed typo
pixelcircuits May 24, 2022
54a63db
Added InputMessage and OutputMessage
pixelcircuits May 24, 2022
31610f9
Fixed markdown links
pixelcircuits May 24, 2022
8065d96
Added SMO opcode
pixelcircuits May 25, 2022
d473743
Added notes to OutputMessage
pixelcircuits May 25, 2022
1e83cf8
reworded abi to data
pixelcircuits Jun 3, 2022
addfe76
Reworded abi to data
pixelcircuits Jun 3, 2022
d6d896a
Added dataLength to messages
pixelcircuits Jun 3, 2022
0993005
Merge branch 'master' into pixelcircuits-refactor-depositwithdraw-to-…
pixelcircuits Jun 6, 2022
e2d4423
Apply suggestions from code review
pixelcircuits Jun 7, 2022
36108d0
Messaging feedback updates
pixelcircuits Jun 7, 2022
9ee74f2
Make message data easier to parse
pixelcircuits Jun 7, 2022
e528991
Updated orders
pixelcircuits Jun 8, 2022
76cba5f
Updated OutputMessage
pixelcircuits Jun 11, 2022
978df96
Fixed link
pixelcircuits Jun 11, 2022
3a5b96e
Spec review changes
pixelcircuits Jun 11, 2022
206635a
Spec changes from feedback
pixelcircuits Jun 12, 2022
142fe9f
Merge branch 'master' into pixelcircuits-refactor-depositwithdraw-to-…
pixelcircuits Jun 12, 2022
d895e1d
Added extra panic scenario
pixelcircuits Jun 14, 2022
d86b788
Apply suggestions from code review
pixelcircuits Jun 14, 2022
64e1801
Added message nonce definition
pixelcircuits Jun 14, 2022
27c55a5
split message id to input and output
pixelcircuits Jun 15, 2022
8e83d05
updated message hash order
pixelcircuits Jun 15, 2022
eba0b42
Update specs/protocol/identifiers.md
pixelcircuits Jun 16, 2022
5ad5b9e
Corrected panic case
pixelcircuits Jun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions specs/protocol/identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
- [Contract ID](#contract-id)
- [UTXO ID](#utxo-id)
- [Coin ID](#coin-id)
- [Deposit ID](#deposit-id)
- [Deposit Asset ID](#deposit-asset-id)
- [Message ID](#message-id)
- [Fee ID](#fee-id)

This document defines how to compute unique identifiers.
Expand All @@ -24,14 +23,9 @@ For a transaction of type `TransactionType.Create`, `tx`, the contract ID is `sh

Is represented as an _outpoint_: a pair of [transaction ID](#transaction-id) as `byte[32]` and output index as a `uint8`.

### Message ID

### Deposit ID

The ID of a deposit is computed as the [hash](./cryptographic_primitives.md#hashing) of the [Deposit Asset ID](#deposit-asset-id) `byte[32]`, recipient address `byte[32]`, amount `uint64` and deposit nonce `uint64`: `hash(byte[32] ++ byte[32] ++ uint64 ++ uint64)`. All value types are serialized according to the standard [transaction serialization](./tx_format.md#transaction).

#### Deposit Asset ID

The ID of a deposit asset is computed as the [hash](./cryptographic_primitives.md#hashing) of the token address `byte[32]` and token precision `uint8`: `hash(byte[32] ++ uint8)`. The address value is serialized as a byte array of length 32 left-padded with zeroes, and all other value types are serialized according to the standard [transaction serialization](./tx_format.md#transaction).
The ID of a message is computed as the [hash](./cryptographic_primitives.md#hashing) of the sender address `byte[32]`, recipient address `byte[32]`, the abi encoded message (either [EVM abi](https://docs.soliditylang.org/en/v0.8.13/abi-spec.html) or [FuelVM abi](./abi.md)) `byte[]`, the amount being sent with the message `uint64`, the message nonce `uint64` and the message owner (either address or predicate hash) `byte[32]`: `hash(byte[32] ++ byte[32] ++ byte[] ++ uint64 ++ uint64 ++ byte[32])`. The address values are serialized as a byte array of length 32 left-padded with zeroes, and all other value types are serialized according to the standard [transaction serialization](./tx_format.md#transaction). If the owner component is not applicable then a 32 byte long array of zeros should be used.

### Fee ID

Expand Down
55 changes: 43 additions & 12 deletions specs/protocol/tx_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
- [InputType](#inputtype)
- [Input](#input)
- [InputCoin](#inputcoin)
- [InputContract](#inputcontract)
- [fInputContract](#inputcontract)
- [InputMessage](#inputmessage)
- [OutputType](#outputtype)
- [Output](#output)
- [OutputCoin](#outputcoin)
- [OutputContract](#outputcontract)
- [OutputWithdrawal](#outputwithdrawal)
- [OutputMessage](#outputmessage)
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved
- [OutputChange](#outputchange)
- [OutputVariable](#outputvariable)
- [OutputContractCreated](#outputcontractcreated)
Expand Down Expand Up @@ -170,6 +171,7 @@ Creates a contract with contract ID as computed [here](./identifiers.md#contract
enum InputType : uint8 {
Coin = 0,
Contract = 1,
Message = 2
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expand All @@ -178,7 +180,7 @@ enum InputType : uint8 {
| name | type | description |
|--------|-------------------------------------------------------------------|----------------|
| `type` | [InputType](#inputtype) | Type of input. |
| `data` | One of [InputCoin](#inputcoin) or [InputContract](#inputcontract) | Input data. |
| `data` | One of [InputCoin](#inputcoin), [InputContract](#inputcontract) or [InputMessage](#inputmessage) | Input data. |
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved

Transaction is invalid if:

Expand Down Expand Up @@ -239,13 +241,39 @@ Note: when verifying a predicate, `txID`, `outputIndex`, `balanceRoot`, `stateRo

Note: when executing a script, `txID`, `outputIndex`, `balanceRoot`, and `stateRoot` are initialized to the transaction ID, output index, amount, and state root of the contract with ID `contractID`, and `txPointer` is initialized to zero.

### InputMessage

| name | type | description |
|-----------------------|-------------|------------------------------------------------------------------------|
| `messageID` | `byte[32]` | The messageID as described [here](./identifiers.md#message-id). |
| `sender` | `byte[32]` | The address of the message sender. |
| `recipient` | `byte[32]` | The address of the message recipient. |
| `callABI` | `byte[]` | The [abi encoded](./abi.md) call to execute. |
| `amount` | `uint64` | Amount of base asset coins sent with message. |
| `nonce` | `uint64` | The message nonce. |
| `owner` | `byte[32]` | Owning address or predicate hash. |
| `witnessIndex` | `uint8` | Index of witness that authorizes spending the coin. |
| `predicateLength` | `uint16` | Length of predicate, in instructions. |
| `predicateDataLength` | `uint16` | Length of predicate input data, in bytes. |
| `predicate` | `byte[]` | Predicate bytecode. |
| `predicateData` | `byte[]` | Predicate input data (parameters). |

Transaction is invalid if:
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved

- `witnessIndex >= tx.witnessesCount`
- `predicateLength > MAX_PREDICATE_LENGTH`
- `predicateDataLength > MAX_PREDICATE_DATA_LENGTH`
- If `predicateLength > 0`; the computed predicate root (see below) is not equal `owner`

Note: the predicate root is computed identically to the contract ID, [here](./identifiers.md#contract-id).
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved

## OutputType

```
enum OutputType : uint8 {
Coin = 0,
Contract = 1,
Withdrawal = 2,
Message = 2,
Change = 3,
Variable = 4,
ContractCreated = 5,
Expand All @@ -257,7 +285,7 @@ enum OutputType : uint8 {
| name | type | description |
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| `type` | [OutputType](#outputtype) | Type of output. |
| `data` | One of [OutputCoin](#outputcoin), [OutputContract](#outputcontract), [OutputWithdrawal](#outputwithdrawal) [OutputChange](#outputchange), [OutputVariable](#outputvariable), or [OutputContractCreated](#outputcontractcreated). | Output data. |
| `data` | One of [OutputCoin](#outputcoin), [OutputContract](#outputcontract), [OutputMessage](#outputmessage) [OutputChange](#outputchange), [OutputVariable](#outputvariable), or [OutputContractCreated](#outputcontractcreated). | Output data. |

Transaction is invalid if:

Expand Down Expand Up @@ -294,15 +322,18 @@ The balance root `balanceRoot` is the root of the [SMT](./cryptographic_primitiv

The state root `stateRoot` is the root of the [SMT](./cryptographic_primitives.md#sparse-merkle-tree) of storage slots. Each storage slot is a `byte[32]`, keyed by a `byte[32]`.

### OutputWithdrawal
### OutputMessage

| name | type | description |
|------------|------------|------------------------------|
| `to` | `byte[32]` | Receiving address. |
| `amount` | `uint64` | Amount of coins to withdraw. |
| `asset_id` | `byte[32]` | Asset ID of coins. |
| name | type | description |
|-----------------------|-------------|-------------------------------------------------------------------------|
| `messageID` | `byte[32]` | The messageID as described [here](./identifiers.md#message-id). |
pixelcircuits marked this conversation as resolved.
Show resolved Hide resolved
| `sender` | `byte[32]` | The address of the message sender. |
| `recipient` | `byte[32]` | The address of the message recipient. |
| `callABI` | `byte[]` | The [abi encoded]([./abi.md](https://docs.soliditylang.org/en/v0.8.13/abi-spec.html)) call to execute. |
| `amount` | `uint64` | Amount of base asset coins sent with message. |
| `nonce` | `uint64` | The message nonce. |

This output type is unspendable and can be pruned form the UTXO set.
This output type is unspendable and can be pruned from the UTXO set.

### OutputChange

Expand Down
4 changes: 2 additions & 2 deletions specs/protocol/tx_validity.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ For each asset ID `asset_id` in the input and output set:
def sum_inputs(tx, col) -> int:
total: int = 0
for input in tx.inputs:
if input.type == InputType.Coin and input.asset_id == col:
if (input.type == InputType.Coin and input.asset_id == col) or (input.type == InputType.Message and col == 0):
adlerjohn marked this conversation as resolved.
Show resolved Hide resolved
total += input.amount
return total

def sum_outputs(tx, col) -> int:
total: int = 0
for output in tx.outputs:
if (output.type == OutputType.Coin or output.type == OutputType.Withdrawal) and output.asset_id == col:
if (output.type == OutputType.Coin and output.asset_id == col) or (output.type == OutputType.Message and col == 0):
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
total += output.amount
return total

Expand Down