From f92735454e15dbdda0206b95ae40cfc03dba33b0 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 3 Jan 2019 16:19:54 +0800 Subject: [PATCH 1/7] Fix `verify_slashable_vote_data` The first field of `AttestationDataAndCustodyBit` should be an `AttestationData` object, not an `SlashableVoteData` object. --- 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 7e2bbe83f..a35540d97 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1039,8 +1039,8 @@ def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) aggregate_pubkey([state.validators[i].pubkey for i in vote_data.custody_bit_1_indices]), ], messages=[ - hash_tree_root(AttestationDataAndCustodyBit(vote_data, False)), - hash_tree_root(AttestationDataAndCustodyBit(vote_data, True)), + hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, False)), + hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, True)), ], signature=vote_data.aggregate_signature, domain=get_domain( From 457f84fa648997fb06498af2cd6739faa37d816b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 3 Jan 2019 12:06:44 -0600 Subject: [PATCH 2/7] Change "justified hash" to "justified slot" There should be a correspondence here but referring to the slot is more explicit, especially for those who are not as familiar with the details of FFG finalization. --- 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 7e2bbe83f..eea62ad13 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1580,7 +1580,7 @@ All [validators](#dfn-validator): * Validators that made an attestation during the previous epoch: * Let `previous_epoch_attestations = [a for a in state.latest_attestations if state.slot - 2 * EPOCH_LENGTH <= a.slot < state.slot - EPOCH_LENGTH]`. * Let `previous_epoch_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.participation_bitfield) for a in previous_epoch_attestations]`. -* Validators targeting the previous justified hash: +* Validators targeting the previous justified slot: * Let `previous_epoch_justified_attestations = [a for a in current_epoch_attestations + previous_epoch_attestations if a.justified_slot == state.previous_justified_slot]`. * Let `previous_epoch_justified_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.participation_bitfield) for a in previous_epoch_justified_attestations]`. * Let `previous_epoch_justified_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_justified_attester_indices])`. From 9a83ad7b9bdda1058433035d24559136a7a9e466 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 3 Jan 2019 14:28:36 -0600 Subject: [PATCH 3/7] Fix a type error with units of wei when determining ejection balance. `EJECTION_BALANCE` is in units of ETH. `state.validator_balances[index]` is in units of Gwei. For the ejection computation to work as desired, we need to convert the `EJECTION_BALANCE` constant from ETH to Gwei. --- 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 7e2bbe83f..5c26069ff 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1690,7 +1690,7 @@ def process_ejections(state: BeaconState) -> None: and eject active validators with balance below ``EJECTION_BALANCE``. """ for index in active_validator_indices(state.validator_registry): - if state.validator_balances[index] < EJECTION_BALANCE: + if state.validator_balances[index] < EJECTION_BALANCE * GWEI_PER_ETH: update_validator_status(state, index, new_status=EXITED_WITHOUT_PENALTY) ``` From 19b1a31903330acb167104071e126ef0442649d6 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 3 Jan 2019 13:57:04 -0800 Subject: [PATCH 4/7] Update 1_shard-data-chains.md --- specs/core/1_shard-data-chains.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index a66f37ac5..973a0d332 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -53,8 +53,8 @@ A `ShardBlock` object has the following fields: # Block signature 'signature': ['uint384'], # Attestation - 'attester_bitfield': 'bytes', - 'aggregate_sig': ['uint384'], + 'participation_bitfield': 'bytes', + 'aggregate_signature': ['uint384'], } ``` @@ -69,9 +69,9 @@ To validate a block header on shard `shard_id`, compute as follows: * Verify that `beacon_chain_ref` is the hash of a block in the beacon chain with slot less than or equal to `slot`. Verify that `beacon_chain_ref` is equal to or a descendant of the `beacon_chain_ref` specified in the `ShardBlock` pointed to by `parent_root`. * Let `state` be the state of the beacon chain block referred to by `beacon_chain_ref`. Let `validators` be `[validators[i] for i in state.current_persistent_committees[shard_id]]`. -* Assert `len(attester_bitfield) == ceil_div8(len(validators))` +* Assert `len(participation_bitfield) == ceil_div8(len(validators))` * Let `proposer_index = hash(state.randao_mix + bytes8(shard_id) + bytes8(slot)) % len(validators)`. Let `msg` be the block but with the `block.signature` set to `[0, 0]`. Verify that `BLSVerify(pub=validators[proposer_index].pubkey, msg=hash(msg), sig=block.signature, domain=get_domain(state, slot, SHARD_PROPOSER_DOMAIN))` passes. -* Generate the `group_public_key` by adding the public keys of all the validators for whom the corresponding position in the bitfield is set to 1. Verify that `BLSVerify(pub=group_public_key, msg=parent_root, sig=block.aggregate_sig, domain=get_domain(state, slot, SHARD_ATTESTER_DOMAIN))` passes. +* Generate the `group_public_key` by adding the public keys of all the validators for whom the corresponding position in the bitfield is set to 1. Verify that `BLSVerify(pub=group_public_key, msg=parent_root, sig=block.aggregate_signature, domain=get_domain(state, slot, SHARD_ATTESTER_DOMAIN))` passes. ### Block Merklization helper From 19a9582a48f97651ecc632c908c2413d5e89625a Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Thu, 3 Jan 2019 19:42:07 -0600 Subject: [PATCH 5/7] Remove dangling `return` statement from spec function This function declares that it returns `None` and instead directly mutates the state. There is a dangling return statement that this commit deletes. --- specs/core/0_beacon-chain.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7e2bbe83f..b714dea0f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1759,8 +1759,6 @@ def update_validator_registry(state: BeaconState) -> None: validators_to_penalize = filter(to_penalize, range(len(validator_registry))) for index in validators_to_penalize: state.validator_balances[index] -= get_effective_balance(state, index) * min(total_penalties * 3, total_balance) // total_balance - - return validator_registry, latest_penalized_exit_balances, validator_registry_delta_chain_tip ``` Also perform the following updates: From c0140d72eee0a191155bef63dd1071aa74f61b92 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 3 Jan 2019 18:23:23 -0800 Subject: [PATCH 6/7] Update 0_beacon-chain.md --- specs/core/0_beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7e2bbe83f..73789749b 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1597,6 +1597,7 @@ All [validators](#dfn-validator): For every `shard_committee` in `state.shard_committees_at_slots`: +* Let `shard_block_root` be `state.latest_crosslinks[shard_committee.shard].shard_block_root` * Let `attesting_validator_indices(shard_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.participation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.shard == shard_committee.shard and a.shard_block_root == shard_block_root]`. * Let `winning_root(shard_committee)` be equal to the value of `shard_block_root` such that `sum([get_effective_balance(state, i) for i in attesting_validator_indices(shard_committee, shard_block_root)])` is maximized (ties broken by favoring lower `shard_block_root` values). * Let `attesting_validators(shard_committee)` be equal to `attesting_validator_indices(shard_committee, winning_root(shard_committee))` for convenience. @@ -1630,7 +1631,7 @@ Set `state.finalized_slot = state.previous_justified_slot` if any of the followi For every `shard_committee_at_slot` in `state.shard_committees_at_slots` and for every `shard_committee`in `shard_committee_at_slot`: -* Set `state.latest_crosslinks[shard_committee.shard] = CrosslinkRecord(slot=state.slot, block_root=winning_root(shard_committee))` if `3 * total_attesting_balance(shard_committee) >= 2 * total_balance(shard_committee)`. +* Set `state.latest_crosslinks[shard_committee.shard] = CrosslinkRecord(slot=state.slot, shard_block_root=winning_root(shard_committee))` if `3 * total_attesting_balance(shard_committee) >= 2 * total_balance(shard_committee)`. ### Rewards and penalties From 97bd04607c6bb212c4e7419546a571306b647864 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 3 Jan 2019 19:40:03 -0800 Subject: [PATCH 7/7] 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 73789749b..3001f44bd 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1595,7 +1595,7 @@ All [validators](#dfn-validator): **Note**: `previous_epoch_boundary_attesting_balance` balance might be marginally different than `current_epoch_boundary_attesting_balance` during the previous epoch transition. Due to the tight bound on validator churn each epoch and small per-epoch rewards/penalties, the potential balance difference is very low and only marginally affects consensus safety. -For every `shard_committee` in `state.shard_committees_at_slots`: +For every `shard_committee_at_slot` in `state.shard_committees_at_slots` and for every `shard_committee` in `shard_committee_at_slot`: * Let `shard_block_root` be `state.latest_crosslinks[shard_committee.shard].shard_block_root` * Let `attesting_validator_indices(shard_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.participation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.shard == shard_committee.shard and a.shard_block_root == shard_block_root]`.