Merge pull request #723 from dankrad/patch-1

Add tuple lengths; update list typedef format
This commit is contained in:
Danny Ryan 2019-03-06 15:59:32 -07:00 committed by GitHub
commit 55b7064646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 18 deletions

View File

@ -387,7 +387,7 @@ The following data structures are defined as [SimpleSerialize (SSZ)](https://git
```python ```python
{ {
# Branch in the deposit tree # Branch in the deposit tree
'proof': ['bytes32'], 'proof': ['bytes32', DEPOSIT_CONTRACT_TREE_DEPTH],
# Index in the deposit tree # Index in the deposit tree
'index': 'uint64', 'index': 'uint64',
# Data # Data
@ -524,7 +524,7 @@ The following data structures are defined as [SimpleSerialize (SSZ)](https://git
'validator_registry_update_epoch': 'uint64', 'validator_registry_update_epoch': 'uint64',
# Randomness and committees # Randomness and committees
'latest_randao_mixes': ['bytes32'], 'latest_randao_mixes': ['bytes32', LATEST_RANDAO_MIXES_LENGTH],
'previous_shuffling_start_shard': 'uint64', 'previous_shuffling_start_shard': 'uint64',
'current_shuffling_start_shard': 'uint64', 'current_shuffling_start_shard': 'uint64',
'previous_shuffling_epoch': 'uint64', 'previous_shuffling_epoch': 'uint64',
@ -539,10 +539,10 @@ The following data structures are defined as [SimpleSerialize (SSZ)](https://git
'finalized_epoch': 'uint64', 'finalized_epoch': 'uint64',
# Recent state # Recent state
'latest_crosslinks': [Crosslink], 'latest_crosslinks': [Crosslink, SHARD_COUNT],
'latest_block_roots': ['bytes32'], 'latest_block_roots': ['bytes32', SLOTS_PER_HISTORICAL_ROOT],
'latest_active_index_roots': ['bytes32'], 'latest_active_index_roots': ['bytes32', LATEST_ACTIVE_INDEX_ROOTS_LENGTH],
'latest_slashed_balances': ['uint64'], # Balances slashed at every withdrawal period 'latest_slashed_balances': ['uint64', LATEST_SLASHED_EXIT_LENGTH], # Balances slashed at every withdrawal period
'latest_attestations': [PendingAttestation], 'latest_attestations': [PendingAttestation],
'batched_block_roots': ['bytes32'], 'batched_block_roots': ['bytes32'],

View File

@ -10,8 +10,8 @@ This is a **work in progress** describing typing, serialization and Merkleizatio
- [Composite types](#composite-types) - [Composite types](#composite-types)
- [Aliases](#aliases) - [Aliases](#aliases)
- [Serialization](#serialization) - [Serialization](#serialization)
- [`uintN`](#uintn) - [`"uintN"`](#uintn)
- [`bool`](#bool) - [`"bool"`](#bool)
- [Tuples, containers, lists](#tuples-containers-lists) - [Tuples, containers, lists](#tuples-containers-lists)
- [Deserialization](#deserialization) - [Deserialization](#deserialization)
- [Merkleization](#merkleization) - [Merkleization](#merkleization)
@ -28,29 +28,29 @@ This is a **work in progress** describing typing, serialization and Merkleizatio
## Typing ## Typing
### Basic types ### Basic types
* `uintN`: `N`-bit unsigned integer (where `N in [8, 16, 32, 64, 128, 256]`) * `"uintN"`: `N`-bit unsigned integer (where `N in [8, 16, 32, 64, 128, 256]`)
* `bool`: `True` or `False` * `"bool"`: `True` or `False`
### Composite types ### Composite types
* **container**: ordered heterogenous collection of values * **container**: ordered heterogenous collection of values
* key-pair curly bracket notation `{}`, e.g. `{'foo': "uint64", 'bar': "bool"}` * key-pair curly bracket notation `{}`, e.g. `{'foo': "uint64", 'bar': "bool"}`
* **tuple**: ordered fixed-length homogeneous collection of values * **tuple**: ordered fixed-length homogeneous collection of values
* angle bracket notation `[N]`, e.g. `uint64[N]` * angle bracket notation `[type, N]`, e.g. `["uint64", N]`
* **list**: ordered variable-length homogenous collection of values * **list**: ordered variable-length homogenous collection of values
* angle bracket notation `[]`, e.g. `uint64[]` * angle bracket notation `[type]`, e.g. `["uint64"]`
### Aliases ### Aliases
For convenience we alias: For convenience we alias:
* `byte` to `uint8` (this is a basic type) * `"byte"` to `"uint8"` (this is a basic type)
* `bytes` to `byte[]` (this is *not* a basic type) * `"bytes"` to `["byte"]` (this is *not* a basic type)
* `bytesN` to `byte[N]` (this is *not* a basic type) * `"bytesN"` to `["byte", N]` (this is *not* a basic type)
## Serialization ## Serialization
We recursively define the `serialize` function which consumes an object `value` (of the type specified) and returns a bytestring of type `bytes`. We recursively define the `serialize` function which consumes an object `value` (of the type specified) and returns a bytestring of type `"bytes"`.
*Note*: In the function definitions below (`serialize`, `hash_tree_root`, `signed_root`, etc.) objects implicitly carry their type. *Note*: In the function definitions below (`serialize`, `hash_tree_root`, `signed_root`, etc.) objects implicitly carry their type.
@ -95,7 +95,7 @@ We first define helper functions:
* `pack`: Given ordered objects of the same basic type, serialize them, pack them into `BYTES_PER_CHUNK`-byte chunks, right-pad the last chunk with zero bytes, and return the chunks. * `pack`: Given ordered objects of the same basic type, serialize them, pack them into `BYTES_PER_CHUNK`-byte chunks, right-pad the last chunk with zero bytes, and return the chunks.
* `merkleize`: Given ordered `BYTES_PER_CHUNK`-byte chunks, if necessary append zero chunks so that the number of chunks is a power of two, Merkleize the chunks, and return the root. * `merkleize`: Given ordered `BYTES_PER_CHUNK`-byte chunks, if necessary append zero chunks so that the number of chunks is a power of two, Merkleize the chunks, and return the root.
* `mix_in_length`: Given a Merkle root `root` and a length `length` (`uint256` little-endian serialization) return `hash(root + length)`. * `mix_in_length`: Given a Merkle root `root` and a length `length` (`"uint256"` little-endian serialization) return `hash(root + length)`.
We now define Merkleization `hash_tree_root(value)` of an object `value` recursively: We now define Merkleization `hash_tree_root(value)` of an object `value` recursively:
@ -106,7 +106,7 @@ We now define Merkleization `hash_tree_root(value)` of an object `value` recursi
## Self-signed containers ## Self-signed containers
Let `value` be a self-signed container object. The convention is that the signature (e.g. a `bytes96` BLS12-381 signature) be the last field of `value`. Further, the signed message for `value` is `signed_root(value) = hash_tree_root(truncate_last(value))` where `truncate_last` truncates the last element of `value`. Let `value` be a self-signed container object. The convention is that the signature (e.g. a `"bytes96"` BLS12-381 signature) be the last field of `value`. Further, the signed message for `value` is `signed_root(value) = hash_tree_root(truncate_last(value))` where `truncate_last` truncates the last element of `value`.
## Implementations ## Implementations