From bf20031755804aa98ea7f0b597f698efac3e01a2 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 May 2019 17:15:05 +0100 Subject: [PATCH 1/3] Cosmetic genesis cleanups --- specs/core/0_beacon-chain.md | 43 +++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 36ac92796..df871dc60 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -93,7 +93,10 @@ - [Routines for updating validator status](#routines-for-updating-validator-status) - [`initiate_validator_exit`](#initiate_validator_exit) - [`slash_validator`](#slash_validator) - - [On genesis](#on-genesis) + - [Genesis](#genesis) + - [`Eth2Genesis`](#eth2genesis) + - [Genesis state](#genesis-state) + - [Genesis block](#genesis-block) - [Beacon chain state transition function](#beacon-chain-state-transition-function) - [State caching](#state-caching) - [Per-epoch processing](#per-epoch-processing) @@ -1171,30 +1174,29 @@ def slash_validator(state: BeaconState, slashed_index: ValidatorIndex, whistlebl decrease_balance(state, slashed_index, whistleblowing_reward) ``` -## On genesis +## Genesis -When enough full deposits have been made to the deposit contract, an `Eth2Genesis` log is emitted. Construct a corresponding `genesis_state` and `genesis_block` as follows: +### `Eth2Genesis` -* Let `genesis_validator_deposits` be the list of deposits, ordered chronologically, up to and including the deposit that triggered the `Eth2Genesis` log. -* Let `genesis_time` be the timestamp specified in the `Eth2Genesis` log. -* Let `genesis_eth1_data` be the `Eth1Data` object where: - * `genesis_eth1_data.deposit_root` is the `deposit_root` contained in the `Eth2Genesis` log. - * `genesis_eth1_data.deposit_count` is the `deposit_count` contained in the `Eth2Genesis` log. - * `genesis_eth1_data.block_hash` is the hash of the Ethereum 1.0 block that emitted the `Eth2Genesis` log. -* Let `genesis_state = get_genesis_beacon_state(genesis_validator_deposits, genesis_time, genesis_eth1_data)`. -* Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`. +When enough deposits of size `MAX_EFFECTIVE_BALANCE` have been made to the deposit contract an `Eth2Genesis` log is emitted triggering the genesis of the beacon chain. Let: + +* `eth2genesis` be the object corresponding to `Eth2Genesis` +* `genesis_eth1_data` be object of type `Eth1Data` where + * `genesis_eth1_data.deposit_root = eth2genesis.deposit_root` + * `genesis_eth1_data.deposit_count = eth2genesis.deposit_count` + * `genesis_eth1_data.block_hash` is the hash of the Ethereum 1.0 block that emitted the `Eth2Genesis` log +* `genesis_deposits` be the object of type `List[Deposit]` with deposits ordered chronologically up to and including the deposit that triggered the `Eth2Genesis` log + +### Genesis state + +Let `genesis_state = get_genesis_beacon_state(eth2genesis.genesis_time, genesis_eth1_data, genesis_deposits)`. ```python -def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit], - genesis_time: int, - genesis_eth1_data: Eth1Data) -> BeaconState: - """ - Get the genesis ``BeaconState``. - """ +def get_genesis_beacon_state(genesis_time: int, eth1_data: Eth1Data, deposits: List[Deposit]) -> BeaconState: state = BeaconState(genesis_time=genesis_time, latest_eth1_data=genesis_eth1_data) # Process genesis deposits - for deposit in genesis_validator_deposits: + for deposit in deposits: process_deposit(state, deposit) # Process genesis activations @@ -1203,6 +1205,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit], validator.activation_eligibility_epoch = GENESIS_EPOCH validator.activation_epoch = GENESIS_EPOCH + # Populate latest_active_index_roots genesis_active_index_root = hash_tree_root(get_active_validator_indices(state, GENESIS_EPOCH)) for index in range(LATEST_ACTIVE_INDEX_ROOTS_LENGTH): state.latest_active_index_roots[index] = genesis_active_index_root @@ -1210,6 +1213,10 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit], return state ``` +### Genesis block + +Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`. + ## Beacon chain state transition function We now define the state transition function. At a high level, the state transition is made up of four parts: From a3bbf20bf732b77eaddabad5a82f89b0c9f612c2 Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 May 2019 17:17:18 +0100 Subject: [PATCH 2/3] Update 0_beacon-chain.md --- 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 df871dc60..4d3263a40 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1189,10 +1189,10 @@ When enough deposits of size `MAX_EFFECTIVE_BALANCE` have been made to the depos ### Genesis state -Let `genesis_state = get_genesis_beacon_state(eth2genesis.genesis_time, genesis_eth1_data, genesis_deposits)`. +Let `genesis_state = get_genesis_beacon_state(genesis_deposits, eth2genesis.genesis_time, genesis_eth1_data)`. ```python -def get_genesis_beacon_state(genesis_time: int, eth1_data: Eth1Data, deposits: List[Deposit]) -> BeaconState: +def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, eth1_data: Eth1Data) -> BeaconState: state = BeaconState(genesis_time=genesis_time, latest_eth1_data=genesis_eth1_data) # Process genesis deposits From 6aff277b1a344a2ecf024ef0fa4e6a126d0cdecf Mon Sep 17 00:00:00 2001 From: Justin Date: Sun, 5 May 2019 17:20:25 +0100 Subject: [PATCH 3/3] 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 4d3263a40..381ef867d 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1192,7 +1192,7 @@ When enough deposits of size `MAX_EFFECTIVE_BALANCE` have been made to the depos Let `genesis_state = get_genesis_beacon_state(genesis_deposits, eth2genesis.genesis_time, genesis_eth1_data)`. ```python -def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, eth1_data: Eth1Data) -> BeaconState: +def get_genesis_beacon_state(deposits: List[Deposit], genesis_time: int, genesis_eth1_data: Eth1Data) -> BeaconState: state = BeaconState(genesis_time=genesis_time, latest_eth1_data=genesis_eth1_data) # Process genesis deposits