From aa9bda271feb8cb9d80cc2ac647e1e510b94b55b Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 28 Dec 2018 11:10:12 -0600 Subject: [PATCH 1/3] fix slashing conditons to be based upon epochs rather than slots --- specs/core/0_beacon-chain.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 045a914b0..8501a1a40 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1080,7 +1080,9 @@ def is_double_vote(attestation_data_1: AttestationData, Returns True if the provided ``AttestationData`` are slashable due to a 'double vote'. """ - return attestation_data_1.slot == attestation_data_2.slot + target_epoch_1 = attestation_data_1.slot // EPOCH_LENGTH + target_epoch_2 = attestation_data_2.slot // EPOCH_LENGTH + return target_epoch_1 == target_epoch_2 ``` #### `is_surround_vote` @@ -1095,10 +1097,14 @@ def is_surround_vote(attestation_data_1: AttestationData, Note: parameter order matters as this function only checks that ``attestation_data_1`` surrounds ``attestation_data_2``. """ + source_epoch_1 = attestation_data_1.justified_slot // EPOCH_LENGTH + source_epoch_2 = attestation_data_2.justified_slot // EPOCH_LENGTH + target_epoch_1 = attestation_data_1.slot // EPOCH_LENGTH + target_epoch_2 = attestation_data_2.slot // EPOCH_LENGTH return ( - (attestation_data_1.justified_slot < attestation_data_2.justified_slot) and - (attestation_data_2.justified_slot + 1 == attestation_data_2.slot) and - (attestation_data_2.slot < attestation_data_1.slot) + (source_epoch_1 < source_epoch_2) and + (source_epoch_2 + 1 == target_epoch_2) and + (target_epoch_2 < target_epoch_1) ) ``` From 1a4973171f3d077e606dc79f2b16dfd60c28a17f Mon Sep 17 00:00:00 2001 From: vbuterin Date: Sun, 30 Dec 2018 17:46:32 -0600 Subject: [PATCH 2/3] Remove references to the persistent committees (#376) * Remove references to the persistent committees --- specs/core/0_beacon-chain.md | 44 ------------------------------------ 1 file changed, 44 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 045a914b0..03c11adfe 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -197,7 +197,6 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted | `MIN_ATTESTATION_INCLUSION_DELAY` | `2**2` (= 4) | slots | 24 seconds | | `EPOCH_LENGTH` | `2**6` (= 64) | slots | 6.4 minutes | | `POW_RECEIPT_ROOT_VOTING_PERIOD` | `2**10` (= 1,024) | slots | ~1.7 hours | -| `SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD` | `2**17` (= 131,072) | slots | ~9 days | | `COLLECTIVE_PENALTY_CALCULATION_PERIOD` | `2**20` (= 1,048,576) | slots | ~73 days | | `ZERO_BALANCE_VALIDATOR_TTL` | `2**22` (= 4,194,304) | slots | ~291 days | @@ -482,8 +481,6 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted 'latest_randao_mixes': ['hash32'], 'latest_vdf_outputs': ['hash32'], 'shard_committees_at_slots': [[ShardCommittee]], - 'persistent_committees': [['uint24']], - 'persistent_committee_reassignments': [ShardReassignmentRecord], # Proof of custody # Placeholders for now; ProofOfCustodyChallenge is defined in phase 1, implementers can @@ -1181,8 +1178,6 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit], latest_randao_mixes=[ZERO_HASH for _ in range(LATEST_RANDAO_MIXES_LENGTH)], latest_vdf_outputs=[ZERO_HASH for _ in range(LATEST_RANDAO_MIXES_LENGTH // EPOCH_LENGTH)], shard_committees_at_slots=[], - persistent_committees=[], - persistent_committee_reassignments=[], # Proof of custody poc_challenges=[], @@ -1223,10 +1218,6 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit], initial_shuffling = get_new_shuffling(ZERO_HASH, state.validator_registry, 0) state.shard_committees_at_slots = initial_shuffling + initial_shuffling - # set initial persistent shuffling - active_validator_indices = get_active_validator_indices(state.validator_registry) - state.persistent_committees = split(shuffle(active_validator_indices, ZERO_HASH), SHARD_COUNT) - return state ``` @@ -1424,13 +1415,6 @@ def exit_validator(state: BeaconState, pubkey=validator.pubkey, flag=EXIT, ) - - # Remove validator from persistent committees - for committee in state.persistent_committees: - for i, validator_index in committee: - if validator_index == index: - committee.pop(i) - break ``` ## Per-slot processing @@ -1575,7 +1559,6 @@ For each `exit` in `block.body.exits`: * Let `validator = state.validator_registry[exit.validator_index]`. * Verify that `validator.status == ACTIVE`. * Verify that `state.slot >= exit.slot`. -* Verify that `state.slot >= validator.latest_status_change_slot + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD`. * Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork_data, exit.slot, DOMAIN_EXIT))`. * Run `update_validator_status(state, validator_index, new_status=ACTIVE_PENDING_EXIT)`. @@ -1803,33 +1786,6 @@ If a validator registry update does _not_ happen do the following: * Let `start_shard = state.shard_committees_at_slots[0][0].shard`. * If `epochs_since_last_registry_change` is an exact power of 2, set `state.shard_committees_at_slots[EPOCH_LENGTH:] = get_new_shuffling(state.latest_randao_mixes[(state.slot - EPOCH_LENGTH) % LATEST_RANDAO_MIXES_LENGTH], state.validator_registry, start_shard)`. Note that `start_shard` is not changed from the last epoch. -### Proposer reshuffling - -Run the following code to update the shard proposer set: - -```python -active_validator_indices = get_active_validator_indices(state.validator_registry) -num_validators_to_reshuffle = len(active_validator_indices) // SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD -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.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] + bytes8(i * 2)) % len(active_validator_indices)] - new_shard = hash(state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] + bytes8(i * 2 + 1)) % SHARD_COUNT - shard_reassignment_record = ShardReassignmentRecord( - validator_index=validator_index, - shard=new_shard, - slot=s + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD - ) - state.persistent_committee_reassignments.append(shard_reassignment_record) - -while len(state.persistent_committee_reassignments) > 0 and state.persistent_committee_reassignments[0].slot <= s: - reassignment = state.persistent_committee_reassignments.pop(0) - for committee in state.persistent_committees: - if reassignment.validator_index in committee: - committee.pop(committee.index(reassignment.validator_index)) - state.persistent_committees[reassignment.shard].append(reassignment.validator_index) -``` - ### Final updates * Remove any `attestation` in `state.latest_attestations` such that `attestation.data.slot < state.slot - EPOCH_LENGTH`. From c8ff723514a9d3efeab4796d1ad3d0520bb95d98 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 30 Dec 2018 16:06:33 -0800 Subject: [PATCH 3/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 03c11adfe..ace489f17 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1529,9 +1529,9 @@ def verify_merkle_branch(leaf: Hash32, branch: [Hash32], depth: int, index: int, value = leaf for i in range(depth): if index % 2: - value = hash(branch[i], value) + value = hash(branch[i] + value) else: - value = hash(value, branch[i]) + value = hash(value + branch[i]) return value == root ```