From 1644ae61255ce25ddc318a299ab0a67e42b068ee Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 10 Jul 2019 16:46:59 +0800 Subject: [PATCH 1/4] Clarify the illegal types --- specs/simple-serialize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 8efd08c0a..0419a524e 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -89,7 +89,7 @@ An SSZ object is called empty (and thus, `is_empty(object)` returns true) if it ### Illegal types -Empty vector types (i.e. `[subtype, 0]` for some `subtype`) are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). +The empty `List[subtype, N]`, `Vector[subtype, N]`, `Bitlist[N]`, and `Bitvector[N]` types, where `N == 0` are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). ## Serialization From 25ec084cc58e97f9c797068c1cd65013b8b7e0be Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 10 Jul 2019 17:20:50 +0800 Subject: [PATCH 2/4] To fit in `MAX_TRANSFERS=0` case --- specs/simple-serialize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 0419a524e..db7b5ad75 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -89,7 +89,7 @@ An SSZ object is called empty (and thus, `is_empty(object)` returns true) if it ### Illegal types -The empty `List[subtype, N]`, `Vector[subtype, N]`, `Bitlist[N]`, and `Bitvector[N]` types, where `N == 0` are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). +The empty `Vector[subtype, N]` and `Bitvector[N]` types, where `N == 0` are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). ## Serialization From 62138fed347aed04833e7c25d2a4aa802ae4cfb2 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 25 Jul 2019 17:26:27 +0800 Subject: [PATCH 3/4] Update Illegal types --- specs/simple-serialize.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index e62dbcd7f..cfc1a4aa2 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -75,7 +75,7 @@ For convenience we alias: * `bit` to `boolean` * `byte` to `uint8` (this is a basic type) * `BytesN` to `Vector[byte, N]` (this is *not* a basic type) -* `null`: `{}`, i.e. the empty container +* `null`: `{}` ### Default values @@ -87,7 +87,9 @@ An SSZ object is called empty (and thus, `is_empty(object)` returns true) if it ### Illegal types -The empty `Vector[subtype, N]` and `Bitvector[N]` types, where `N == 0` are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). +- Empty vector types (`Vector[type, 0]`, `Bitvector[0]`) are illegal. +- Containers with no fields are illegal. +- The `null` type is only legal as the first type in a union subtype (i.e. with type index zero). ## Serialization From f336e7ffb33e736b6f201d98562c833e1e0b5611 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 25 Jul 2019 17:32:27 +0800 Subject: [PATCH 4/4] Rename `is_empty` to `is_zero` --- scripts/build_spec.py | 2 +- specs/core/1_custody-game.md | 2 +- specs/simple-serialize.md | 6 +++--- test_libs/pyspec/eth2spec/utils/ssz/ssz_impl.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 8b541ff50..c221a5fba 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -49,7 +49,7 @@ from eth2spec.utils.ssz.ssz_impl import ( hash_tree_root, signing_root, serialize, - is_empty, + is_zero, ) from eth2spec.utils.ssz.ssz_typing import ( bit, boolean, Container, List, Vector, Bytes, uint64, diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index f79977442..63900681e 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -328,7 +328,7 @@ def get_reveal_period(state: BeaconState, validator_index: ValidatorIndex, epoch ```python def replace_empty_or_append(list: MutableSequence[Any], new_element: Any) -> int: for i in range(len(list)): - if is_empty(list[i]): + if is_zero(list[i]): list[i] = new_element return i list.append(new_element) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index cfc1a4aa2..f479c5d00 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -14,7 +14,7 @@ - [Variable-size and fixed-size](#variable-size-and-fixed-size) - [Aliases](#aliases) - [Default values](#default-values) - - [`is_empty`](#is_empty) + - [`is_zero`](#is_zero) - [Illegal types](#illegal-types) - [Serialization](#serialization) - [`uintN`](#uintn) @@ -81,9 +81,9 @@ For convenience we alias: The default value of a type upon initialization is recursively defined using `0` for `uintN`, `False` for `boolean` and the elements of `Bitvector`, and `[]` for lists and `Bitlist`. Unions default to the first type in the union (with type index zero), which is `null` if present in the union. -#### `is_empty` +#### `is_zero` -An SSZ object is called empty (and thus, `is_empty(object)` returns true) if it is equal to the default value for that type. +An SSZ object is called zeroed (and thus, `is_zero(object)` returns true) if it is equal to the default value for that type. ### Illegal types diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_impl.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_impl.py index b005f2456..748386733 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_impl.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_impl.py @@ -33,7 +33,7 @@ def deserialize_basic(value, typ: BasicType): raise Exception(f"Type not supported: {typ}") -def is_empty(obj: SSZValue): +def is_zero(obj: SSZValue): return type(obj).default() == obj