From 44ac70e7fe829a316999ce8926e139feae4ccf6d Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 10 Dec 2018 13:55:11 -0600 Subject: [PATCH 1/4] remove trailing whitespace (#278) --- specs/core/0_beacon-chain.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index cad7507e9..be3e66ebf 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -225,7 +225,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ### Signature domains -| Name | Value | +| Name | Value | | - | - | | `DOMAIN_DEPOSIT` | `0` | | `DOMAIN_ATTESTATION` | `1` | @@ -1136,7 +1136,7 @@ def get_new_validators(validators: List[ValidatorRecord], ) validators_copy = copy.deepcopy(validators) validator_pubkeys = [v.pubkey for v in validators_copy] - + if pubkey not in validator_pubkeys: # Add new validator validator = ValidatorRecord( @@ -1167,7 +1167,7 @@ def get_new_validators(validators: List[ValidatorRecord], return validators_copy, index ``` -`BLSVerify` is a function for verifying a BLS12-381 signature, defined in the [BLS12-381 spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/bls_verify.md). +`BLSVerify` is a function for verifying a BLS12-381 signature, defined in the [BLS12-381 spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/bls_verify.md). Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn-validator)'s balance: ```python @@ -1227,7 +1227,7 @@ def exit_validator(index: int, if new_status == EXITED_WITH_PENALTY: state.latest_penalized_exit_balances[state.slot // COLLECTIVE_PENALTY_CALCULATION_PERIOD] += get_effective_balance(validator) - + whistleblower = state.validator_registry[get_beacon_proposer_index(state, state.slot)] whistleblower_reward = validator.balance // WHISTLEBLOWER_REWARD_QUOTIENT whistleblower.balance += whistleblower_reward @@ -1432,7 +1432,7 @@ For every `shard_committee` in `state.shard_committees_at_slots`: * Let `total_balance(shard_committee) = sum([get_effective_balance(v) for v in shard_committee.committee])`. * Let `inclusion_slot(v) = a.slot_included` for the attestation `a` where `v` is in `get_attestation_participants(state, a.data, a.participation_bitfield)`. * Let `inclusion_distance(v) = a.slot_included - a.data.slot` where `a` is the above attestation. -* Let `adjust_for_inclusion_distance(magnitude, distance)` be the function below. +* Let `adjust_for_inclusion_distance(magnitude, distance)` be the function below. ```python def adjust_for_inclusion_distance(magnitude: int, distance: int) -> int: @@ -1537,7 +1537,7 @@ def get_updated_validator_registry(validator_registry: List[ValidatorRecord], active_validator_indices = get_active_validator_indices(validator_registry) # The total effective balance of active validators total_balance = sum([get_effective_balance(v) for i, v in enumerate(validator_registry) if i in active_validator_indices]) - + # The maximum balance churn in Gwei (for deposits and exits separately) max_balance_churn = max( MAX_DEPOSIT * GWEI_PER_ETH, @@ -1563,7 +1563,7 @@ def get_updated_validator_registry(validator_registry: List[ValidatorRecord], flag=ACTIVATION, ) - # Exit validators within the allowable balance churn + # Exit validators within the allowable balance churn balance_churn = 0 for i, validator in enumerate(validator_registry): if validator.status == ACTIVE_PENDING_EXIT: @@ -1662,7 +1662,7 @@ This section is divided into Normative and Informative references. Normative re ## Normative ## Informative - _**python-poc**_ + _**python-poc**_   _Python proof-of-concept implementation_. Ethereum Foundation. URL: https://github.com/ethereum/beacon_chain # Copyright From 2facc754ccc9c57191e51e596db9705133520abe Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 10 Dec 2018 14:38:32 -0600 Subject: [PATCH 2/4] attestations: avoid unsigned underflow (eth2.0-specs/issues/#224) * and some nitpicks --- specs/core/0_beacon-chain.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index be3e66ebf..ccd337a9b 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1319,16 +1319,16 @@ Verify that `len(block.body.attestations) <= MAX_ATTESTATIONS`. For each `attestation` in `block.body.attestations`: -* Verify that `attestation.data.slot <= state.slot - MIN_ATTESTATION_INCLUSION_DELAY`. -* Verify that `attestation.data.slot >= max(state.slot - EPOCH_LENGTH, 0)`. +* Verify that `attestation.data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot`. +* Verify that `attestation.data.slot + EPOCH_LENGTH >= state.slot`. * Verify that `attestation.data.justified_slot` is equal to `state.justified_slot if attestation.data.slot >= state.slot - (state.slot % EPOCH_LENGTH) else state.previous_justified_slot`. * Verify that `attestation.data.justified_block_hash` is equal to `get_block_hash(state, attestation.data.justified_slot)`. * Verify that either `attestation.data.latest_crosslink_hash` or `attestation.data.shard_block_hash` equals `state.latest_crosslinks[shard].shard_block_hash`. * `aggregate_signature` verification: * Let `participants = get_attestation_participants(state, attestation.data, attestation.participation_bitfield)`. * Let `group_public_key = BLSAddPubkeys([state.validator_registry[v].pubkey for v in participants])`. - * Verify that `BLSVerify(pubkey=group_public_key, msg=SSZTreeHash(attestation.data) + bytes1(0), sig=aggregate_signature, domain=get_domain(state.fork_data, slot, DOMAIN_ATTESTATION))`. -* [TO BE REMOVED IN PHASE 1] Verify that `shard_block_hash == ZERO_HASH`. + * Verify that `BLSVerify(pubkey=group_public_key, msg=SSZTreeHash(attestation.data) + bytes1(0), sig=attestation.aggregate_signature, domain=get_domain(state.fork_data, attestation.data.slot, DOMAIN_ATTESTATION))`. +* [TO BE REMOVED IN PHASE 1] Verify that `attestation.data.shard_block_hash == ZERO_HASH`. * Append `PendingAttestationRecord(data=attestation.data, participation_bitfield=attestation.participation_bitfield, custody_bitfield=attestation.custody_bitfield, slot_included=state.slot)` to `state.latest_attestations`. #### Deposits From ed3611904db994b54963604f3cdaec05790e68ca Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 10 Dec 2018 13:32:16 -0800 Subject: [PATCH 3/4] update reference to hash function --- specs/simple-serialize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index 82d472ea4..d7ac4e992 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -392,7 +392,7 @@ return typ(**values), item_index The below `SSZTreeHash` algorithm is defined recursively in the case of lists and containers, and it outputs a value equal to or less than 32 bytes in size. For the final output only (ie. not intermediate outputs), if the output is less than 32 bytes, right-zero-pad it to 32 bytes. The goal is collision resistance *within* each type, not between types. -We define `hash(x)` as `BLAKE2b-512(x)[0:32]`. +Refer to Appendix A of Phase 0 of the [Eth2.0 specs](https://github.com/ethereum/eth2.0-specs) for a definition of the hash function used below, `hash(x)`. #### `uint8`..`uint256`, `bool`, `address`, `hash1`..`hash32` From 49f3cfebdf40d1498a279253224711681ba6b2f2 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 10 Dec 2018 16:22:42 -0600 Subject: [PATCH 4/4] add link to appendix A --- specs/simple-serialize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/simple-serialize.md b/specs/simple-serialize.md index d7ac4e992..46f73c045 100644 --- a/specs/simple-serialize.md +++ b/specs/simple-serialize.md @@ -392,7 +392,7 @@ return typ(**values), item_index The below `SSZTreeHash` algorithm is defined recursively in the case of lists and containers, and it outputs a value equal to or less than 32 bytes in size. For the final output only (ie. not intermediate outputs), if the output is less than 32 bytes, right-zero-pad it to 32 bytes. The goal is collision resistance *within* each type, not between types. -Refer to Appendix A of Phase 0 of the [Eth2.0 specs](https://github.com/ethereum/eth2.0-specs) for a definition of the hash function used below, `hash(x)`. +Refer to [Appendix A](https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#appendix-a---hash-function) of Phase 0 of the [Eth2.0 specs](https://github.com/ethereum/eth2.0-specs) for a definition of the hash function used below, `hash(x)`. #### `uint8`..`uint256`, `bool`, `address`, `hash1`..`hash32`