From 840d3f11ad9b584d15bb2066c157170194ddf318 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 16 Oct 2018 16:37:59 -0500 Subject: [PATCH 1/3] clarify the validity conditions for attestation.justified_slot and justified_block_hash --- specs/beacon-chain.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 38364fc7a..14fa1d4d6 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -632,7 +632,8 @@ A block can have 0 or more `AttestationRecord` objects For each one of these attestations: * Verify that `slot <= parent.slot` and `slot >= max(parent.slot - CYCLE_LENGTH + 1, 0)` -* Verify that the `justified_slot` and `justified_block_hash` given are in the chain and are equal to or earlier than the `last_justified_slot` in the crystallized state. +* Verify that `justified_slot` is equal to or earlier than `last_justified_slot` +* Verify that `justified_block_hash` is the hash of the block in the current chain at the slot -- `justified_slot` * Compute `parent_hashes` = `[get_block_hash(active_state, block, slot - CYCLE_LENGTH + i) for i in range(1, CYCLE_LENGTH - len(oblique_parent_hashes) + 1)] + oblique_parent_hashes` (eg, if `CYCLE_LENGTH = 4`, `slot = 5`, the actual block hashes starting from slot 0 are `Z A B C D E F G H I J`, and `oblique_parent_hashes = [D', E']` then `parent_hashes = [B, C, D' E']`). Note that when *creating* an attestation for a block, the hash of that block itself won't yet be in the `active_state`, so you would need to add it explicitly. * Let `attestation_indices` be `get_shards_and_committees_for_slot(crystallized_state, slot)[x]`, choosing `x` so that `attestation_indices.shard` equals the `shard` value provided to find the set of validators that is creating this attestation record. * Verify that `len(attester_bitfield) == ceil_div8(len(attestation_indices))`, where `ceil_div8 = (x + 7) // 8`. Verify that bits `len(attestation_indices)....` and higher, if present (i.e. `len(attestation_indices)` is not a multiple of 8), are all zero From d0501631a43bbc57464b38d40d7260c2534ae7d5 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 17 Oct 2018 09:45:15 -0500 Subject: [PATCH 2/3] added missing periods --- specs/beacon-chain.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 14fa1d4d6..9a28d85c8 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -631,13 +631,13 @@ A block can have 0 or more `AttestationRecord` objects For each one of these attestations: -* Verify that `slot <= parent.slot` and `slot >= max(parent.slot - CYCLE_LENGTH + 1, 0)` -* Verify that `justified_slot` is equal to or earlier than `last_justified_slot` -* Verify that `justified_block_hash` is the hash of the block in the current chain at the slot -- `justified_slot` +* Verify that `slot <= parent.slot` and `slot >= max(parent.slot - CYCLE_LENGTH + 1, 0)`. +* Verify that `justified_slot` is equal to or earlier than `last_justified_slot`. +* Verify that `justified_block_hash` is the hash of the block in the current chain at the slot -- `justified_slot`. * Compute `parent_hashes` = `[get_block_hash(active_state, block, slot - CYCLE_LENGTH + i) for i in range(1, CYCLE_LENGTH - len(oblique_parent_hashes) + 1)] + oblique_parent_hashes` (eg, if `CYCLE_LENGTH = 4`, `slot = 5`, the actual block hashes starting from slot 0 are `Z A B C D E F G H I J`, and `oblique_parent_hashes = [D', E']` then `parent_hashes = [B, C, D' E']`). Note that when *creating* an attestation for a block, the hash of that block itself won't yet be in the `active_state`, so you would need to add it explicitly. * Let `attestation_indices` be `get_shards_and_committees_for_slot(crystallized_state, slot)[x]`, choosing `x` so that `attestation_indices.shard` equals the `shard` value provided to find the set of validators that is creating this attestation record. -* Verify that `len(attester_bitfield) == ceil_div8(len(attestation_indices))`, where `ceil_div8 = (x + 7) // 8`. Verify that bits `len(attestation_indices)....` and higher, if present (i.e. `len(attestation_indices)` is not a multiple of 8), are all zero -* Derive a group public key by adding the public keys of all of the attesters in `attestation_indices` for whom the corresponding bit in `attester_bitfield` (the ith bit is `(attester_bitfield[i // 8] >> (7 - (i %8))) % 2`) equals 1 +* Verify that `len(attester_bitfield) == ceil_div8(len(attestation_indices))`, where `ceil_div8 = (x + 7) // 8`. Verify that bits `len(attestation_indices)....` and higher, if present (i.e. `len(attestation_indices)` is not a multiple of 8), are all zero. +* Derive a group public key by adding the public keys of all of the attesters in `attestation_indices` for whom the corresponding bit in `attester_bitfield` (the ith bit is `(attester_bitfield[i // 8] >> (7 - (i %8))) % 2`) equals 1. * Let `fork_version = pre_fork_version if slot < fork_slot_number else post_fork_version`. * Verify that `aggregate_sig` verifies using the group pubkey generated and the serialized form of `AttestationSignedData(fork_version, slot, shard, parent_hashes, shard_block_hash, justified_slot)` as the message. From 9b9cfae117bb1b30975cc90759d3a6c5f3c9fa64 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Wed, 17 Oct 2018 09:48:17 -0500 Subject: [PATCH 3/3] Add explicit setting of parent and parent_hash --- specs/beacon-chain.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/specs/beacon-chain.md b/specs/beacon-chain.md index 9a28d85c8..32bed6957 100644 --- a/specs/beacon-chain.md +++ b/specs/beacon-chain.md @@ -603,7 +603,10 @@ def exit_validator(index, crystallized_state, penalize, current_slot): This procedure should be carried out every block. -First, set `recent_block_hashes` to the output of the following, where `parent_hash` is the hash of the immediate previous block (ie. must be equal to `ancestor_hashes[0]`): +* Let `parent_hash` be the hash of the immediate previous beacon block (ie. equal to `ancestor_hashes[0]`). +* Let `parent` be the beacon block with the hash `parent_hash` + +First, set `recent_block_hashes` to the output of the following: ```python def append_to_recent_block_hashes(old_block_hashes: List[Hash32],