From ba8c44dd9abfe10f671fb556056e76e88a5946fb Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 19 Jan 2019 15:46:09 +0800 Subject: [PATCH 1/9] Fix the new `Eth1Data` fields to `bytes32` --- 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 0394761ad..3ef3c94e2 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -601,9 +601,9 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # Root of the deposit tree - 'deposit_root': 'hash32', + 'deposit_root': 'bytes32', # Block hash - 'block_hash': 'hash32', + 'block_hash': 'bytes32', } ``` From 41813462c3e3b6af6239fea622cdebccd3761c5c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 19 Jan 2019 15:58:24 +0800 Subject: [PATCH 2/9] Add custom types --- specs/core/0_beacon-chain.md | 59 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 3ef3c94e2..569296b5f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -50,6 +50,7 @@ - [`ValidatorRegistryDeltaBlock`](#validatorregistrydeltablock) - [`Eth1Data`](#eth1data) - [`Eth1DataVote`](#eth1datavote) + - [Custom Types](#custom-types) - [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract) - [Deposit arguments](#deposit-arguments) - [Withdrawal credentials](#withdrawal-credentials) @@ -253,6 +254,8 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ## Data structures +The following data structures are [SimpleSerialize (SSZ)](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md) objects. + ### Beacon chain operations #### Proposer slashings @@ -618,6 +621,20 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted } ``` +## Custom Types + +We define the following Python custom types for type hinting and readability: + +| Name | Type | Description | +| - | - | - | +| `SlotNumber` | unsigned 64-bit integer | the number of a slot | +| `ShardNumber` | unsigned 64-bit integer | the number of a shard | +| `ValidatorIndex` | unsigned 24-bit integer | the index number of validator in the registry | +| `Gwei` | unsigned 64-bit integer | the amount in Gwei | +| `Bytes32` | 32-byte data | the binary data in 32-byte length | +| `BLSPubkey` | 48-byte data | the public key in BLS signature scheme | +| `BLSSignature` | 96-byte data | the signature in BLS signature scheme | + ## Ethereum 1.0 deposit contract The initial deployment phases of Ethereum 2.0 are implemented without consensus changes to Ethereum 1.0. A deposit contract at address `DEPOSIT_CONTRACT_ADDRESS` is added to Ethereum 1.0 for deposits of ETH to the beacon chain. Validator balances will be withdrawable to the shards in phase 2, i.e. when the EVM2.0 is deployed and the shards have state. @@ -788,7 +805,7 @@ Note: We aim to migrate to a S[T/N]ARK-friendly hash function in a future Ethere #### `is_active_validator` ```python -def is_active_validator(validator: Validator, slot: int) -> bool: +def is_active_validator(validator: Validator, slot: SlotNumber) -> bool: """ Checks if ``validator`` is active. """ @@ -798,7 +815,7 @@ def is_active_validator(validator: Validator, slot: int) -> bool: #### `get_active_validator_indices` ```python -def get_active_validator_indices(validators: [Validator], slot: int) -> List[int]: +def get_active_validator_indices(validators: [Validator], slot: SlotNumber) -> List[ValidatorIndex]: """ Gets indices of active validators from ``validators``. """ @@ -890,7 +907,7 @@ def get_committee_count_per_slot(active_validator_count: int) -> int: ```python def get_shuffling(seed: Bytes32, validators: List[Validator], - slot: int) -> List[List[int]] + slot: SlotNumber) -> List[List[ValidatorIndex]] """ Shuffles ``validators`` into crosslink committees seeded by ``seed`` and ``slot``. Returns a list of ``EPOCH_LENGTH * committees_per_slot`` committees where each @@ -942,7 +959,7 @@ def get_current_epoch_committee_count_per_slot(state: BeaconState) -> int: ```python def get_crosslink_committees_at_slot(state: BeaconState, - slot: int) -> List[Tuple[List[int], int]]: + slot: SlotNumber) -> List[Tuple[List[ValidatorIndex], ShardNumber]]: """ Returns the list of ``(committee, shard)`` tuples for the ``slot``. """ @@ -983,7 +1000,7 @@ def get_crosslink_committees_at_slot(state: BeaconState, ```python def get_block_root(state: BeaconState, - slot: int) -> Bytes32: + slot: SlotNumber) -> Bytes32: """ Returns the block root at a recent ``slot``. """ @@ -998,7 +1015,7 @@ def get_block_root(state: BeaconState, ```python def get_randao_mix(state: BeaconState, - slot: int) -> Bytes32: + slot: SlotNumber) -> Bytes32: """ Returns the randao mix at a recent ``slot``. """ @@ -1011,7 +1028,7 @@ def get_randao_mix(state: BeaconState, ```python def get_beacon_proposer_index(state: BeaconState, - slot: int) -> int: + slot: SlotNumber) -> ValidatorIndex: """ Returns the beacon proposer index for the ``slot``. """ @@ -1037,7 +1054,7 @@ def merkle_root(values: List[Bytes32]) -> Bytes32: ```python def get_attestation_participants(state: BeaconState, attestation_data: AttestationData, - aggregation_bitfield: bytes) -> List[int]: + aggregation_bitfield: bytes) -> List[ValidatorIndex]: """ Returns the participant indices at for the ``attestation_data`` and ``aggregation_bitfield``. """ @@ -1065,7 +1082,7 @@ def get_attestation_participants(state: BeaconState, #### `get_effective_balance` ```python -def get_effective_balance(state: State, index: int) -> int: +def get_effective_balance(state: State, index: ValidatorIndex) -> Gwei: """ Returns the effective balance (also known as "balance at stake") for a ``validator`` with the given ``index``. """ @@ -1076,7 +1093,7 @@ def get_effective_balance(state: State, index: int) -> int: ```python def get_fork_version(fork: Fork, - slot: int) -> int: + slot: SlotNumber) -> int: if slot < fork.slot: return fork.previous_version else: @@ -1087,7 +1104,7 @@ def get_fork_version(fork: Fork, ```python def get_domain(fork: Fork, - slot: int, + slot: SlotNumber, domain_type: int) -> int: return get_fork_version( fork, @@ -1294,8 +1311,8 @@ First, a helper function: ```python def validate_proof_of_possession(state: BeaconState, - pubkey: Bytes48, - proof_of_possession: Bytes96, + pubkey: BLSPubkey, + proof_of_possession: BLSSignature, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> bool: @@ -1323,9 +1340,9 @@ Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn ```python def process_deposit(state: BeaconState, - pubkey: Bytes48, - amount: int, - proof_of_possession: Bytes96, + pubkey: BLSPubkey, + amount: Gwei, + proof_of_possession: BLSSignature, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> None: @@ -1379,7 +1396,7 @@ def process_deposit(state: BeaconState, Note: All functions in this section mutate `state`. ```python -def activate_validator(state: BeaconState, index: int, genesis: bool) -> None: +def activate_validator(state: BeaconState, index: ValidatorIndex, genesis: bool) -> None: validator = state.validator_registry[index] validator.activation_slot = GENESIS_SLOT if genesis else (state.slot + ENTRY_EXIT_DELAY) @@ -1395,13 +1412,13 @@ def activate_validator(state: BeaconState, index: int, genesis: bool) -> None: ``` ```python -def initiate_validator_exit(state: BeaconState, index: int) -> None: +def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None: validator = state.validator_registry[index] validator.status_flags |= INITIATED_EXIT ``` ```python -def exit_validator(state: BeaconState, index: int) -> None: +def exit_validator(state: BeaconState, index: ValidatorIndex) -> None: validator = state.validator_registry[index] # The following updates only occur if not previous exited @@ -1424,7 +1441,7 @@ def exit_validator(state: BeaconState, index: int) -> None: ``` ```python -def penalize_validator(state: BeaconState, index: int) -> None: +def penalize_validator(state: BeaconState, index: ValidatorIndex) -> None: exit_validator(state, index) validator = state.validator_registry[index] state.latest_penalized_balances[(state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH] += get_effective_balance(state, index) @@ -1437,7 +1454,7 @@ def penalize_validator(state: BeaconState, index: int) -> None: ``` ```python -def prepare_validator_for_withdrawal(state: BeaconState, index: int) -> None: +def prepare_validator_for_withdrawal(state: BeaconState, index: ValidatorIndex) -> None: validator = state.validator_registry[index] validator.status_flags |= WITHDRAWABLE ``` From 1ae3768ac868b23449ac79bd57edec9bad1f804c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 19 Jan 2019 16:06:00 +0800 Subject: [PATCH 3/9] Minor fixes --- specs/core/0_beacon-chain.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 569296b5f..60b39c70b 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -254,7 +254,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ## Data structures -The following data structures are [SimpleSerialize (SSZ)](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md) objects. +The following data structures are defined as [SimpleSerialize (SSZ)](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md) objects. ### Beacon chain operations @@ -801,7 +801,7 @@ Note: We aim to migrate to a S[T/N]ARK-friendly hash function in a future Ethere #### `hash_tree_root` -`hash_tree_root` is a function for hashing objects into a single root utilizing a hash tree structure. `hash_tree_root` is defined in the [SimpleSerialize spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md#tree-hash). +`def hash_tree_root(object: SSZSerializable) -> Bytes32` is a function for hashing objects into a single root utilizing a hash tree structure. `hash_tree_root` is defined in the [SimpleSerialize spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md#tree-hash). #### `is_active_validator` ```python @@ -815,7 +815,7 @@ def is_active_validator(validator: Validator, slot: SlotNumber) -> bool: #### `get_active_validator_indices` ```python -def get_active_validator_indices(validators: [Validator], slot: SlotNumber) -> List[ValidatorIndex]: +def get_active_validator_indices(validators: List[Validator], slot: SlotNumber) -> List[ValidatorIndex]: """ Gets indices of active validators from ``validators``. """ @@ -1568,7 +1568,7 @@ For each `deposit` in `block.body.deposits`: * Verify that `verify_merkle_branch(hash(serialized_deposit_data), deposit.branch, DEPOSIT_CONTRACT_TREE_DEPTH, deposit.index, state.latest_eth1_data.deposit_root)` is `True`. ```python -def verify_merkle_branch(leaf: Bytes32, branch: [Bytes32], depth: int, index: int, root: Bytes32) -> bool: +def verify_merkle_branch(leaf: Bytes32, branch: List[Bytes32], depth: int, index: int, root: Bytes32) -> bool: value = leaf for i in range(depth): if index // (2**i) % 2: From f27905583f0cdfc2a78c98ead5d03902bcddd597 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 25 Jan 2019 16:01:35 +0800 Subject: [PATCH 4/9] PR feedback --- specs/core/0_beacon-chain.md | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 93e773976..382caeca7 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -746,26 +746,36 @@ Beacon block production is significantly different because of the proof of stake The beacon chain fork choice rule is a hybrid that combines justification and finality with Latest Message Driven (LMD) Greediest Heaviest Observed SubTree (GHOST). At any point in time a [validator](#dfn-validator) `v` subjectively calculates the beacon chain head as follows. -* Let `store` be the set of attestations and blocks that the [validator](#dfn-validator) `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not part of any chain are still included in `store`. +* Abstractly define `Store` as the type of storage object for the chain data and `store` be the set of attestations and blocks that the [validator](#dfn-validator) `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not part of any chain are still included in `store`. * Let `finalized_head` be the finalized block with the highest slot number. (A block `B` is finalized if there is a descendant of `B` in `store` the processing of which sets `B` as finalized.) * Let `justified_head` be the descendant of `finalized_head` with the highest slot number that has been justified for at least `EPOCH_LENGTH` slots. (A block `B` is justified if there is a descendant of `B` in `store` the processing of which sets `B` as justified.) If no such descendant exists set `justified_head` to `finalized_head`. -* Let `get_ancestor(store, block, slot)` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as `def get_ancestor(store, block, slot): return block if block.slot == slot else get_ancestor(store, store.get_parent(block), slot)`. -* Let `get_latest_attestation(store, validator)` be the attestation with the highest slot number in `store` from `validator`. If several such attestations exist, use the one the [validator](#dfn-validator) `v` observed first. -* Let `get_latest_attestation_target(store, validator)` be the target block in the attestation `get_latest_attestation(store, validator)`. -* The head is `lmd_ghost(store, justified_head)` where the function `lmd_ghost` is defined below. Note that the implementation below is suboptimal; there are implementations that compute the head in time logarithmic in slot count. +* Let `get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as `def get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock: return block if block.slot == slot else get_ancestor(store, store.get_parent(block), slot)`. +* Let `get_latest_attestation(store: Store, validator: Validator) -> Attestation` be the attestation with the highest slot number in `store` from `validator`. If several such attestations exist, use the one the [validator](#dfn-validator) `v` observed first. +* Let `get_latest_attestation_target(store: Store, validator: Validator) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, validator)`. +* Let `get_children(block: BeaconBlock) -> List[BeaconBlock]` returns the children blocks of the given `block`. +* Let `justified_head_state` be the `BeaconState` object after processing `justified_head`. +* The `head` is `lmd_ghost(store, justified_head_state, justified_head)` where the function `lmd_ghost` is defined below. Note that the implementation below is suboptimal; there are implementations that compute the head in time logarithmic in slot count. ```python -def lmd_ghost(store, start): - validators = start.state.validator_registry - active_validators = [validators[i] for i in - get_active_validator_indices(validators, start.state.slot)] - attestation_targets = [get_latest_attestation_target(store, validator) - for validator in active_validators] - def get_vote_count(block): - return len([target for target in attestation_targets if - get_ancestor(store, target, block.slot) == block]) +def lmd_ghost(store: Store, start_state: BeaconState, start_block: BeaconBlock) -> BeaconBlock: + validators = start_state.validator_registry + active_validators = [ + validators[i] + for i in get_active_validator_indices(validators, start_state.slot) + ] + attestation_targets = [ + get_latest_attestation_target(store, validator) + for validator in active_validators + ] - head = start + def get_vote_count(block: BeaconBlock) -> int: + return len([ + target + for target in attestation_targets + if get_ancestor(store, target, block.slot) == block + ]) + + head = start_block while 1: children = get_children(head) if len(children) == 0: From 21cecba6bb24bdbb0e57cefab76c2b550527c89a Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 25 Jan 2019 16:06:05 +0800 Subject: [PATCH 5/9] Update `get_children` def --- 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 382caeca7..a4440e924 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -752,7 +752,7 @@ The beacon chain fork choice rule is a hybrid that combines justification and fi * Let `get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as `def get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock: return block if block.slot == slot else get_ancestor(store, store.get_parent(block), slot)`. * Let `get_latest_attestation(store: Store, validator: Validator) -> Attestation` be the attestation with the highest slot number in `store` from `validator`. If several such attestations exist, use the one the [validator](#dfn-validator) `v` observed first. * Let `get_latest_attestation_target(store: Store, validator: Validator) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, validator)`. -* Let `get_children(block: BeaconBlock) -> List[BeaconBlock]` returns the children blocks of the given `block`. +* Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` returns the children blocks of the given `block`. * Let `justified_head_state` be the `BeaconState` object after processing `justified_head`. * The `head` is `lmd_ghost(store, justified_head_state, justified_head)` where the function `lmd_ghost` is defined below. Note that the implementation below is suboptimal; there are implementations that compute the head in time logarithmic in slot count. @@ -777,7 +777,7 @@ def lmd_ghost(store: Store, start_state: BeaconState, start_block: BeaconBlock) head = start_block while 1: - children = get_children(head) + children = get_children(store, head) if len(children) == 0: return head head = max(children, key=get_vote_count) From feaf689c9401434b97cd2f68b22baaae74368861 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sat, 26 Jan 2019 16:02:49 +0800 Subject: [PATCH 6/9] Apply suggestions from code review Co-Authored-By: hwwhww --- specs/core/0_beacon-chain.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index a4440e924..ea2d6eeb0 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -622,11 +622,11 @@ We define the following Python custom types for type hinting and readability: | - | - | - | | `SlotNumber` | unsigned 64-bit integer | the number of a slot | | `ShardNumber` | unsigned 64-bit integer | the number of a shard | -| `ValidatorIndex` | unsigned 24-bit integer | the index number of validator in the registry | -| `Gwei` | unsigned 64-bit integer | the amount in Gwei | -| `Bytes32` | 32-byte data | the binary data in 32-byte length | -| `BLSPubkey` | 48-byte data | the public key in BLS signature scheme | -| `BLSSignature` | 96-byte data | the signature in BLS signature scheme | +| `ValidatorIndex` | unsigned 24-bit integer | the index number of a validator in the registry | +| `Gwei` | unsigned 64-bit integer | an amount in Gwei | +| `Bytes32` | 32-byte data | binary data with 32-byte length | +| `BLSPubkey` | 48-byte data | a public key in BLS signature scheme | +| `BLSSignature` | 96-byte data | a signature in BLS signature scheme | ## Ethereum 1.0 deposit contract @@ -746,14 +746,14 @@ Beacon block production is significantly different because of the proof of stake The beacon chain fork choice rule is a hybrid that combines justification and finality with Latest Message Driven (LMD) Greediest Heaviest Observed SubTree (GHOST). At any point in time a [validator](#dfn-validator) `v` subjectively calculates the beacon chain head as follows. -* Abstractly define `Store` as the type of storage object for the chain data and `store` be the set of attestations and blocks that the [validator](#dfn-validator) `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not part of any chain are still included in `store`. +* Abstractly define `Store` as the type of storage object for the chain data and `store` be the set of attestations and blocks that the [validator](#dfn-validator) `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not yet included in any chain are still included in `store`. * Let `finalized_head` be the finalized block with the highest slot number. (A block `B` is finalized if there is a descendant of `B` in `store` the processing of which sets `B` as finalized.) * Let `justified_head` be the descendant of `finalized_head` with the highest slot number that has been justified for at least `EPOCH_LENGTH` slots. (A block `B` is justified if there is a descendant of `B` in `store` the processing of which sets `B` as justified.) If no such descendant exists set `justified_head` to `finalized_head`. * Let `get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as `def get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock: return block if block.slot == slot else get_ancestor(store, store.get_parent(block), slot)`. * Let `get_latest_attestation(store: Store, validator: Validator) -> Attestation` be the attestation with the highest slot number in `store` from `validator`. If several such attestations exist, use the one the [validator](#dfn-validator) `v` observed first. * Let `get_latest_attestation_target(store: Store, validator: Validator) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, validator)`. -* Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` returns the children blocks of the given `block`. -* Let `justified_head_state` be the `BeaconState` object after processing `justified_head`. +* Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` returns the child blocks of the given `block`. +* Let `justified_head_state` be the resulting `BeaconState` object from processing the chain up to the `justified_head`. * The `head` is `lmd_ghost(store, justified_head_state, justified_head)` where the function `lmd_ghost` is defined below. Note that the implementation below is suboptimal; there are implementations that compute the head in time logarithmic in slot count. ```python From 8c91be9e74c3ed5cc19695deb891cd72c08c0f8f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sat, 26 Jan 2019 16:07:15 +0800 Subject: [PATCH 7/9] Add custom type hinting for `get_active_index_root` --- 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 5013b9c95..af121905f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -116,7 +116,7 @@ - [Attestation inclusion](#attestation-inclusion) - [Crosslinks](#crosslinks-1) - [Ejections](#ejections) - - [Validator registry](#validator-registry) + - [Validator registry and shuffling seed data](#validator-registry-and-shuffling-seed-data) - [Final updates](#final-updates) - [State root processing](#state-root-processing) - [References](#references) @@ -1013,7 +1013,7 @@ def get_randao_mix(state: BeaconState, ```python def get_active_index_root(state: BeaconState, - slot: int) -> Bytes32: + slot: SlotNumber) -> Bytes32: """ Returns the index root at a recent ``slot``. """ From 0b827a04476f0fef05276aebb153e6ec9a51765a Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 26 Jan 2019 21:38:27 +1100 Subject: [PATCH 8/9] Change `PENALIZED_WITHDRAWAL_TIME` variable It's not in the "Constants" list and it is assigned to. --- 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 af121905f..c7bef5c25 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1823,8 +1823,8 @@ def process_penalties_and_exits(state: BeaconState) -> None: def eligible(index): validator = state.validator_registry[index] if validator.penalized_slot <= state.slot: - PENALIZED_WITHDRAWAL_TIME = LATEST_PENALIZED_EXIT_LENGTH * EPOCH_LENGTH // 2 - return state.slot >= validator.penalized_slot + PENALIZED_WITHDRAWAL_TIME + penalized_withdrawal_time = LATEST_PENALIZED_EXIT_LENGTH * EPOCH_LENGTH // 2 + return state.slot >= validator.penalized_slot + penalized_withdrawal_time else: return state.slot >= validator.exit_slot + MIN_VALIDATOR_WITHDRAWAL_TIME From 1a4107876823f4c6060f25ba79cff89c988a2a1c Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sat, 26 Jan 2019 12:13:12 -0700 Subject: [PATCH 9/9] randao reveal is signed epoch number (#498) --- specs/core/0_beacon-chain.md | 8 ++------ specs/validator/0_beacon-chain-validator.md | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index c7bef5c25..5a185f63f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -514,8 +514,6 @@ The following data structures are defined as [SimpleSerialize (SSZ)](https://git 'pubkey': 'bytes48', # Withdrawal credentials 'withdrawal_credentials': 'bytes32', - # Number of proposer slots since genesis - 'proposer_slots': 'uint64', # Slot when validator activated 'activation_slot': 'uint64', # Slot when validator exited @@ -1368,7 +1366,6 @@ def process_deposit(state: BeaconState, validator = Validator( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, - proposer_slots=0, activation_slot=FAR_FUTURE_SLOT, exit_slot=FAR_FUTURE_SLOT, withdrawal_slot=FAR_FUTURE_SLOT, @@ -1447,7 +1444,6 @@ Below are the processing steps that happen at every slot. ### Misc counters * Set `state.slot += 1`. -* Set `state.validator_registry[get_beacon_proposer_index(state, state.slot)].proposer_slots += 1`. * Set `state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] = state.latest_randao_mixes[(state.slot - 1) % LATEST_RANDAO_MIXES_LENGTH]` ### Block roots @@ -1473,8 +1469,8 @@ Below are the processing steps that happen at every `block`. ### RANDAO * Let `proposer = state.validator_registry[get_beacon_proposer_index(state, state.slot)]`. -* Verify that `bls_verify(pubkey=proposer.pubkey, message=int_to_bytes32(proposer.proposer_slots), signature=block.randao_reveal, domain=get_domain(state.fork, state.slot, DOMAIN_RANDAO))`. -* Set `state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] = hash(state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] + block.randao_reveal)`. +* Verify that `bls_verify(pubkey=proposer.pubkey, message=int_to_bytes32(state.slot // EPOCH_LENGTH), signature=block.randao_reveal, domain=get_domain(state.fork, state.slot, DOMAIN_RANDAO))`. +* Set `state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] = xor(state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH], hash(block.randao_reveal))`. ### Eth1 data diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 29ec0c7e0..83ebb5751 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -158,12 +158,12 @@ _Note_: To calculate `state_root`, the validator should first run the state tran ##### Randao reveal -Set `block.randao_reveal = reveal_signature` where `reveal_signature` is defined as: +Set `block.randao_reveal = epoch_signature` where `epoch_signature` is defined as: ```python -reveal_signature = bls_sign( +epoch_signature = bls_sign( privkey=validator.privkey, # privkey store locally, not in state - message=int_to_bytes32(validator.proposer_slots + 1), + message=int_to_bytes32(block.slot // EPOCH_LENGTH), domain=get_domain( fork_data, # `fork_data` is the fork_data at the slot `block.slot` block.slot,