From 425f7d51c96f5b14a994267b668abacff4836ecd Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sat, 15 Dec 2018 05:10:31 -0500 Subject: [PATCH] Keep randao mixes in the state Response to #295 Also a simplification, as two special cases get replaced: `state.randao_mix` -> `state.latest_randao_mixes[-1]`, and `state.next_seed` -> `state.latest_randao_mixes[-CYCLE_LENGTH-1]`. --- specs/core/0_beacon-chain.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 2097f6a0e..8d9f88d86 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -459,8 +459,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted 'validator_registry_delta_chain_tip': 'hash32', # For light clients to track deltas # Randomness and committees - 'randao_mix': 'hash32', - 'next_seed': 'hash32', + 'latest_randao_mixes': ['hash32'], 'shard_committees_at_slots': [[ShardCommittee]], 'persistent_committees': [['uint24']], 'persistent_committee_reassignments': [ShardReassignmentRecord], @@ -1154,8 +1153,7 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit], validator_registry_delta_chain_tip=ZERO_HASH, # Randomness and committees - randao_mix=ZERO_HASH, - next_seed=ZERO_HASH, + latest_randao_mixes=[ZERO_HASH for _ in range(LATEST_BLOCK_ROOTS_LENGTH)], shard_committees_at_slots=[], persistent_committees=[], persistent_committee_reassignments=[], @@ -1415,7 +1413,7 @@ Below are the processing steps that happen at every `block`. * Let `repeat_hash(x, n) = x if n == 0 else repeat_hash(hash(x), n-1)`. * Let `proposer = state.validator_registry[get_beacon_proposer_index(state, state.slot)]`. * Verify that `repeat_hash(block.randao_reveal, proposer.randao_layers) == proposer.randao_commitment`. -* Set `state.randao_mix = xor(state.randao_mix, block.randao_reveal)`. +* Set `state.latest_randao_mixes = state.latest_randao_mixes[1:] + [xor(state.latest_randao_mixes[-1], block.randao_reveal)] * Set `proposer.randao_commitment = block.randao_reveal`. * Set `proposer.randao_layers = 0`. @@ -1749,15 +1747,14 @@ Also perform the following updates: * Set `state.validator_registry_latest_change_slot = state.slot`. * Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`. -* Set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.next_seed, state.validator_registry, next_start_shard)` where `next_start_shard = (state.shard_committees_at_slots[-1][-1].shard + 1) % SHARD_COUNT`. -* Set `state.next_seed = state.randao_mix`. +* Set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.latest_randao_mixes[-CYCLE_LENGTH-1], state.validator_registry, next_start_shard)` where `next_start_shard = (state.shard_committees_at_slots[-1][-1].shard + 1) % SHARD_COUNT`. If a validator registry update does _not_ happen do the following: * Set `state.shard_committees_at_slots[:EPOCH_LENGTH] = state.shard_committees_at_slots[EPOCH_LENGTH:]`. * Let `slots_since_finality = state.slot - state.validator_registry_latest_change_slot`. * Let `start_shard = state.shard_committees_at_slots[0][0].shard`. -* If `slots_since_finality * EPOCH_LENGTH <= MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL` or `slots_since_finality` is an exact power of 2, set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.next_seed, state.validator_registry, start_shard)` and set `state.next_seed = state.randao_mix`. Note that `start_shard` is not changed from the last epoch. +* If `slots_since_finality * EPOCH_LENGTH <= MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL` or `slots_since_finality` is an exact power of 2, set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.latest_randao_mixes[-CYCLE_LENGTH-1], state.validator_registry, start_shard)`. Note that `start_shard` is not changed from the last epoch. ### Proposer reshuffling @@ -1769,8 +1766,8 @@ num_validators_to_reshuffle = len(active_validator_indices) // SHARD_PERSISTENT_ for i in range(num_validators_to_reshuffle): # Multiplying i to 2 to ensure we have different input to all the required hashes in the shuffling # and none of the hashes used for entropy in this loop will be the same - validator_index = active_validator_indices[hash(state.randao_mix + bytes8(i * 2)) % len(active_validator_indices)] - new_shard = hash(state.randao_mix + bytes8(i * 2 + 1)) % SHARD_COUNT + validator_index = active_validator_indices[hash(state.latest_randao_mixes[-1] + bytes8(i * 2)) % len(active_validator_indices)] + new_shard = hash(state.latest_randao_mixes[-1] + bytes8(i * 2 + 1)) % SHARD_COUNT shard_reassignment_record = ShardReassignmentRecord( validator_index=validator_index, shard=new_shard,