From 1f147486fccf4557c5cfd74f4a4f47a244e6393c Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 8 Mar 2019 09:57:09 +0100 Subject: [PATCH 1/6] Semantic fork versions and signature domains Fix #706 --- specs/core/0_beacon-chain.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 898fc3c86..cfa4782a5 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -268,12 +268,12 @@ Code snippets appearing in `this style` are to be interpreted as Python code. | Name | Value | | - | - | -| `DOMAIN_BEACON_BLOCK` | `0` | -| `DOMAIN_RANDAO` | `1` | -| `DOMAIN_ATTESTATION` | `2` | -| `DOMAIN_DEPOSIT` | `3` | -| `DOMAIN_VOLUNTARY_EXIT` | `4` | -| `DOMAIN_TRANSFER` | `5` | +| `DOMAIN_BEACON_BLOCK` | `int_to_bytes4(0)` | +| `DOMAIN_RANDAO` | `int_to_bytes4(1)` | +| `DOMAIN_ATTESTATION` | `int_to_bytes4(2)` | +| `DOMAIN_DEPOSIT` | `int_to_bytes4(3)` | +| `DOMAIN_VOLUNTARY_EXIT` | `int_to_bytes4(4)` | +| `DOMAIN_TRANSFER` | `int_to_bytes4(5)` | ## Data structures @@ -288,9 +288,9 @@ The types are defined topologically to aid in facilitating an executable version ```python { # Previous fork version - 'previous_version': 'uint64', + 'previous_version': 'bytes4', # Current fork version - 'current_version': 'uint64', + 'current_version': 'bytes4', # Fork epoch number 'epoch': 'uint64', } @@ -1107,7 +1107,7 @@ def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> G ```python def get_fork_version(fork: Fork, - epoch: Epoch) -> int: + epoch: Epoch) -> bytes8: """ Return the fork version of the given ``epoch``. """ @@ -1122,12 +1122,11 @@ def get_fork_version(fork: Fork, ```python def get_domain(fork: Fork, epoch: Epoch, - domain_type: int) -> int: + domain_type: bytes4) -> bytes8: """ Get the domain number that represents the fork meta and signature domain. """ - fork_version = get_fork_version(fork, epoch) - return fork_version * 2**32 + domain_type + return get_fork_version(fork, epoch) + domain_type ``` ### `get_bitfield_bit` From a51d7d5db591ada9b7ae01ba37fe4fecf6ca0653 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 8 Mar 2019 10:50:45 +0100 Subject: [PATCH 2/6] Update 0_beacon-chain.md --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index cfa4782a5..7b7c58ab0 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1107,7 +1107,7 @@ def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> G ```python def get_fork_version(fork: Fork, - epoch: Epoch) -> bytes8: + epoch: Epoch) -> bytes4: """ Return the fork version of the given ``epoch``. """ From 3aedf1226a5913b3545f35cefcca058a9dfdf9a1 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 8 Mar 2019 17:36:58 +0100 Subject: [PATCH 3/6] Update 0_beacon-chain.md Did I get the type casting OK @hwwhww? --- specs/core/0_beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7b7c58ab0..9efc73f1a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1122,11 +1122,11 @@ def get_fork_version(fork: Fork, ```python def get_domain(fork: Fork, epoch: Epoch, - domain_type: bytes4) -> bytes8: + domain_type: bytes4) -> uint64: """ Get the domain number that represents the fork meta and signature domain. """ - return get_fork_version(fork, epoch) + domain_type + return bytes_to_int(get_fork_version(fork, epoch) + domain_type)) ``` ### `get_bitfield_bit` From ecd93468a233ba54af5a7a1492a195c4b3a18db1 Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 8 Mar 2019 17:38:19 +0100 Subject: [PATCH 4/6] Update 0_beacon-chain.md --- specs/core/0_beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 9efc73f1a..900708e7a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1122,7 +1122,7 @@ def get_fork_version(fork: Fork, ```python def get_domain(fork: Fork, epoch: Epoch, - domain_type: bytes4) -> uint64: + domain_type: bytes4) -> int: """ Get the domain number that represents the fork meta and signature domain. """ From d8a3048f2c119687e92072fe797fa1d377b3948f Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 12 Mar 2019 12:36:09 +0000 Subject: [PATCH 5/6] Update 0_beacon-chain.md --- specs/core/0_beacon-chain.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 900708e7a..b2696892f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -268,12 +268,12 @@ Code snippets appearing in `this style` are to be interpreted as Python code. | Name | Value | | - | - | -| `DOMAIN_BEACON_BLOCK` | `int_to_bytes4(0)` | -| `DOMAIN_RANDAO` | `int_to_bytes4(1)` | -| `DOMAIN_ATTESTATION` | `int_to_bytes4(2)` | -| `DOMAIN_DEPOSIT` | `int_to_bytes4(3)` | -| `DOMAIN_VOLUNTARY_EXIT` | `int_to_bytes4(4)` | -| `DOMAIN_TRANSFER` | `int_to_bytes4(5)` | +| `DOMAIN_BEACON_BLOCK` | `0` | +| `DOMAIN_RANDAO` | `1` | +| `DOMAIN_ATTESTATION` | `2` | +| `DOMAIN_DEPOSIT` | `3` | +| `DOMAIN_VOLUNTARY_EXIT` | `4` | +| `DOMAIN_TRANSFER` | `5` | ## Data structures @@ -1107,7 +1107,7 @@ def get_total_balance(state: BeaconState, validators: List[ValidatorIndex]) -> G ```python def get_fork_version(fork: Fork, - epoch: Epoch) -> bytes4: + epoch: Epoch) -> bytes: """ Return the fork version of the given ``epoch``. """ @@ -1122,11 +1122,11 @@ def get_fork_version(fork: Fork, ```python def get_domain(fork: Fork, epoch: Epoch, - domain_type: bytes4) -> int: + domain_type: int) -> int: """ Get the domain number that represents the fork meta and signature domain. """ - return bytes_to_int(get_fork_version(fork, epoch) + domain_type)) + return bytes_to_int(get_fork_version(fork, epoch) + int_to_bytes4(domain_type)) ``` ### `get_bitfield_bit` From a68b050053bcb08b5c0faa14348ecc88773dd137 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 12 Mar 2019 11:35:59 -0600 Subject: [PATCH 6/6] set fork values in genesis as bytes4 --- specs/core/0_beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 21bf3e7a6..bb3d5269c 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1517,8 +1517,8 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit], slot=GENESIS_SLOT, genesis_time=genesis_time, fork=Fork( - previous_version=GENESIS_FORK_VERSION, - current_version=GENESIS_FORK_VERSION, + previous_version=int_to_bytes4(GENESIS_FORK_VERSION), + current_version=int_to_bytes4(GENESIS_FORK_VERSION), epoch=GENESIS_EPOCH, ),