From 66cf4e95c149fe156adf46db377a62aa66456283 Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Fri, 19 Apr 2019 18:43:26 +0300 Subject: [PATCH 1/3] Added signing_root to ssz_static tests --- test_generators/ssz_static/README.md | 17 +++++++++++++++++ test_generators/ssz_static/main.py | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test_generators/ssz_static/README.md b/test_generators/ssz_static/README.md index 014c71517..01892ecc2 100644 --- a/test_generators/ssz_static/README.md +++ b/test_generators/ssz_static/README.md @@ -2,3 +2,20 @@ The purpose of this test-generator is to provide test-vectors for the most important applications of SSZ: the serialization and hashing of ETH 2.0 data types + +#### Test case +Example: +```yaml +- type_name: DepositData + value: {pubkey: '0x364194dbcda9974ec8e57aa0d556ced515e43ce450e21aa8f9b2099a528679fcf45aed142db60b7f848bd399b63f0933', + withdrawal_credentials: '0xad1256c89ae823b24e1d81fae3d3d382d60012d8399f469ff404e3bbf908027a', + amount: 2672254660871140633, signature: '0x5c3fe3bdbf58d0fb4cdb63a19a67082c697ef910c182dc824c8fb048c935b4b46f522c36047ae36feef84654c1e868f3a0edd76852c09e35414782160767439b49aceaa4219cc25016effcc82a9e17b336efee40ab37e3a47fc31da557027491'} + serialized: '0x364194dbcda9974ec8e57aa0d556ced515e43ce450e21aa8f9b2099a528679fcf45aed142db60b7f848bd399b63f0933ad1256c89ae823b24e1d81fae3d3d382d60012d8399f469ff404e3bbf908027a19359bb274c115255c3fe3bdbf58d0fb4cdb63a19a67082c697ef910c182dc824c8fb048c935b4b46f522c36047ae36feef84654c1e868f3a0edd76852c09e35414782160767439b49aceaa4219cc25016effcc82a9e17b336efee40ab37e3a47fc31da557027491' + root: '0x2eaae270579fc1a1eabde69c841221cb3dfab9de7ad99fcfbee8fe0c198878b7' + signing_root: '0x844655facb151b633410ffc698d8467c6488ae87f2d5f739d39c9bfc18750524' +``` +**type_name** - Name of valid Eth2.0 type from the spec +**value** - Field values used to create type instance +**serialized** - [SSZ serialization](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#serialization) of the value +**root** - [hash_tree_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#merkleization) of the value +**signing_root** - (Optional) [signing_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#self-signed-containers) of the value, if type contains ``signature`` field \ No newline at end of file diff --git a/test_generators/ssz_static/main.py b/test_generators/ssz_static/main.py index 010ca2735..1234294db 100644 --- a/test_generators/ssz_static/main.py +++ b/test_generators/ssz_static/main.py @@ -2,7 +2,11 @@ from random import Random from eth2spec.debug import random_value, encode from eth2spec.phase0 import spec -from eth2spec.utils.minimal_ssz import hash_tree_root, serialize +from eth2spec.utils.minimal_ssz import ( + hash_tree_root, + signing_root, + serialize, +) from eth_utils import ( to_tuple, to_dict ) @@ -21,6 +25,8 @@ def create_test_case(rng: Random, name: str, mode: random_value.RandomizationMod yield "value", encode.encode(value, typ) yield "serialized", '0x' + serialize(value).hex() yield "root", '0x' + hash_tree_root(value).hex() + if hasattr(value, "signature"): + yield "signing_root", '0x' + signing_root(value).hex() @to_tuple From 04d498695e680e2c4c7a8b575bdd73e4f0265f85 Mon Sep 17 00:00:00 2001 From: protolambda Date: Mon, 22 Apr 2019 14:01:04 +1000 Subject: [PATCH 2/3] update test format docs --- specs/test_formats/ssz_static/core.md | 9 +++++++++ test_generators/ssz_static/README.md | 17 +---------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/specs/test_formats/ssz_static/core.md b/specs/test_formats/ssz_static/core.md index 8a5067f03..ee712a830 100644 --- a/specs/test_formats/ssz_static/core.md +++ b/specs/test_formats/ssz_static/core.md @@ -13,6 +13,7 @@ type_name: string -- string, object name, formatted as in spec. E.g. "BeaconBlo value: dynamic -- the YAML-encoded value, of the type specified by type_name. serialized: bytes -- string, SSZ-serialized data, hex encoded, with prefix 0x root: bytes32 -- string, hash-tree-root of the value, hex encoded, with prefix 0x +signing_root: bytes32 -- string, signing-root of the value, hex encoded, with prefix 0x. Optional, present if type contains ``signature`` field ``` ## Condition @@ -20,4 +21,12 @@ root: bytes32 -- string, hash-tree-root of the value, hex encoded, with pre A test-runner can implement the following assertions: - Serialization: After parsing the `value`, SSZ-serialize it: the output should match `serialized` - Hash-tree-root: After parsing the `value`, Hash-tree-root it: the output should match `root` + - Optionally also check signing-root, if present. - Deserialization: SSZ-deserialize the `serialized` value, and see if it matches the parsed `value` + +## References + + +**`serialized`**: [SSZ serialization](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#serialization) +**`root`** - [hash_tree_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#merkleization) +**`signing_root`** - [signing_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#self-signed-containers) diff --git a/test_generators/ssz_static/README.md b/test_generators/ssz_static/README.md index 01892ecc2..d73556e1b 100644 --- a/test_generators/ssz_static/README.md +++ b/test_generators/ssz_static/README.md @@ -3,19 +3,4 @@ The purpose of this test-generator is to provide test-vectors for the most important applications of SSZ: the serialization and hashing of ETH 2.0 data types -#### Test case -Example: -```yaml -- type_name: DepositData - value: {pubkey: '0x364194dbcda9974ec8e57aa0d556ced515e43ce450e21aa8f9b2099a528679fcf45aed142db60b7f848bd399b63f0933', - withdrawal_credentials: '0xad1256c89ae823b24e1d81fae3d3d382d60012d8399f469ff404e3bbf908027a', - amount: 2672254660871140633, signature: '0x5c3fe3bdbf58d0fb4cdb63a19a67082c697ef910c182dc824c8fb048c935b4b46f522c36047ae36feef84654c1e868f3a0edd76852c09e35414782160767439b49aceaa4219cc25016effcc82a9e17b336efee40ab37e3a47fc31da557027491'} - serialized: '0x364194dbcda9974ec8e57aa0d556ced515e43ce450e21aa8f9b2099a528679fcf45aed142db60b7f848bd399b63f0933ad1256c89ae823b24e1d81fae3d3d382d60012d8399f469ff404e3bbf908027a19359bb274c115255c3fe3bdbf58d0fb4cdb63a19a67082c697ef910c182dc824c8fb048c935b4b46f522c36047ae36feef84654c1e868f3a0edd76852c09e35414782160767439b49aceaa4219cc25016effcc82a9e17b336efee40ab37e3a47fc31da557027491' - root: '0x2eaae270579fc1a1eabde69c841221cb3dfab9de7ad99fcfbee8fe0c198878b7' - signing_root: '0x844655facb151b633410ffc698d8467c6488ae87f2d5f739d39c9bfc18750524' -``` -**type_name** - Name of valid Eth2.0 type from the spec -**value** - Field values used to create type instance -**serialized** - [SSZ serialization](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#serialization) of the value -**root** - [hash_tree_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#merkleization) of the value -**signing_root** - (Optional) [signing_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#self-signed-containers) of the value, if type contains ``signature`` field \ No newline at end of file +Test-format documentation can be found [here](../../specs/test_formats/ssz_static/README.md). From 7043bb90800b2be43781e36b6f87472bf0e38eba Mon Sep 17 00:00:00 2001 From: Dmitrii Shmatko Date: Mon, 22 Apr 2019 12:09:56 +0300 Subject: [PATCH 3/3] test: clean up of ssz_static references styling --- specs/test_formats/ssz_static/core.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/test_formats/ssz_static/core.md b/specs/test_formats/ssz_static/core.md index ee712a830..059f11027 100644 --- a/specs/test_formats/ssz_static/core.md +++ b/specs/test_formats/ssz_static/core.md @@ -28,5 +28,5 @@ A test-runner can implement the following assertions: **`serialized`**: [SSZ serialization](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#serialization) -**`root`** - [hash_tree_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#merkleization) -**`signing_root`** - [signing_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#self-signed-containers) +**`root`** - [hash_tree_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#merkleization) function +**`signing_root`** - [signing_root](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/simple-serialize.md#self-signed-containers) function