From 8ebc4dece847bb87daf3aa4ce6974ff37b60b2c2 Mon Sep 17 00:00:00 2001 From: Anton Nashatyrev Date: Fri, 11 Jan 2019 15:07:18 +0300 Subject: [PATCH 01/29] Local var should stay uint --- specs/core/0_beacon-chain.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 22e8c6dfe..c1668bd98 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -921,9 +921,10 @@ def get_shard_committees_at_slot(state: BeaconState, """ Returns the ``ShardCommittee`` for the ``slot``. """ - earliest_slot_in_array = state.slot - (state.slot % EPOCH_LENGTH) - EPOCH_LENGTH - assert earliest_slot_in_array <= slot < earliest_slot_in_array + EPOCH_LENGTH * 2 - return state.shard_committees_at_slots[slot - earliest_slot_in_array] + state_epoch_slot = state.slot - (state.slot % EPOCH_LENGTH) + assert state_epoch_slot <= slot + EPOCH_LENGTH + assert slot < state_epoch_slot + EPOCH_LENGTH + return state.shard_committees_at_slots[slot - state_epoch_slot + EPOCH_LENGTH] ``` #### `get_block_root` From 23e3f4defe5cd10aa239094768fc9489a126a9ea Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:30:04 +0800 Subject: [PATCH 02/29] Rename `bytes1(x)`, `bytes2(x)`... function to `int_to_bytes1(x)`, `int_to_bytes2(x)`... --- specs/core/0_beacon-chain.md | 14 +++++++------- specs/core/1_shard-data-chains.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 2757d89a7..92c300b0d 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -75,7 +75,7 @@ - [`get_beacon_proposer_index`](#get_beacon_proposer_index) - [`merkle_root`](#merkle_root) - [`get_attestation_participants`](#get_attestation_participants) - - [`bytes1`, `bytes2`, ...](#bytes1-bytes2-) + - [`int_to_bytes1`, `int_to_bytes2`, ...](#int_to_bytes1-int_to_bytes2-) - [`get_effective_balance`](#get_effective_balance) - [`get_fork_version`](#get_fork_version) - [`get_domain`](#get_domain) @@ -190,9 +190,9 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted | `GENESIS_SLOT` | `0` | | `GENESIS_START_SHARD` | `0` | | `FAR_FUTURE_SLOT` | `2**64 - 1` | -| `ZERO_HASH` | `bytes32(0)` | -| `EMPTY_SIGNATURE` | `[bytes48(0), bytes48(0)]` | -| `BLS_WITHDRAWAL_PREFIX_BYTE` | `bytes1(0)` | +| `ZERO_HASH` | `int_to_bytes32(0)` | +| `EMPTY_SIGNATURE` | `[int_to_bytes48(0), int_to_bytes48(0)]` | +| `BLS_WITHDRAWAL_PREFIX_BYTE` | `int_to_bytes1(0)` | ### Time parameters @@ -894,7 +894,7 @@ def get_shuffling(seed: Hash32, committees_per_slot = get_committee_count_per_slot(len(active_validator_indices)) # Shuffle - seed = xor(seed, bytes32(slot)) + seed = xor(seed, int_to_bytes32(slot)) shuffled_active_validator_indices = shuffle(active_validator_indices, seed) # Split the shuffled list into epoch_length * committees_per_slot pieces @@ -1046,9 +1046,9 @@ def get_attestation_participants(state: BeaconState, return participants ``` -#### `bytes1`, `bytes2`, ... +#### `int_to_bytes1`, `int_to_bytes2`, ... -`bytes1(x): return x.to_bytes(1, 'big')`, `bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32. +`int_to_bytes1(x): return x.to_bytes(1, 'big')`, `int_to_bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32. #### `get_effective_balance` diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 973a0d332..cabe2934e 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -70,7 +70,7 @@ 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(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. +* Let `proposer_index = hash(state.randao_mix + int_to_bytes8(shard_id) + int_to_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_signature, domain=get_domain(state, slot, SHARD_ATTESTER_DOMAIN))` passes. ### Block Merklization helper From accd3cfd01a5ebe55440490a45fc46b826fb8050 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:33:59 +0800 Subject: [PATCH 03/29] Replace `hash32` with `bytes32` --- specs/core/0_beacon-chain.md | 56 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 92c300b0d..bc612473b 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -328,17 +328,17 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Shard number 'shard': 'uint64', # Hash of root of the signed beacon block - 'beacon_block_root': 'hash32', + 'beacon_block_root': 'bytes32', # Hash of root of the ancestor at the epoch boundary - 'epoch_boundary_root': 'hash32', + 'epoch_boundary_root': 'bytes32', # Shard block's hash of root - 'shard_block_root': 'hash32', + 'shard_block_root': 'bytes32', # Last crosslink's hash of root - 'latest_crosslink_root': 'hash32', + 'latest_crosslink_root': 'bytes32', # Slot of the last justified beacon block 'justified_slot': 'uint64', # Hash of the last justified beacon block - 'justified_block_root': 'hash32', + 'justified_block_root': 'bytes32', } ``` @@ -360,7 +360,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # Branch in the deposit tree - 'branch': '[hash32]', + 'branch': '[bytes32]', # Index in the deposit tree 'index': 'uint64', # Data @@ -388,11 +388,11 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # BLS pubkey 'pubkey': 'uint384', # Withdrawal credentials - 'withdrawal_credentials': 'hash32', + 'withdrawal_credentials': 'bytes32', # Initial RANDAO commitment - 'randao_commitment': 'hash32', + 'randao_commitment': 'bytes32', # Initial custody commitment - 'custody_commitment': 'hash32', + 'custody_commitment': 'bytes32', # A BLS signature of this `DepositInput` 'proof_of_possession': ['uint384'], } @@ -421,10 +421,10 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted { ## Header ## 'slot': 'uint64', - 'parent_root': 'hash32', - 'state_root': 'hash32', - 'randao_reveal': 'hash32', - 'deposit_root': 'hash32', + 'parent_root': 'bytes32', + 'state_root': 'bytes32', + 'randao_reveal': 'bytes32', + 'deposit_root': 'bytes32', 'signature': ['uint384'], ## Body ## @@ -458,7 +458,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Shard number (`BEACON_CHAIN_SHARD_NUMBER` for beacon chain) 'shard': 'uint64', # Block's hash of root - 'block_root': 'hash32', + 'block_root': 'bytes32', } ``` @@ -478,17 +478,17 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted 'validator_balances': ['uint64'], 'validator_registry_latest_change_slot': 'uint64', 'validator_registry_exit_count': 'uint64', - 'validator_registry_delta_chain_tip': 'hash32', # For light clients to track deltas + 'validator_registry_delta_chain_tip': 'bytes32', # For light clients to track deltas # Randomness and committees - 'latest_randao_mixes': ['hash32'], - 'latest_vdf_outputs': ['hash32'], + 'latest_randao_mixes': ['bytes32'], + 'latest_vdf_outputs': ['bytes32'], 'previous_epoch_start_shard': 'uint64', 'current_epoch_start_shard': 'uint64', 'previous_epoch_calculation_slot': 'uint64', 'current_epoch_calculation_slot': 'uint64', - 'previous_epoch_randao_mix': 'hash32', - 'current_epoch_randao_mix': 'hash32', + 'previous_epoch_randao_mix': 'bytes32', + 'current_epoch_randao_mix': 'bytes32', # Custody challenges 'custody_challenges': [CustodyChallenge], @@ -501,13 +501,13 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Recent state 'latest_crosslinks': [CrosslinkRecord], - 'latest_block_roots': ['hash32'], # Needed to process attestations, older to newer + 'latest_block_roots': ['bytes32'], # Needed to process attestations, older to newer 'latest_penalized_exit_balances': ['uint64'], # Balances penalized at every withdrawal period 'latest_attestations': [PendingAttestationRecord], - 'batched_block_roots': ['hash32'], + 'batched_block_roots': ['bytes32'], # Ethereum 1.0 deposit root - 'latest_deposit_root': 'hash32', + 'latest_deposit_root': 'bytes32', 'deposit_root_votes': [DepositRootVote], } ``` @@ -519,9 +519,9 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # BLS public key 'pubkey': 'uint384', # Withdrawal credentials - 'withdrawal_credentials': 'hash32', + 'withdrawal_credentials': 'bytes32', # RANDAO commitment - 'randao_commitment': 'hash32', + 'randao_commitment': 'bytes32', # Slots the proposer has skipped (i.e. layers of RANDAO expected) 'randao_layers': 'uint64', # Slot when validator activated @@ -537,7 +537,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Status flags 'status_flags': 'uint64', # Custody commitment - 'custody_commitment': 'hash32', + 'custody_commitment': 'bytes32', # Slot of latest custody reseed 'latest_custody_reseed_slot': 'uint64', # Slot of second-latest custody reseed @@ -552,7 +552,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Slot number 'slot': 'uint64', # Shard block root - 'shard_block_root': 'hash32', + 'shard_block_root': 'bytes32', } ``` @@ -561,7 +561,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # Deposit root - 'deposit_root': 'hash32', + 'deposit_root': 'bytes32', # Vote count 'vote_count': 'uint64', } @@ -599,7 +599,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { - latest_registry_delta_root: 'hash32', + latest_registry_delta_root: 'bytes32', validator_index: 'uint24', pubkey: 'uint384', slot: 'uint64', From 8d5fd404a76d0d879b07582bcd1459183d6a3fa6 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:42:46 +0800 Subject: [PATCH 04/29] Add `Signature` SSZ obj --- specs/core/0_beacon-chain.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index bc612473b..cbca62b97 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -21,6 +21,8 @@ - [Validator registry delta flags](#validator-registry-delta-flags) - [Signature domains](#signature-domains) - [Data structures](#data-structures) + - [Signatures](#signatures) + - [`Signature`](#signature) - [Beacon chain operations](#beacon-chain-operations) - [Proposer slashings](#proposer-slashings) - [`ProposerSlashing`](#proposerslashing) @@ -253,6 +255,17 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ## Data structures +### Signatures + +#### `Signature` + +```python +{ + 'z_1': 'bytes48', + 'z_2': 'bytes48', +} +``` + ### Beacon chain operations #### Proposer slashings From b515683e391197becf4cd788bf48de0a73147b6b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:44:23 +0800 Subject: [PATCH 05/29] Replace `'[uint384]'` with Signature --- specs/core/0_beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index cbca62b97..cf284b169 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -279,11 +279,11 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # First proposal data 'proposal_data_1': ProposalSignedData, # First proposal signature - 'proposal_signature_1': '[uint384]', + 'proposal_signature_1': Signature, # Second proposal data 'proposal_data_2': ProposalSignedData, # Second proposal signature - 'proposal_signature_2': '[uint384]', + 'proposal_signature_2': Signature, } ``` @@ -422,7 +422,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Index of the exiting validator 'validator_index': 'uint24', # Validator signature - 'signature': '[uint384]', + 'signature': Signature, } ``` From 7005e5fd55f007ff0c15a518036def669716f77b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:49:08 +0800 Subject: [PATCH 06/29] Replace `['uint384']` with `Signature` --- 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 cf284b169..7873a5aa4 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -311,7 +311,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Attestation data 'data': AttestationData, # Aggregate signature - 'aggregate_signature': ['uint384'], + 'aggregate_signature': Signature, } ``` @@ -328,7 +328,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Custody bitfield 'custody_bitfield': 'bytes', # BLS aggregate signature - 'aggregate_signature': ['uint384'], + 'aggregate_signature': Signature, } ``` @@ -407,7 +407,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Initial custody commitment 'custody_commitment': 'bytes32', # A BLS signature of this `DepositInput` - 'proof_of_possession': ['uint384'], + 'proof_of_possession': Signature, } ``` @@ -438,7 +438,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted 'state_root': 'bytes32', 'randao_reveal': 'bytes32', 'deposit_root': 'bytes32', - 'signature': ['uint384'], + 'signature': Signature, ## Body ## 'body': BeaconBlockBody, From a588643661563d5419bdbf450819e3aeeb1c2a07 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:51:50 +0800 Subject: [PATCH 07/29] Replace `uint384` with `bytes48` for pubkey --- specs/core/0_beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7873a5aa4..bc8fcfa7c 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -399,7 +399,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # BLS pubkey - 'pubkey': 'uint384', + 'pubkey': 'bytes48', # Withdrawal credentials 'withdrawal_credentials': 'bytes32', # Initial RANDAO commitment @@ -530,7 +530,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # BLS public key - 'pubkey': 'uint384', + 'pubkey': 'bytes48', # Withdrawal credentials 'withdrawal_credentials': 'bytes32', # RANDAO commitment @@ -614,7 +614,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted { latest_registry_delta_root: 'bytes32', validator_index: 'uint24', - pubkey: 'uint384', + pubkey: 'bytes48', slot: 'uint64', flag: 'uint64', } From 14891047d71263e34f82ee5a1e1841b1a511d5b9 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:52:56 +0800 Subject: [PATCH 08/29] Update `EMPTY_SIGNATURE` --- 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 bc8fcfa7c..89036acb9 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -193,7 +193,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted | `GENESIS_START_SHARD` | `0` | | `FAR_FUTURE_SLOT` | `2**64 - 1` | | `ZERO_HASH` | `int_to_bytes32(0)` | -| `EMPTY_SIGNATURE` | `[int_to_bytes48(0), int_to_bytes48(0)]` | +| `EMPTY_SIGNATURE` | `Signature(int_to_bytes48(0), int_to_bytes48(0))` | | `BLS_WITHDRAWAL_PREFIX_BYTE` | `int_to_bytes1(0)` | ### Time parameters From 61f5d99dee28b9e974f8d66e8bd9387bb20dca03 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:54:38 +0800 Subject: [PATCH 09/29] Fix `Deposit.branch` type notation --- 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 89036acb9..b584bd4be 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -373,7 +373,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ```python { # Branch in the deposit tree - 'branch': '[bytes32]', + 'branch': ['bytes32'], # Index in the deposit tree 'index': 'uint64', # Data From 0b10b0444a4e6c4f5bf548344796df76dd6d5657 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 16:56:33 +0800 Subject: [PATCH 10/29] Replace `Hash32` with `Bytes32` --- specs/core/0_beacon-chain.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b584bd4be..d3ffa7632 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -810,7 +810,7 @@ def get_active_validator_indices(validators: [ValidatorRecord], slot: int) -> Li #### `shuffle` ```python -def shuffle(values: List[Any], seed: Hash32) -> List[Any]: +def shuffle(values: List[Any], seed: Bytes32) -> List[Any]: """ Returns the shuffled ``values`` with ``seed`` as entropy. """ @@ -890,7 +890,7 @@ def get_committee_count_per_slot(active_validator_count: int) -> int: #### `get_shuffling` ```python -def get_shuffling(seed: Hash32, +def get_shuffling(seed: Bytes32, validators: List[ValidatorRecord], slot: int) -> List[List[int]] """ @@ -984,7 +984,7 @@ def get_crosslink_committees_at_slot(state: BeaconState, ```python def get_block_root(state: BeaconState, - slot: int) -> Hash32: + slot: int) -> Bytes32: """ Returns the block root at a recent ``slot``. """ @@ -999,7 +999,7 @@ def get_block_root(state: BeaconState, ```python def get_randao_mix(state: BeaconState, - slot: int) -> Hash32: + slot: int) -> Bytes32: """ Returns the randao mix at a recent ``slot``. """ @@ -1023,7 +1023,7 @@ def get_beacon_proposer_index(state: BeaconState, #### `merkle_root` ```python -def merkle_root(values: List[Hash32]) -> Hash32: +def merkle_root(values: List[Bytes32]) -> Bytes32: """ Merkleize ``values`` (where ``len(values)`` is a power of two) and return the Merkle root. """ @@ -1217,7 +1217,7 @@ A valid block with slot `GENESIS_SLOT` (a "genesis block") has the following val ```python def get_initial_beacon_state(initial_validator_deposits: List[Deposit], genesis_time: int, - latest_deposit_root: Hash32) -> BeaconState: + latest_deposit_root: Bytes32) -> BeaconState: state = BeaconState( # Misc slot=GENESIS_SLOT, @@ -1294,9 +1294,9 @@ First, a helper function: def validate_proof_of_possession(state: BeaconState, pubkey: int, proof_of_possession: bytes, - withdrawal_credentials: Hash32, - randao_commitment: Hash32, - custody_commitment: Hash32) -> bool: + withdrawal_credentials: Bytes32, + randao_commitment: Bytes32, + custody_commitment: Bytes32) -> bool: proof_of_possession_data = DepositInput( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, @@ -1324,9 +1324,9 @@ def process_deposit(state: BeaconState, pubkey: int, amount: int, proof_of_possession: bytes, - withdrawal_credentials: Hash32, - randao_commitment: Hash32, - custody_commitment: Hash32) -> None: + withdrawal_credentials: Bytes32, + randao_commitment: Bytes32, + custody_commitment: Bytes32) -> None: """ Process a deposit from Ethereum 1.0. Note that this function mutates ``state``. @@ -1550,7 +1550,7 @@ For each `deposit` in `block.body.deposits`: * Verify that `verify_merkle_branch(hash(serialized_deposit_data), deposit.branch, DEPOSIT_CONTRACT_TREE_DEPTH, deposit.index, state.latest_deposit_root)` is `True`. ```python -def verify_merkle_branch(leaf: Hash32, branch: [Hash32], depth: int, index: int, root: Hash32) -> bool: +def verify_merkle_branch(leaf: Bytes32, branch: [Bytes32], depth: int, index: int, root: Bytes32) -> bool: value = leaf for i in range(depth): if index // (2**i) % 2: From 725199593bdee4389a9ded72b1c25054830485d2 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 17:00:39 +0800 Subject: [PATCH 11/29] For pubkey type hinting, use `bytes` for now. --- 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 d3ffa7632..7a12c6a2a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1292,7 +1292,7 @@ First, a helper function: ```python def validate_proof_of_possession(state: BeaconState, - pubkey: int, + pubkey: bytes, proof_of_possession: bytes, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, @@ -1321,7 +1321,7 @@ Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn ```python def process_deposit(state: BeaconState, - pubkey: int, + pubkey: bytes, amount: int, proof_of_possession: bytes, withdrawal_credentials: Bytes32, From 713af88c4311edb1b3ce23c231ddc8aac70f7b58 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 17:03:20 +0800 Subject: [PATCH 12/29] `proof_of_possession: Signature` --- 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 7a12c6a2a..56207a4ca 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1293,7 +1293,7 @@ First, a helper function: ```python def validate_proof_of_possession(state: BeaconState, pubkey: bytes, - proof_of_possession: bytes, + proof_of_possession: Signature, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> bool: @@ -1323,7 +1323,7 @@ Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn def process_deposit(state: BeaconState, pubkey: bytes, amount: int, - proof_of_possession: bytes, + proof_of_possession: Signature, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> None: From 209220787b4fbfb8300b685dfd37bfa681fe7a76 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 17:29:28 +0800 Subject: [PATCH 13/29] Deal with BLS APIs, will define `Bytes48` in the type hinting cleanup --- specs/bls_signature.md | 8 ++++---- specs/core/0_beacon-chain.md | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/specs/bls_signature.md b/specs/bls_signature.md index 8e0b76c6b..75827982b 100644 --- a/specs/bls_signature.md +++ b/specs/bls_signature.md @@ -106,11 +106,11 @@ def modular_squareroot(value: int) -> int: ### `bls_aggregate_pubkeys` -Let `bls_aggregate_pubkeys(pubkeys: [uint384]) -> uint384` return `pubkeys[0] + .... + pubkeys[len(pubkeys)-1]`, where `+` is the elliptic curve addition operation over the G1 curve. +Let `bls_aggregate_pubkeys(pubkeys: List[Bytes48]) -> Bytes48` return `pubkeys[0] + .... + pubkeys[len(pubkeys)-1]`, where `+` is the elliptic curve addition operation over the G1 curve. ### `bls_aggregate_signatures` -Let `bls_aggregate_signatures(signatures: [[uint384]]) -> [uint384]` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. +Let `bls_aggregate_signatures(signatures: Tuple[Bytes48, Bytes48]) -> Tuple[Bytes48, Bytes48]` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. ## Signature verification @@ -124,7 +124,7 @@ g = Fq2(g_x, g_y) ### `bls_verify` -Let `bls_verify(pubkey: uint384, message: bytes32, signature: [uint384], domain: uint64) -> bool`: +Let `bls_verify(pubkey: Bytes48, message: Bytes32, signature: Tuple[Bytes48, Bytes48], domain: uint64) -> bool`: * Verify that `pubkey` is a valid G1 point. * Verify that `signature` is a valid G2 point. @@ -132,7 +132,7 @@ Let `bls_verify(pubkey: uint384, message: bytes32, signature: [uint384], domain: ### `bls_verify_multiple` -Let `bls_verify_multiple(pubkeys: [uint384], messages: [bytes32], signature: [uint384], domain: uint64) -> bool`: +Let `bls_verify_multiple(pubkeys: List[Bytes48], messages: List[Bytes32], signature: Tuple[Bytes48, Bytes48], domain: uint64) -> bool`: * Verify that each `pubkey` in `pubkeys` is a valid G1 point. * Verify that `signature` is a valid G2 point. diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 56207a4ca..17e9ca24f 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -85,6 +85,7 @@ - [`is_double_vote`](#is_double_vote) - [`is_surround_vote`](#is_surround_vote) - [`integer_squareroot`](#integer_squareroot) + - [`signature_to_tuple`](#signature_to_tuple) - [`bls_verify`](#bls_verify) - [`bls_verify_multiple`](#bls_verify_multiple) - [`bls_aggregate_pubkeys`](#bls_aggregate_pubkeys) @@ -1112,7 +1113,7 @@ def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, False)), hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, True)), ], - signature=vote_data.aggregate_signature, + signature=signature_to_tuple(vote_data.aggregate_signature), domain=get_domain( state.fork_data, state.slot, @@ -1175,6 +1176,16 @@ def integer_squareroot(n: int) -> int: return x ``` +#### `signature_to_tuple` + +```python +def signature_to_tuple(signature: Signature) -> Tuple[bytes, bytes]: + """ + Convert SSZ object ``signature`` to ``tuple`` type for BLS APIs. + """ + return (signature.z_1, signature.z_2) +``` + #### `bls_verify` `bls_verify` is a function for verifying a BLS signature, defined in the [BLS Signature spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/bls_signature.md#bls_verify). @@ -1308,7 +1319,7 @@ def validate_proof_of_possession(state: BeaconState, return bls_verify( pubkey=pubkey, message=hash_tree_root(proof_of_possession_data), - signature=proof_of_possession, + signature=signature_to_tuple(proof_of_possession), domain=get_domain( state.fork_data, state.slot, @@ -1469,7 +1480,7 @@ Below are the processing steps that happen at every `block`. * Let `block_without_signature_root` be the `hash_tree_root` of `block` where `block.signature` is set to `EMPTY_SIGNATURE`. * Let `proposal_root = hash_tree_root(ProposalSignedData(state.slot, BEACON_CHAIN_SHARD_NUMBER, block_without_signature_root))`. -* Verify that `bls_verify(pubkey=state.validator_registry[get_beacon_proposer_index(state, state.slot)].pubkey, message=proposal_root, signature=block.signature, domain=get_domain(state.fork_data, state.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=state.validator_registry[get_beacon_proposer_index(state, state.slot)].pubkey, message=proposal_root, signature=signature_to_tuple(block.signature), domain=get_domain(state.fork_data, state.slot, DOMAIN_PROPOSAL))`. ### RANDAO @@ -1498,8 +1509,8 @@ For each `proposer_slashing` in `block.body.proposer_slashings`: * Verify that `proposer_slashing.proposal_data_1.shard == proposer_slashing.proposal_data_2.shard`. * Verify that `proposer_slashing.proposal_data_1.block_root != proposer_slashing.proposal_data_2.block_root`. * Verify that `proposer.penalized_slot > state.slot`. -* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_1), signature=proposer_slashing.proposal_signature_1, domain=get_domain(state.fork_data, proposer_slashing.proposal_data_1.slot, DOMAIN_PROPOSAL))`. -* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_2), signature=proposer_slashing.proposal_signature_2, domain=get_domain(state.fork_data, proposer_slashing.proposal_data_2.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_1), signature=signature_to_tuple(proposer_slashing.proposal_signature_1), domain=get_domain(state.fork_data, proposer_slashing.proposal_data_1.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_2), signature=signature_to_tuple(proposer_slashing.proposal_signature_2), domain=get_domain(state.fork_data, proposer_slashing.proposal_data_2.slot, DOMAIN_PROPOSAL))`. * Run `penalize_validator(state, proposer_slashing.proposer_index)`. #### Casper slashings @@ -1533,7 +1544,7 @@ For each `attestation` in `block.body.attestations`: * `aggregate_signature` verification: * Let `participants = get_attestation_participants(state, attestation.data, attestation.participation_bitfield)`. * Let `group_public_key = bls_aggregate_pubkeys([state.validator_registry[v].pubkey for v in participants])`. - * Verify that `bls_verify(pubkey=group_public_key, message=hash_tree_root(AttestationDataAndCustodyBit(attestation.data, False)), signature=attestation.aggregate_signature, domain=get_domain(state.fork_data, attestation.data.slot, DOMAIN_ATTESTATION))`. + * Verify that `bls_verify(pubkey=group_public_key, message=hash_tree_root(AttestationDataAndCustodyBit(attestation.data, False)), signature=signature_to_tuple(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_root == 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`. @@ -1583,7 +1594,7 @@ For each `exit` in `block.body.exits`: * Let `validator = state.validator_registry[exit.validator_index]`. * Verify that `validator.exit_slot > state.slot + ENTRY_EXIT_DELAY`. * Verify that `state.slot >= exit.slot`. -* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork_data, exit.slot, DOMAIN_EXIT))`. +* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=signature_to_tuple(exit.signature), domain=get_domain(state.fork_data, exit.slot, DOMAIN_EXIT))`. * Run `initiate_validator_exit(state, exit.validator_index)`. #### Custody From ba7bc29ce9308d8f0407dc34d128fa63fc53eeb4 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 17:36:31 +0800 Subject: [PATCH 14/29] Fix `bls_aggregate_signatures` --- specs/bls_signature.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/bls_signature.md b/specs/bls_signature.md index 75827982b..bbb40e7c8 100644 --- a/specs/bls_signature.md +++ b/specs/bls_signature.md @@ -110,7 +110,7 @@ Let `bls_aggregate_pubkeys(pubkeys: List[Bytes48]) -> Bytes48` return `pubkeys[0 ### `bls_aggregate_signatures` -Let `bls_aggregate_signatures(signatures: Tuple[Bytes48, Bytes48]) -> Tuple[Bytes48, Bytes48]` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. +Let `bls_aggregate_signatures(signatures: List[Tuple[Bytes48, Bytes48]]) -> Tuple[Bytes48, Bytes48]` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. ## Signature verification From 18b97cf922b9c0d2035c8e3e014e4087e9dd3f6f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 17 Jan 2019 19:40:26 +0800 Subject: [PATCH 15/29] pubkey: Bytes48 --- 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 17e9ca24f..981344116 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1303,7 +1303,7 @@ First, a helper function: ```python def validate_proof_of_possession(state: BeaconState, - pubkey: bytes, + pubkey: Bytes48, proof_of_possession: Signature, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, @@ -1332,7 +1332,7 @@ Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn ```python def process_deposit(state: BeaconState, - pubkey: bytes, + pubkey: Bytes48, amount: int, proof_of_possession: Signature, withdrawal_credentials: Bytes32, From 4d05d3385856c73eaca5b3d6f5c894236ea1b9a0 Mon Sep 17 00:00:00 2001 From: jannikluhn Date: Thu, 17 Jan 2019 18:35:12 +0100 Subject: [PATCH 16/29] Add links to accompanying documents to readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9563c97ed..169e00cee 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ Core specifications for eth2.0 client validation can be found in [specs/core](sp * [Phase 0 -- The Beacon Chain](specs/core/0_beacon-chain.md) * [Phase 1 -- Shard Data Chains](specs/core/1_shard-data-chains.md) +Accompanying documents can be found in [specs](specs) and include +* [SimpleSerialize (SSZ) spec](specs/simple_serialize.md) +* [BLS signature verification](specs/bls_signature.md) +* [General test format](specs/test-format.md) + ## Design goals The following are the broad design goals for Ethereum 2.0: * to minimize complexity, even at the cost of some losses in efficiency From 3ada70c2f00c78135c06b5f0877ec7259408fdc1 Mon Sep 17 00:00:00 2001 From: jannikluhn Date: Thu, 17 Jan 2019 18:39:58 +0100 Subject: [PATCH 17/29] Fix link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 169e00cee..f3aba3f64 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Core specifications for eth2.0 client validation can be found in [specs/core](sp * [Phase 1 -- Shard Data Chains](specs/core/1_shard-data-chains.md) Accompanying documents can be found in [specs](specs) and include -* [SimpleSerialize (SSZ) spec](specs/simple_serialize.md) +* [SimpleSerialize (SSZ) spec](specs/simple-serialize.md) * [BLS signature verification](specs/bls_signature.md) * [General test format](specs/test-format.md) From 91eba49eebae8f5f95b950c907182a6687e503bb Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 17 Jan 2019 13:00:29 -0600 Subject: [PATCH 18/29] fix slot for domain in verify_slashable_vote_data (#465) --- 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 0ba9b5bcc..6f970f8be 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1113,7 +1113,7 @@ def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) signature=vote_data.aggregate_signature, domain=get_domain( state.fork, - state.slot, + vote_data.data.slot, DOMAIN_ATTESTATION, ), ) From 063f6586971f54a2583d22683a7e659a5f7dbd52 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 18 Jan 2019 03:19:38 +0800 Subject: [PATCH 19/29] `bytes96` for Signature --- specs/bls_signature.md | 6 ++-- specs/core/0_beacon-chain.md | 58 +++++++++++------------------------- 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/specs/bls_signature.md b/specs/bls_signature.md index bbb40e7c8..11264c251 100644 --- a/specs/bls_signature.md +++ b/specs/bls_signature.md @@ -110,7 +110,7 @@ Let `bls_aggregate_pubkeys(pubkeys: List[Bytes48]) -> Bytes48` return `pubkeys[0 ### `bls_aggregate_signatures` -Let `bls_aggregate_signatures(signatures: List[Tuple[Bytes48, Bytes48]]) -> Tuple[Bytes48, Bytes48]` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. +Let `bls_aggregate_signatures(signatures: List[Bytes96]) -> Bytes96` return `signatures[0] + .... + signatures[len(signatures)-1]`, where `+` is the elliptic curve addition operation over the G2 curve. ## Signature verification @@ -124,7 +124,7 @@ g = Fq2(g_x, g_y) ### `bls_verify` -Let `bls_verify(pubkey: Bytes48, message: Bytes32, signature: Tuple[Bytes48, Bytes48], domain: uint64) -> bool`: +Let `bls_verify(pubkey: Bytes48, message: Bytes32, signature: Bytes96, domain: uint64) -> bool`: * Verify that `pubkey` is a valid G1 point. * Verify that `signature` is a valid G2 point. @@ -132,7 +132,7 @@ Let `bls_verify(pubkey: Bytes48, message: Bytes32, signature: Tuple[Bytes48, Byt ### `bls_verify_multiple` -Let `bls_verify_multiple(pubkeys: List[Bytes48], messages: List[Bytes32], signature: Tuple[Bytes48, Bytes48], domain: uint64) -> bool`: +Let `bls_verify_multiple(pubkeys: List[Bytes48], messages: List[Bytes32], signature: Bytes96, domain: uint64) -> bool`: * Verify that each `pubkey` in `pubkeys` is a valid G1 point. * Verify that `signature` is a valid G2 point. diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index f67c4b896..f97c19ac3 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -21,8 +21,6 @@ - [Validator registry delta flags](#validator-registry-delta-flags) - [Signature domains](#signature-domains) - [Data structures](#data-structures) - - [Signatures](#signatures) - - [`Signature`](#signature) - [Beacon chain operations](#beacon-chain-operations) - [Proposer slashings](#proposer-slashings) - [`ProposerSlashing`](#proposerslashing) @@ -86,7 +84,6 @@ - [`is_double_vote`](#is_double_vote) - [`is_surround_vote`](#is_surround_vote) - [`integer_squareroot`](#integer_squareroot) - - [`signature_to_tuple`](#signature_to_tuple) - [`bls_verify`](#bls_verify) - [`bls_verify_multiple`](#bls_verify_multiple) - [`bls_aggregate_pubkeys`](#bls_aggregate_pubkeys) @@ -194,7 +191,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted | `GENESIS_START_SHARD` | `0` | | `FAR_FUTURE_SLOT` | `2**64 - 1` | | `ZERO_HASH` | `int_to_bytes32(0)` | -| `EMPTY_SIGNATURE` | `Signature(int_to_bytes48(0), int_to_bytes48(0))` | +| `EMPTY_SIGNATURE` | `int_to_bytes96(0)` | | `BLS_WITHDRAWAL_PREFIX_BYTE` | `int_to_bytes1(0)` | ### Time parameters @@ -256,17 +253,6 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted ## Data structures -### Signatures - -#### `Signature` - -```python -{ - 'z_1': 'bytes48', - 'z_2': 'bytes48', -} -``` - ### Beacon chain operations #### Proposer slashings @@ -280,11 +266,11 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # First proposal data 'proposal_data_1': ProposalSignedData, # First proposal signature - 'proposal_signature_1': Signature, + 'proposal_signature_1': 'bytes96', # Second proposal data 'proposal_data_2': ProposalSignedData, # Second proposal signature - 'proposal_signature_2': Signature, + 'proposal_signature_2': 'bytes96', } ``` @@ -312,7 +298,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Attestation data 'data': AttestationData, # Aggregate signature - 'aggregate_signature': Signature, + 'aggregate_signature': 'bytes96', } ``` @@ -329,7 +315,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Custody bitfield 'custody_bitfield': 'bytes', # BLS aggregate signature - 'aggregate_signature': Signature, + 'aggregate_signature': 'bytes96', } ``` @@ -408,7 +394,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Initial custody commitment 'custody_commitment': 'bytes32', # A BLS signature of this `DepositInput` - 'proof_of_possession': Signature, + 'proof_of_possession': 'bytes96', } ``` @@ -423,7 +409,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted # Index of the exiting validator 'validator_index': 'uint24', # Validator signature - 'signature': Signature, + 'signature': 'bytes96', } ``` @@ -439,7 +425,7 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted 'state_root': 'bytes32', 'randao_reveal': 'bytes32', 'eth1_data': Eth1Data, - 'signature': Signature, + 'signature': 'bytes96', ## Body ## 'body': BeaconBlockBody, @@ -1124,7 +1110,7 @@ def verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData) hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, False)), hash_tree_root(AttestationDataAndCustodyBit(vote_data.data, True)), ], - signature=signature_to_tuple(vote_data.aggregate_signature), + signature=vote_data.aggregate_signature, domain=get_domain( state.fork, state.slot, @@ -1187,16 +1173,6 @@ def integer_squareroot(n: int) -> int: return x ``` -#### `signature_to_tuple` - -```python -def signature_to_tuple(signature: Signature) -> Tuple[bytes, bytes]: - """ - Convert SSZ object ``signature`` to ``tuple`` type for BLS APIs. - """ - return (signature.z_1, signature.z_2) -``` - #### `bls_verify` `bls_verify` is a function for verifying a BLS signature, defined in the [BLS Signature spec](https://github.com/ethereum/eth2.0-specs/blob/master/specs/bls_signature.md#bls_verify). @@ -1318,7 +1294,7 @@ First, a helper function: ```python def validate_proof_of_possession(state: BeaconState, pubkey: Bytes48, - proof_of_possession: Signature, + proof_of_possession: Bytes96, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> bool: @@ -1333,7 +1309,7 @@ def validate_proof_of_possession(state: BeaconState, return bls_verify( pubkey=pubkey, message=hash_tree_root(proof_of_possession_data), - signature=signature_to_tuple(proof_of_possession), + signature=proof_of_possession, domain=get_domain( state.fork, state.slot, @@ -1348,7 +1324,7 @@ Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn def process_deposit(state: BeaconState, pubkey: Bytes48, amount: int, - proof_of_possession: Signature, + proof_of_possession: Bytes96, withdrawal_credentials: Bytes32, randao_commitment: Bytes32, custody_commitment: Bytes32) -> None: @@ -1494,7 +1470,7 @@ Below are the processing steps that happen at every `block`. * Let `block_without_signature_root` be the `hash_tree_root` of `block` where `block.signature` is set to `EMPTY_SIGNATURE`. * Let `proposal_root = hash_tree_root(ProposalSignedData(state.slot, BEACON_CHAIN_SHARD_NUMBER, block_without_signature_root))`. -* Verify that `bls_verify(pubkey=state.validator_registry[get_beacon_proposer_index(state, state.slot)].pubkey, message=proposal_root, signature=signature_to_tuple(block.signature), domain=get_domain(state.fork, state.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=state.validator_registry[get_beacon_proposer_index(state, state.slot)].pubkey, message=proposal_root, signature=block.signature, domain=get_domain(state.fork, state.slot, DOMAIN_PROPOSAL))`. ### RANDAO @@ -1523,8 +1499,8 @@ For each `proposer_slashing` in `block.body.proposer_slashings`: * Verify that `proposer_slashing.proposal_data_1.shard == proposer_slashing.proposal_data_2.shard`. * Verify that `proposer_slashing.proposal_data_1.block_root != proposer_slashing.proposal_data_2.block_root`. * Verify that `proposer.penalized_slot > state.slot`. -* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_1), signature=signature_to_tuple(proposer_slashing.proposal_signature_1), domain=get_domain(state.fork, proposer_slashing.proposal_data_1.slot, DOMAIN_PROPOSAL))`. -* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_2), signature=signature_to_tuple(proposer_slashing.proposal_signature_2), domain=get_domain(state.fork, proposer_slashing.proposal_data_2.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_1), signature=proposer_slashing.proposal_signature_1, domain=get_domain(state.fork, proposer_slashing.proposal_data_1.slot, DOMAIN_PROPOSAL))`. +* Verify that `bls_verify(pubkey=proposer.pubkey, message=hash_tree_root(proposer_slashing.proposal_data_2), signature=proposer_slashing.proposal_signature_2, domain=get_domain(state.fork, proposer_slashing.proposal_data_2.slot, DOMAIN_PROPOSAL))`. * Run `penalize_validator(state, proposer_slashing.proposer_index)`. #### Casper slashings @@ -1558,7 +1534,7 @@ For each `attestation` in `block.body.attestations`: * `aggregate_signature` verification: * Let `participants = get_attestation_participants(state, attestation.data, attestation.aggregation_bitfield)`. * Let `group_public_key = bls_aggregate_pubkeys([state.validator_registry[v].pubkey for v in participants])`. - * Verify that `bls_verify(pubkey=group_public_key, message=hash_tree_root(AttestationDataAndCustodyBit(attestation.data, False)), signature=signature_to_tuple(attestation.aggregate_signature), domain=get_domain(state.fork, attestation.data.slot, DOMAIN_ATTESTATION))`. + * Verify that `bls_verify(pubkey=group_public_key, message=hash_tree_root(AttestationDataAndCustodyBit(attestation.data, False)), signature=attestation.aggregate_signature, domain=get_domain(state.fork, attestation.data.slot, DOMAIN_ATTESTATION))`. * [TO BE REMOVED IN PHASE 1] Verify that `attestation.data.shard_block_root == ZERO_HASH`. * Append `PendingAttestation(data=attestation.data, aggregation_bitfield=attestation.aggregation_bitfield, custody_bitfield=attestation.custody_bitfield, slot_included=state.slot)` to `state.latest_attestations`. @@ -1608,7 +1584,7 @@ For each `exit` in `block.body.exits`: * Let `validator = state.validator_registry[exit.validator_index]`. * Verify that `validator.exit_slot > state.slot + ENTRY_EXIT_DELAY`. * Verify that `state.slot >= exit.slot`. -* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=signature_to_tuple(exit.signature), domain=get_domain(state.fork, exit.slot, DOMAIN_EXIT))`. +* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork, exit.slot, DOMAIN_EXIT))`. * Run `initiate_validator_exit(state, exit.validator_index)`. #### Custody From c8597a0d49b1ea82592e53149746493fb36c9e66 Mon Sep 17 00:00:00 2001 From: Dean Eigenmann Date: Fri, 18 Jan 2019 02:11:54 +0100 Subject: [PATCH 20/29] 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 6f970f8be..38a973365 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1606,7 +1606,7 @@ All [validators](#dfn-validator): * Let `current_epoch_attestations = [a for a in state.latest_attestations if state.slot - EPOCH_LENGTH <= a.data.slot < state.slot]`. (Note: this is the set of attestations of slots in the epoch `state.slot-EPOCH_LENGTH...state.slot-1`, _not_ attestations that got included in the chain during the epoch `state.slot-EPOCH_LENGTH...state.slot-1`.) * Validators justifying the epoch boundary block at the start of the current epoch: - * Let `current_epoch_boundary_attestations = [a for a in current_epoch_attestations if a.data.epoch_boundary_root == get_block_root(state, state.slot-EPOCH_LENGTH) and a.justified_slot == state.justified_slot]`. + * Let `current_epoch_boundary_attestations = [a for a in current_epoch_attestations if a.data.epoch_boundary_root == get_block_root(state, state.slot-EPOCH_LENGTH) and a.data.justified_slot == state.justified_slot]`. * Let `current_epoch_boundary_attester_indices` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in current_epoch_boundary_attestations]`. * Let `current_epoch_boundary_attesting_balance = sum([get_effective_balance(state, i) for i in current_epoch_boundary_attester_indices])`. @@ -1616,7 +1616,7 @@ All [validators](#dfn-validator): * 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.aggregation_bitfield) for a in previous_epoch_attestations]`. * 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_attestations = [a for a in current_epoch_attestations + previous_epoch_attestations if a.data.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.aggregation_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])`. * Validators justifying the epoch boundary block at the start of the previous epoch: From 96aac450b5b0360ac22c9d5d03527b5d9c8d762f Mon Sep 17 00:00:00 2001 From: Dean Eigenmann Date: Fri, 18 Jan 2019 02:22:12 +0100 Subject: [PATCH 21/29] 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 6f970f8be..2f3c3461e 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1620,7 +1620,7 @@ All [validators](#dfn-validator): * Let `previous_epoch_justified_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_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])`. * Validators justifying the epoch boundary block at the start of the previous epoch: - * Let `previous_epoch_boundary_attestations = [a for a in previous_epoch_justified_attestations if a.epoch_boundary_root == get_block_root(state, state.slot - 2 * EPOCH_LENGTH)]`. + * Let `previous_epoch_boundary_attestations = [a for a in previous_epoch_justified_attestations if a.data.epoch_boundary_root == get_block_root(state, state.slot - 2 * EPOCH_LENGTH)]`. * Let `previous_epoch_boundary_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in previous_epoch_boundary_attestations]`. * Let `previous_epoch_boundary_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_boundary_attester_indices])`. * Validators attesting to the expected beacon chain head during the previous epoch: From 15fdea5b1bf70338436fc4913df0368c3de6babd Mon Sep 17 00:00:00 2001 From: Dean Eigenmann Date: Fri, 18 Jan 2019 02:36:37 +0100 Subject: [PATCH 22/29] `a.beacon_block_root` -> `a.data.beacon_block_root` --- 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 6f970f8be..b630cb0a0 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1624,7 +1624,7 @@ All [validators](#dfn-validator): * Let `previous_epoch_boundary_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in previous_epoch_boundary_attestations]`. * Let `previous_epoch_boundary_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_boundary_attester_indices])`. * Validators attesting to the expected beacon chain head during the previous epoch: - * Let `previous_epoch_head_attestations = [a for a in previous_epoch_attestations if a.beacon_block_root == get_block_root(state, a.slot)]`. + * Let `previous_epoch_head_attestations = [a for a in previous_epoch_attestations if a.data.beacon_block_root == get_block_root(state, a.slot)]`. * Let `previous_epoch_head_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in previous_epoch_head_attestations]`. * Let `previous_epoch_head_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_head_attester_indices])`. From 690cf4b787585d9d0dea92a49b604a87dec0fe2c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 18 Jan 2019 16:21:58 +0800 Subject: [PATCH 23/29] PR feedback --- 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 f97c19ac3..006c4a54a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1059,7 +1059,7 @@ def get_attestation_participants(state: BeaconState, #### `int_to_bytes1`, `int_to_bytes2`, ... -`int_to_bytes1(x): return x.to_bytes(1, 'big')`, `int_to_bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32. +`int_to_bytes1(x): return x.to_bytes(1, 'big')`, `int_to_bytes2(x): return x.to_bytes(2, 'big')`, and so on for all integers, particularly 1, 2, 3, 4, 8, 32, 48, 96. #### `get_effective_balance` From a7307b9236b95d607b24cb617d0502555f77ae1e Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 18 Jan 2019 02:10:23 -0800 Subject: [PATCH 24/29] Sign full `Exit` message so that a validator can prevent tampering (#468) --- 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 98df49eb9..002e53f97 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1585,7 +1585,8 @@ For each `exit` in `block.body.exits`: * Let `validator = state.validator_registry[exit.validator_index]`. * Verify that `validator.exit_slot > state.slot + ENTRY_EXIT_DELAY`. * Verify that `state.slot >= exit.slot`. -* Verify that `bls_verify(pubkey=validator.pubkey, message=ZERO_HASH, signature=exit.signature, domain=get_domain(state.fork, exit.slot, DOMAIN_EXIT))`. +* Let `exit_message = hash_tree_root(Exit(slot=exit.slot, validator_index=exit.validator_index, signature=EMPTY_SIGNATURE))`. +* Verify that `bls_verify(pubkey=validator.pubkey, message=exit_message, signature=exit.signature, domain=get_domain(state.fork, exit.slot, DOMAIN_EXIT))`. * Run `initiate_validator_exit(state, exit.validator_index)`. #### Custody From b493f850fce367b7818192caade9a85739ae1558 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 18 Jan 2019 09:40:15 -0600 Subject: [PATCH 25/29] cleanup crosslink committees iters --- specs/core/0_beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 002e53f97..272002d02 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1632,7 +1632,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 `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committee_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committee_at_slot`, compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * Let `shard_block_root` be `state.latest_crosslinks[shard].shard_block_root` * Let `attesting_validator_indices(crosslink_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.shard == shard and a.shard_block_root == shard_block_root]`. @@ -1668,7 +1668,7 @@ Set `state.finalized_slot = state.previous_justified_slot` if any of the followi ### Crosslinks -For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committee_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committee_at_slot`, compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * Set `state.latest_crosslinks[shard] = Crosslink(slot=state.slot, shard_block_root=winning_root(crosslink_committee))` if `3 * total_attesting_balance(crosslink_committee) >= 2 * total_balance(crosslink_committee)`. @@ -1714,7 +1714,7 @@ For each `index` in `previous_epoch_attester_indices`, we determine the proposer #### Crosslinks -For every `i in range(state.slot - 2 * EPOCH_LENGTH, state.slot - EPOCH_LENGTH)`, let `crosslink_committee_at_slot, start_shard = get_crosslink_committees_at_slot(i)`. For every `j in range(len(crosslink_committee_at_slot))`, let `crosslink_committee = crosslink_committee_at_slot[j]`, `shard = (start_shard + j) % SHARD_COUNT`, and compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot - EPOCH_LENGTH)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * If `index in attesting_validators(crosslink_committee)`, `state.validator_balances[index] += base_reward(state, index) * total_attesting_balance(crosslink_committee) // total_balance(crosslink_committee))`. * If `index not in attesting_validators(crosslink_committee)`, `state.validator_balances[index] -= base_reward(state, index)`. From aa29b9a347ff9006a91aef493dd8d9fb135b7823 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 18 Jan 2019 09:55:32 -0600 Subject: [PATCH 26/29] add missing state param to calls to get_crosslink_committees_at_slots --- specs/core/0_beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 272002d02..5640340b6 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1632,7 +1632,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 `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(state, slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * Let `shard_block_root` be `state.latest_crosslinks[shard].shard_block_root` * Let `attesting_validator_indices(crosslink_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.shard == shard and a.shard_block_root == shard_block_root]`. @@ -1668,7 +1668,7 @@ Set `state.finalized_slot = state.previous_justified_slot` if any of the followi ### Crosslinks -For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(state, slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * Set `state.latest_crosslinks[shard] = Crosslink(slot=state.slot, shard_block_root=winning_root(crosslink_committee))` if `3 * total_attesting_balance(crosslink_committee) >= 2 * total_balance(crosslink_committee)`. @@ -1714,7 +1714,7 @@ For each `index` in `previous_epoch_attester_indices`, we determine the proposer #### Crosslinks -For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot - EPOCH_LENGTH)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: +For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot - EPOCH_LENGTH)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(state, slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * If `index in attesting_validators(crosslink_committee)`, `state.validator_balances[index] += base_reward(state, index) * total_attesting_balance(crosslink_committee) // total_balance(crosslink_committee))`. * If `index not in attesting_validators(crosslink_committee)`, `state.validator_balances[index] -= base_reward(state, index)`. From 8d5c75c6fded531f162a0265a40ba079ed36f93e Mon Sep 17 00:00:00 2001 From: Jonny Rhea Date: Fri, 18 Jan 2019 15:39:28 -0600 Subject: [PATCH 27/29] Update bls_signature.md (#473) fq2 param should be a list --- specs/bls_signature.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/bls_signature.md b/specs/bls_signature.md index 8e0b76c6b..9dd5cac8b 100644 --- a/specs/bls_signature.md +++ b/specs/bls_signature.md @@ -119,7 +119,7 @@ In the following `e` is the pairing function and `g` is the G1 generator with th ```python g_x = 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 g_y = 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569 -g = Fq2(g_x, g_y) +g = Fq2([g_x, g_y]) ``` ### `bls_verify` From 89f0543ab9ed5853017bdd0f83288737120223fe Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 18 Jan 2019 17:13:23 -0700 Subject: [PATCH 28/29] add some missing `data` calls --- specs/core/0_beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 5640340b6..9ba2df843 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1615,7 +1615,7 @@ All [validators](#dfn-validator): [Validators](#dfn-Validator) attesting during the previous epoch: * 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_attestations = [a for a in state.latest_attestations if state.slot - 2 * EPOCH_LENGTH <= a.data.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.aggregation_bitfield) for a in previous_epoch_attestations]`. * Validators targeting the previous justified slot: * Let `previous_epoch_justified_attestations = [a for a in current_epoch_attestations + previous_epoch_attestations if a.data.justified_slot == state.previous_justified_slot]`. @@ -1626,7 +1626,7 @@ All [validators](#dfn-validator): * Let `previous_epoch_boundary_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in previous_epoch_boundary_attestations]`. * Let `previous_epoch_boundary_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_boundary_attester_indices])`. * Validators attesting to the expected beacon chain head during the previous epoch: - * Let `previous_epoch_head_attestations = [a for a in previous_epoch_attestations if a.data.beacon_block_root == get_block_root(state, a.slot)]`. + * Let `previous_epoch_head_attestations = [a for a in previous_epoch_attestations if a.data.beacon_block_root == get_block_root(state, a.data.slot)]`. * Let `previous_epoch_head_attester_indices` be the union of the validator index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in previous_epoch_head_attestations]`. * Let `previous_epoch_head_attesting_balance = sum([get_effective_balance(state, i) for i in previous_epoch_head_attester_indices])`. @@ -1635,7 +1635,7 @@ All [validators](#dfn-validator): For every `slot in range(state.slot - 2 * EPOCH_LENGTH, state.slot)`, let `crosslink_committees_at_slot = get_crosslink_committees_at_slot(state, slot)`. For every `(crosslink_committee, shard)` in `crosslink_committees_at_slot`, compute: * Let `shard_block_root` be `state.latest_crosslinks[shard].shard_block_root` -* Let `attesting_validator_indices(crosslink_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.shard == shard and a.shard_block_root == shard_block_root]`. +* Let `attesting_validator_indices(crosslink_committee, shard_block_root)` be the union of the [validator](#dfn-validator) index sets given by `[get_attestation_participants(state, a.data, a.aggregation_bitfield) for a in current_epoch_attestations + previous_epoch_attestations if a.data.shard == shard and a.data.shard_block_root == shard_block_root]`. * Let `winning_root(crosslink_committee)` be equal to the value of `shard_block_root` such that `sum([get_effective_balance(state, i) for i in attesting_validator_indices(crosslink_committee, shard_block_root)])` is maximized (ties broken by favoring lower `shard_block_root` values). * Let `attesting_validators(crosslink_committee)` be equal to `attesting_validator_indices(crosslink_committee, winning_root(crosslink_committee))` for convenience. * Let `total_attesting_balance(crosslink_committee) = sum([get_effective_balance(state, i) for i in attesting_validators(crosslink_committee)])`. From cc18df11851092ed92160e8d010b1d56f6179854 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 18 Jan 2019 18:45:15 -0600 Subject: [PATCH 29/29] remove unused variable def --- specs/core/0_beacon-chain.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 5640340b6..ce8c55ea6 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1363,8 +1363,7 @@ def process_deposit(state: BeaconState, penultimate_custody_reseed_slot=GENESIS_SLOT, ) - # Note: In phase 2 registry indices that has been withdrawn for a long time will be recycled. - index = len(state.validator_registry) + # Note: In phase 2 registry indices that have been withdrawn for a long time will be recycled. state.validator_registry.append(validator) state.validator_balances.append(amount) else: