From 0fd1d384179048cebfd56423dbd47c4d84958407 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 20:58:02 +0200 Subject: [PATCH 1/7] `Misc` function rename --- scripts/build_spec.py | 2 +- specs/core/0_beacon-chain.md | 113 +++++++++--------- specs/core/0_fork-choice.md | 8 +- specs/core/1_custody-game.md | 4 +- specs/core/1_shard-data-chains.md | 11 +- specs/light_client/sync_protocol.md | 4 +- specs/validator/0_beacon-chain-validator.md | 18 +-- test_generators/shuffling/main.py | 2 +- .../eth2spec/test/helpers/attestations.py | 10 +- .../pyspec/eth2spec/test/helpers/block.py | 8 +- .../pyspec/eth2spec/test/helpers/deposits.py | 2 +- ..._process_justification_and_finalization.py | 8 +- .../pyspec/eth2spec/test/test_finality.py | 2 +- 13 files changed, 97 insertions(+), 95 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index fe66a72d5..2a556cb87 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -98,7 +98,7 @@ def apply_constants_preset(preset: Dict[str, Any]) -> None: global_vars[k] = v # Deal with derived constants - global_vars['GENESIS_EPOCH'] = slot_to_epoch(GENESIS_SLOT) + global_vars['GENESIS_EPOCH'] = compute_slot_epoch(GENESIS_SLOT) # Initialize SSZ types again, to account for changed lengths init_SSZ_types() diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 68915177c..75721ec1a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -66,13 +66,13 @@ - [`is_slashable_attestation_data`](#is_slashable_attestation_data) - [`is_valid_merkle_branch`](#is_valid_merkle_branch) - [Misc](#misc) - - [`shuffle_index`](#shuffle_index) + - [`compute_shuffle_index`](#compute_shuffle_index) - [`compute_committee`](#compute_committee) - - [`validate_indexed_attestation`](#validate_indexed_attestation) - - [`slot_to_epoch`](#slot_to_epoch) - - [`epoch_start_slot`](#epoch_start_slot) + - [`compute_slot_epoch`](#compute_slot_epoch) + - [`compute_epoch_start_slot`](#compute_epoch_start_slot) - [`compute_activation_exit_epoch`](#compute_activation_exit_epoch) - - [`bls_domain`](#bls_domain) + - [`compute_bls_domain`](#compute_bls_domain) + - [`validate_indexed_attestation`](#validate_indexed_attestation) - [Beacon state accessors](#beacon-state-accessors) - [`get_current_epoch`](#get_current_epoch) - [`get_previous_epoch`](#get_previous_epoch) @@ -662,10 +662,10 @@ def is_valid_merkle_branch(leaf: Hash, branch: Sequence[Hash], depth: uint64, in ### Misc -#### `shuffle_index` +#### `compute_shuffle_index` ```python -def shuffle_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> ValidatorIndex: +def compute_shuffle_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> ValidatorIndex: """ Return the shuffled validator index corresponding to ``seed`` (and ``index_count``). """ @@ -698,7 +698,47 @@ def compute_committee(indices: Sequence[ValidatorIndex], """ start = (len(indices) * index) // count end = (len(indices) * (index + 1)) // count - return [indices[shuffle_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)] + return [indices[compute_shuffle_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)] +``` + +#### `compute_slot_epoch` + +```python +def compute_slot_epoch(slot: Slot) -> Epoch: + """ + Return the epoch number of ``slot``. + """ + return Epoch(slot // SLOTS_PER_EPOCH) +``` + +#### `compute_epoch_start_slot` + +```python +def compute_epoch_start_slot(epoch: Epoch) -> Slot: + """ + Return the start slot of ``epoch``. + """ + return Slot(epoch * SLOTS_PER_EPOCH) +``` + +#### `compute_activation_exit_epoch` + +```python +def compute_activation_exit_epoch(epoch: Epoch) -> Epoch: + """ + Return the epoch during which validator activations and exits initiated in ``epoch`` take effect. + """ + return Epoch(epoch + 1 + ACTIVATION_EXIT_DELAY) +``` + +#### `compute_bls_domain` + +```python +def compute_bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: + """ + Return the BLS domain for the ``domain_type`` and ``fork_version``. + """ + return bytes_to_int(int_to_bytes(domain_type, length=4) + fork_version) ``` #### `validate_indexed_attestation` @@ -734,46 +774,6 @@ def validate_indexed_attestation(state: BeaconState, indexed_attestation: Indexe ) ``` -#### `slot_to_epoch` - -```python -def slot_to_epoch(slot: Slot) -> Epoch: - """ - Return the epoch number of ``slot``. - """ - return Epoch(slot // SLOTS_PER_EPOCH) -``` - -#### `epoch_start_slot` - -```python -def epoch_start_slot(epoch: Epoch) -> Slot: - """ - Return the start slot of ``epoch``. - """ - return Slot(epoch * SLOTS_PER_EPOCH) -``` - -#### `compute_activation_exit_epoch` - -```python -def compute_activation_exit_epoch(epoch: Epoch) -> Epoch: - """ - Return the epoch during which validator activations and exits initiated in ``epoch`` take effect. - """ - return Epoch(epoch + 1 + ACTIVATION_EXIT_DELAY) -``` - -#### `bls_domain` - -```python -def bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: - """ - Return the BLS domain for the ``domain_type`` and ``fork_version``. - """ - return bytes_to_int(int_to_bytes(domain_type, length=4) + fork_version) -``` - ### Beacon state accessors #### `get_current_epoch` @@ -783,7 +783,7 @@ def get_current_epoch(state: BeaconState) -> Epoch: """ Return the current epoch. """ - return slot_to_epoch(state.slot) + return compute_slot_epoch(state.slot) ``` #### `get_previous_epoch` @@ -804,7 +804,7 @@ def get_block_root(state: BeaconState, epoch: Epoch) -> Hash: """ Return the block root at the start of a recent ``epoch``. """ - return get_block_root_at_slot(state, epoch_start_slot(epoch)) + return get_block_root_at_slot(state, compute_epoch_start_slot(epoch)) ``` #### `get_block_root_at_slot` @@ -950,7 +950,7 @@ def get_attestation_data_slot(state: BeaconState, data: AttestationData) -> Slot """ committee_count = get_committee_count(state, data.target.epoch) offset = (data.crosslink.shard + SHARD_COUNT - get_start_shard(state, data.target.epoch)) % SHARD_COUNT - return Slot(epoch_start_slot(data.target.epoch) + offset // (committee_count // SLOTS_PER_EPOCH)) + return Slot(compute_epoch_start_slot(data.target.epoch) + offset // (committee_count // SLOTS_PER_EPOCH)) ``` #### `get_compact_committees_root` @@ -1003,7 +1003,7 @@ def get_domain(state: BeaconState, domain_type: uint64, message_epoch: Epoch=Non """ epoch = get_current_epoch(state) if message_epoch is None else message_epoch fork_version = state.fork.previous_version if epoch < state.fork.epoch else state.fork.current_version - return bls_domain(domain_type, fork_version) + return compute_bls_domain(domain_type, fork_version) ``` #### `get_indexed_attestation` @@ -1585,14 +1585,14 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: def process_proposer_slashing(state: BeaconState, proposer_slashing: ProposerSlashing) -> None: proposer = state.validators[proposer_slashing.proposer_index] # Verify that the epoch is the same - assert slot_to_epoch(proposer_slashing.header_1.slot) == slot_to_epoch(proposer_slashing.header_2.slot) + assert compute_slot_epoch(proposer_slashing.header_1.slot) == compute_slot_epoch(proposer_slashing.header_2.slot) # But the headers are different assert proposer_slashing.header_1 != proposer_slashing.header_2 # Check proposer is slashable assert is_slashable_validator(proposer, get_current_epoch(state)) # Signatures are valid for header in (proposer_slashing.header_1, proposer_slashing.header_2): - domain = get_domain(state, DOMAIN_BEACON_PROPOSER, slot_to_epoch(header.slot)) + domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_slot_epoch(header.slot)) assert bls_verify(proposer.pubkey, signing_root(header), header.signature, domain) slash_validator(state, proposer_slashing.proposer_index) @@ -1677,8 +1677,9 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: if pubkey not in validator_pubkeys: # Verify the deposit signature (proof of possession) for new validators. # Note: The deposit contract does not check signatures. - # Note: Deposits are valid across forks, hence the deposit domain is retrieved directly from `bls_domain` - if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, bls_domain(DOMAIN_DEPOSIT)): + # Note: Deposits are valid across forks. thus the deposit domain is retrieved directly from `compute_bls_domain` + if not bls_verify(pubkey, signing_root(deposit.data), + deposit.data.signature, compute_bls_domain(DOMAIN_DEPOSIT)): return # Add validator and balance entries diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index a45d79fbe..a386e162d 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -124,7 +124,7 @@ def get_latest_attesting_balance(store: Store, root: Hash) -> Gwei: def get_head(store: Store) -> Hash: # Execute the LMD-GHOST fork choice head = store.justified_checkpoint.root - justified_slot = epoch_start_slot(store.justified_checkpoint.epoch) + justified_slot = compute_epoch_start_slot(store.justified_checkpoint.epoch) while True: children = [ root for root in store.blocks.keys() @@ -162,7 +162,7 @@ def on_block(store: Store, block: BeaconBlock) -> None: store.finalized_checkpoint.root ) # Check that block is later than the finalized epoch slot - assert block.slot > epoch_start_slot(store.finalized_checkpoint.epoch) + assert block.slot > compute_epoch_start_slot(store.finalized_checkpoint.epoch) # Check the block is valid and compute the post-state state = state_transition(pre_state, block) # Add new state for this block to the store @@ -190,11 +190,11 @@ def on_attestation(store: Store, attestation: Attestation) -> None: # Attestations cannot be from future epochs. If they are, delay consideration until the epoch arrivesr base_state = store.block_states[target.root].copy() - assert store.time >= base_state.genesis_time + epoch_start_slot(target.epoch) * SECONDS_PER_SLOT + assert store.time >= base_state.genesis_time + compute_epoch_start_slot(target.epoch) * SECONDS_PER_SLOT # Store target checkpoint state if not yet seen if target not in store.checkpoint_states: - process_slots(base_state, epoch_start_slot(target.epoch)) + process_slots(base_state, compute_epoch_start_slot(target.epoch)) store.checkpoint_states[target] = base_state target_state = store.checkpoint_states[target] diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index 54a1ca34b..149386519 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -475,7 +475,7 @@ def process_chunk_challenge(state: BeaconState, challenge: CustodyChunkChallenge # Verify the attestation validate_indexed_attestation(state, get_indexed_attestation(state, challenge.attestation)) # Verify it is not too late to challenge - assert slot_to_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY + assert compute_slot_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY responder = state.validators[challenge.responder_index] assert responder.exit_epoch >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY # Verify the responder participated in the attestation @@ -516,7 +516,7 @@ For each `challenge` in `block.body.custody_bit_challenges`, run the following f ```python def process_bit_challenge(state: BeaconState, challenge: CustodyBitChallenge) -> None: attestation = challenge.attestation - epoch = slot_to_epoch(attestation.data.slot) + epoch = compute_slot_epoch(attestation.data.slot) shard = attestation.data.crosslink.shard # Verify challenge signature diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index fd0e41b4f..5dc6e698f 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -163,7 +163,7 @@ def get_persistent_committee(state: BeaconState, """ Return the persistent committee for the given ``shard`` at the given ``slot``. """ - epoch = slot_to_epoch(slot) + epoch = compute_slot_epoch(slot) earlier_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2) later_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD) @@ -240,7 +240,7 @@ def verify_shard_attestation_signature(state: BeaconState, pubkey=bls_aggregate_pubkeys(pubkeys), message_hash=data.shard_block_root, signature=attestation.aggregate_signature, - domain=get_domain(state, DOMAIN_SHARD_ATTESTER, slot_to_epoch(data.slot)) + domain=get_domain(state, DOMAIN_SHARD_ATTESTER, compute_slot_epoch(data.slot)) ) ``` @@ -339,7 +339,7 @@ def is_valid_shard_block(beacon_blocks: Sequence[BeaconBlock], pubkey=beacon_state.validators[proposer_index].pubkey, message_hash=signing_root(candidate), signature=candidate.signature, - domain=get_domain(beacon_state, DOMAIN_SHARD_PROPOSER, slot_to_epoch(candidate.slot)), + domain=get_domain(beacon_state, DOMAIN_SHARD_PROPOSER, compute_slot_epoch(candidate.slot)), ) return True @@ -403,11 +403,12 @@ def is_valid_beacon_attestation(shard: Shard, None, ) assert previous_attestation is not None - assert candidate.data.previous_attestation.epoch < slot_to_epoch(candidate.data.slot) + assert candidate.data.previous_attestation.epoch < compute_slot_epoch(candidate.data.slot) # Check crosslink data root start_epoch = beacon_state.crosslinks[shard].epoch - end_epoch = min(slot_to_epoch(candidate.data.slot) - CROSSLINK_LOOKBACK, start_epoch + MAX_EPOCHS_PER_CROSSLINK) + end_epoch = min(compute_slot_epoch(candidate.data.slot) - CROSSLINK_LOOKBACK, + start_epoch + MAX_EPOCHS_PER_CROSSLINK) blocks = [] for slot in range(start_epoch * SLOTS_PER_EPOCH, end_epoch * SLOTS_PER_EPOCH): blocks.append(shard_blocks[slot]) diff --git a/specs/light_client/sync_protocol.md b/specs/light_client/sync_protocol.md index 2b1703f21..f9e347d80 100644 --- a/specs/light_client/sync_protocol.md +++ b/specs/light_client/sync_protocol.md @@ -124,7 +124,7 @@ def compute_committee(header: BeaconBlockHeader, maximal_later_committee = validator_memory.later_period_data.committee earlier_start_epoch = get_earlier_start_epoch(header.slot) later_start_epoch = get_later_start_epoch(header.slot) - epoch = slot_to_epoch(header.slot) + epoch = compute_slot_epoch(header.slot) committee_count = max( earlier_validator_count // (SHARD_COUNT * TARGET_COMMITTEE_SIZE), @@ -192,7 +192,7 @@ def verify_block_validity_proof(proof: BlockValidityProof, validator_memory: Val pubkey=group_public_key, message_hash=hash_tree_root(shard_parent_block), signature=proof.shard_aggregate_signature, - domain=get_domain(state, slot_to_epoch(shard_block.slot), DOMAIN_SHARD_ATTESTER), + domain=get_domain(state, compute_slot_epoch(shard_block.slot), DOMAIN_SHARD_ATTESTER), ) ``` diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 0b6857a72..d9906827d 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -98,7 +98,7 @@ To submit a deposit: * Pack the validator's [initialization parameters](#initialization) into `deposit_data`, a [`DepositData`](../core/0_beacon-chain.md#depositdata) SSZ object. * Let `amount` be the amount in Gwei to be deposited by the validator where `MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE`. * Set `deposit_data.amount = amount`. -* Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=bls_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `bls_domain` will default to zeroes there). +* Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=compute_bls_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `compute_bls_domain` will default to zeroes there). * Send a transaction on the Ethereum 1.0 chain to `DEPOSIT_CONTRACT_ADDRESS` executing `def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])` along with a deposit of `amount` Gwei. *Note*: Deposits made for the same `pubkey` are treated as for the same validator. A singular `Validator` will be added to `state.validators` with each additional deposit amount added to the validator's balance. A validator can only be activated when total deposits for the validator pubkey meet or exceed `MAX_EFFECTIVE_BALANCE`. @@ -146,7 +146,7 @@ def get_committee_assignment( assert epoch <= next_epoch committees_per_slot = get_committee_count(state, epoch) // SLOTS_PER_EPOCH - start_slot = epoch_start_slot(epoch) + start_slot = compute_epoch_start_slot(epoch) for slot in range(start_slot, start_slot + SLOTS_PER_EPOCH): offset = committees_per_slot * (slot % SLOTS_PER_EPOCH) slot_start_shard = (get_start_shard(state, epoch) + offset) % SHARD_COUNT @@ -210,10 +210,10 @@ Set `block.randao_reveal = epoch_signature` where `epoch_signature` is defined a ```python epoch_signature = bls_sign( privkey=validator.privkey, # privkey stored locally, not in state - message_hash=hash_tree_root(slot_to_epoch(block.slot)), + message_hash=hash_tree_root(compute_slot_epoch(block.slot)), domain=get_domain( fork=fork, # `fork` is the fork object at the slot `block.slot` - epoch=slot_to_epoch(block.slot), + epoch=compute_slot_epoch(block.slot), domain_type=DOMAIN_RANDAO, ) ) @@ -252,7 +252,7 @@ block_signature = bls_sign( message_hash=signing_root(block), domain=get_domain( fork=fork, # `fork` is the fork object at the slot `block.slot` - epoch=slot_to_epoch(block.slot), + epoch=compute_slot_epoch(block.slot), domain_type=DOMAIN_BEACON_BLOCK, ) ) @@ -307,7 +307,7 @@ Set `attestation_data.beacon_block_root = signing_root(head_block)`. * Set `attestation_data.target_root = epoch_boundary_block_root` where `epoch_boundary_block_root` is the root of block at the most recent epoch boundary. *Note*: `epoch_boundary_block_root` can be looked up in the state using: -* Let `start_slot = epoch_start_slot(get_current_epoch(head_state))`. +* Let `start_slot = compute_epoch_start_slot(get_current_epoch(head_state))`. * Let `epoch_boundary_block_root = signing_root(head_block) if start_slot == head_state.slot else get_block_root(state, start_slot)`. ##### Crosslink vote @@ -357,7 +357,7 @@ signed_attestation_data = bls_sign( message_hash=attestation_message, domain=get_domain( fork=fork, # `fork` is the fork object at the slot, `attestation_data.slot` - epoch=slot_to_epoch(attestation_data.slot), + epoch=compute_slot_epoch(attestation_data.slot), domain_type=DOMAIN_ATTESTATION, ) ) @@ -376,7 +376,7 @@ To avoid "proposer slashings", a validator must not sign two conflicting [`Beaco *In Phase 0, as long as the validator does not sign two different beacon blocks for the same epoch, the validator is safe against proposer slashings.* Specifically, when signing a `BeaconBlock`, a validator should perform the following steps in the following order: -1. Save a record to hard disk that a beacon block has been signed for the `epoch=slot_to_epoch(block.slot)`. +1. Save a record to hard disk that a beacon block has been signed for the `epoch=compute_slot_epoch(block.slot)`. 2. Generate and broadcast the block. If the software crashes at some point within this routine, then when the validator comes back online, the hard disk has the record of the *potentially* signed/broadcast block and can effectively avoid slashing. @@ -386,7 +386,7 @@ If the software crashes at some point within this routine, then when the validat To avoid "attester slashings", a validator must not sign two conflicting [`AttestationData`](../core/0_beacon-chain.md#attestationdata) objects, i.e. two attestations that satisfy [`is_slashable_attestation_data`](../core/0_beacon-chain.md#is_slashable_attestation_data). Specifically, when signing an `Attestation`, a validator should perform the following steps in the following order: -1. Save a record to hard disk that an attestation has been signed for source (i.e. `attestation_data.source_epoch`) and target (i.e. `slot_to_epoch(attestation_data.slot)`). +1. Save a record to hard disk that an attestation has been signed for source (i.e. `attestation_data.source_epoch`) and target (i.e. `compute_slot_epoch(attestation_data.slot)`). 2. Generate and broadcast attestation. If the software crashes at some point within this routine, then when the validator comes back online, the hard disk has the record of the *potentially* signed/broadcast attestation and can effectively avoid slashing. diff --git a/test_generators/shuffling/main.py b/test_generators/shuffling/main.py index e40dda520..bc7907242 100644 --- a/test_generators/shuffling/main.py +++ b/test_generators/shuffling/main.py @@ -10,7 +10,7 @@ from preset_loader import loader def shuffling_case(seed, count): yield 'seed', '0x' + seed.hex() yield 'count', count - yield 'shuffled', [spec.shuffle_index(i, count, seed) for i in range(count)] + yield 'shuffled', [spec.compute_shuffle_index(i, count, seed) for i in range(count)] @to_tuple diff --git a/test_libs/pyspec/eth2spec/test/helpers/attestations.py b/test_libs/pyspec/eth2spec/test/helpers/attestations.py index 92c4b843d..ba2bd3ca0 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/attestations.py +++ b/test_libs/pyspec/eth2spec/test/helpers/attestations.py @@ -15,7 +15,7 @@ def build_attestation_data(spec, state, slot, shard): else: block_root = spec.get_block_root_at_slot(state, slot) - current_epoch_start_slot = spec.epoch_start_slot(spec.get_current_epoch(state)) + current_epoch_start_slot = spec.compute_epoch_start_slot(spec.get_current_epoch(state)) if slot < current_epoch_start_slot: epoch_boundary_root = spec.get_block_root(state, spec.get_previous_epoch(state)) elif slot == current_epoch_start_slot: @@ -30,7 +30,7 @@ def build_attestation_data(spec, state, slot, shard): source_epoch = state.current_justified_checkpoint.epoch source_root = state.current_justified_checkpoint.root - if spec.slot_to_epoch(slot) == spec.get_current_epoch(state): + if spec.compute_slot_epoch(slot) == spec.get_current_epoch(state): parent_crosslink = state.current_crosslinks[shard] else: parent_crosslink = state.previous_crosslinks[shard] @@ -38,11 +38,11 @@ def build_attestation_data(spec, state, slot, shard): return spec.AttestationData( beacon_block_root=block_root, source=spec.Checkpoint(epoch=source_epoch, root=source_root), - target=spec.Checkpoint(epoch=spec.slot_to_epoch(slot), root=epoch_boundary_root), + target=spec.Checkpoint(epoch=spec.compute_slot_epoch(slot), root=epoch_boundary_root), crosslink=spec.Crosslink( shard=shard, start_epoch=parent_crosslink.end_epoch, - end_epoch=min(spec.slot_to_epoch(slot), parent_crosslink.end_epoch + spec.MAX_EPOCHS_PER_CROSSLINK), + end_epoch=min(spec.compute_slot_epoch(slot), parent_crosslink.end_epoch + spec.MAX_EPOCHS_PER_CROSSLINK), data_root=spec.Hash(), parent_root=hash_tree_root(parent_crosslink), ), @@ -53,7 +53,7 @@ def get_valid_attestation(spec, state, slot=None, signed=False): if slot is None: slot = state.slot - epoch = spec.slot_to_epoch(slot) + epoch = spec.compute_slot_epoch(slot) epoch_start_shard = spec.get_start_shard(state, epoch) committees_per_slot = spec.get_committee_count(state, epoch) // spec.SLOTS_PER_EPOCH shard = (epoch_start_shard + committees_per_slot * (slot % spec.SLOTS_PER_EPOCH)) % spec.SHARD_COUNT diff --git a/test_libs/pyspec/eth2spec/test/helpers/block.py b/test_libs/pyspec/eth2spec/test/helpers/block.py index fdbc5ef55..830a1e9ec 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/block.py +++ b/test_libs/pyspec/eth2spec/test/helpers/block.py @@ -14,7 +14,7 @@ def sign_block(spec, state, block, proposer_index=None): if block.slot == state.slot: proposer_index = spec.get_beacon_proposer_index(state) else: - if spec.slot_to_epoch(state.slot) + 1 > spec.slot_to_epoch(block.slot): + if spec.compute_slot_epoch(state.slot) + 1 > spec.compute_slot_epoch(block.slot): print("warning: block slot far away, and no proposer index manually given." " Signing block is slow due to transition for proposer index calculation.") # use stub state to get proposer index of future slot @@ -26,10 +26,10 @@ def sign_block(spec, state, block, proposer_index=None): block.body.randao_reveal = bls_sign( privkey=privkey, - message_hash=hash_tree_root(spec.slot_to_epoch(block.slot)), + message_hash=hash_tree_root(spec.compute_slot_epoch(block.slot)), domain=spec.get_domain( state, - message_epoch=spec.slot_to_epoch(block.slot), + message_epoch=spec.compute_slot_epoch(block.slot), domain_type=spec.DOMAIN_RANDAO, ) ) @@ -39,7 +39,7 @@ def sign_block(spec, state, block, proposer_index=None): domain=spec.get_domain( state, spec.DOMAIN_BEACON_PROPOSER, - spec.slot_to_epoch(block.slot))) + spec.compute_slot_epoch(block.slot))) def apply_empty_block(spec, state): diff --git a/test_libs/pyspec/eth2spec/test/helpers/deposits.py b/test_libs/pyspec/eth2spec/test/helpers/deposits.py index 4f099be9d..276fa617b 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/deposits.py +++ b/test_libs/pyspec/eth2spec/test/helpers/deposits.py @@ -19,7 +19,7 @@ def build_deposit_data(spec, pubkey, privkey, amount, withdrawal_credentials, st def sign_deposit_data(spec, deposit_data, privkey, state=None): if state is None: # Genesis - domain = spec.bls_domain(spec.DOMAIN_DEPOSIT) + domain = spec.compute_bls_domain(spec.DOMAIN_DEPOSIT) else: domain = spec.get_domain( state, diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py index f59da1fc5..b7a34b5ee 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py @@ -9,7 +9,7 @@ def run_process_just_and_fin(spec, state): def get_shards_for_slot(spec, state, slot): - epoch = spec.slot_to_epoch(slot) + epoch = spec.compute_slot_epoch(slot) epoch_start_shard = spec.get_start_shard(state, epoch) committees_per_slot = spec.get_committee_count(state, epoch) // spec.SLOTS_PER_EPOCH shard = (epoch_start_shard + committees_per_slot * (slot % spec.SLOTS_PER_EPOCH)) % spec.SHARD_COUNT @@ -33,7 +33,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support total_balance = spec.get_total_active_balance(state) remaining_balance = total_balance * 2 // 3 - start_slot = spec.epoch_start_slot(epoch) + start_slot = spec.compute_epoch_start_slot(epoch) for slot in range(start_slot, start_slot + spec.SLOTS_PER_EPOCH): for shard in get_shards_for_slot(spec, state, slot): # Check if we already have had sufficient balance. (and undone if we don't want it). @@ -41,7 +41,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support if remaining_balance < 0: return - committee = spec.get_crosslink_committee(state, spec.slot_to_epoch(slot), shard) + committee = spec.get_crosslink_committee(state, spec.compute_slot_epoch(slot), shard) # Create a bitfield filled with the given count per attestation, # exactly on the right-most part of the committee field. @@ -80,7 +80,7 @@ def get_checkpoints(spec, epoch): def put_checkpoints_in_block_roots(spec, state, checkpoints): for c in checkpoints: - state.block_roots[spec.epoch_start_slot(c.epoch) % spec.SLOTS_PER_HISTORICAL_ROOT] = c.root + state.block_roots[spec.compute_epoch_start_slot(c.epoch) % spec.SLOTS_PER_HISTORICAL_ROOT] = c.root def finalize_on_234(spec, state, epoch, sufficient_support): diff --git a/test_libs/pyspec/eth2spec/test/test_finality.py b/test_libs/pyspec/eth2spec/test/test_finality.py index 5ff0ed1ef..cdeee2351 100644 --- a/test_libs/pyspec/eth2spec/test/test_finality.py +++ b/test_libs/pyspec/eth2spec/test/test_finality.py @@ -43,7 +43,7 @@ def next_epoch_with_attestations(spec, block = build_empty_block_for_next_slot(spec, post_state) if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY: slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1 - if slot_to_attest >= spec.epoch_start_slot(spec.get_current_epoch(post_state)): + if slot_to_attest >= spec.compute_epoch_start_slot(spec.get_current_epoch(post_state)): cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest) block.body.attestations.append(cur_attestation) From c2a4838f5af373bf00edf8c3ed4cf56877632e8d Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 21:49:29 +0200 Subject: [PATCH 2/7] Implments suggestions from review --- specs/core/0_beacon-chain.md | 14 +++++++------- test_generators/shuffling/main.py | 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 75721ec1a..4554c3195 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -66,7 +66,7 @@ - [`is_slashable_attestation_data`](#is_slashable_attestation_data) - [`is_valid_merkle_branch`](#is_valid_merkle_branch) - [Misc](#misc) - - [`compute_shuffle_index`](#compute_shuffle_index) + - [`compute_shuffled_index`](#compute_shuffled_index) - [`compute_committee`](#compute_committee) - [`compute_slot_epoch`](#compute_slot_epoch) - [`compute_epoch_start_slot`](#compute_epoch_start_slot) @@ -662,10 +662,10 @@ def is_valid_merkle_branch(leaf: Hash, branch: Sequence[Hash], depth: uint64, in ### Misc -#### `compute_shuffle_index` +#### `compute_shuffled_index` ```python -def compute_shuffle_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> ValidatorIndex: +def compute_shuffled_index(index: ValidatorIndex, index_count: uint64, seed: Hash) -> ValidatorIndex: """ Return the shuffled validator index corresponding to ``seed`` (and ``index_count``). """ @@ -698,7 +698,7 @@ def compute_committee(indices: Sequence[ValidatorIndex], """ start = (len(indices) * index) // count end = (len(indices) * (index + 1)) // count - return [indices[compute_shuffle_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)] + return [indices[compute_shuffled_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)] ``` #### `compute_slot_epoch` @@ -1677,9 +1677,9 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: if pubkey not in validator_pubkeys: # Verify the deposit signature (proof of possession) for new validators. # Note: The deposit contract does not check signatures. - # Note: Deposits are valid across forks. thus the deposit domain is retrieved directly from `compute_bls_domain` - if not bls_verify(pubkey, signing_root(deposit.data), - deposit.data.signature, compute_bls_domain(DOMAIN_DEPOSIT)): + # Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_bls_domain` + domain = compute_bls_domain(DOMAIN_DEPOSIT) + if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, domain): return # Add validator and balance entries diff --git a/test_generators/shuffling/main.py b/test_generators/shuffling/main.py index bc7907242..8e6125e6f 100644 --- a/test_generators/shuffling/main.py +++ b/test_generators/shuffling/main.py @@ -10,7 +10,7 @@ from preset_loader import loader def shuffling_case(seed, count): yield 'seed', '0x' + seed.hex() yield 'count', count - yield 'shuffled', [spec.compute_shuffle_index(i, count, seed) for i in range(count)] + yield 'shuffled', [spec.compute_shuffled_index(i, count, seed) for i in range(count)] @to_tuple From 918192cdaba57868593b88c08d1f0b7ae9fe8307 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 23:35:07 +0200 Subject: [PATCH 3/7] `compute_slot_epoch`->`compute_epoch_of_slot` --- scripts/build_spec.py | 2 +- specs/core/0_beacon-chain.md | 23 ++++++++++--------- specs/core/0_fork-choice.md | 8 +++---- specs/core/1_custody-game.md | 5 ++-- specs/core/1_shard-data-chains.md | 10 ++++---- specs/light_client/sync_protocol.md | 4 ++-- specs/validator/0_beacon-chain-validator.md | 16 ++++++------- .../eth2spec/test/helpers/attestations.py | 10 ++++---- .../pyspec/eth2spec/test/helpers/block.py | 8 +++---- ..._process_justification_and_finalization.py | 8 +++---- .../pyspec/eth2spec/test/test_finality.py | 2 +- 11 files changed, 49 insertions(+), 47 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index c9b421409..43d8b5149 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -97,7 +97,7 @@ def apply_constants_preset(preset: Dict[str, Any]) -> None: global_vars[k] = v # Deal with derived constants - global_vars['GENESIS_EPOCH'] = compute_slot_epoch(GENESIS_SLOT) + global_vars['GENESIS_EPOCH'] = compute_epoch_of_slot(GENESIS_SLOT) # Initialize SSZ types again, to account for changed lengths init_SSZ_types() diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 600a246b4..bdbd96f85 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -68,8 +68,8 @@ - [Misc](#misc) - [`compute_shuffled_index`](#compute_shuffled_index) - [`compute_committee`](#compute_committee) - - [`compute_slot_epoch`](#compute_slot_epoch) - - [`compute_epoch_start_slot`](#compute_epoch_start_slot) + - [`compute_epoch_of_slot`](#compute_epoch_of_slot) + - [`compute_start_slot_of_epoch`](#compute_start_slot_of_epoch) - [`compute_activation_exit_epoch`](#compute_activation_exit_epoch) - [`compute_bls_domain`](#compute_bls_domain) - [`validate_indexed_attestation`](#validate_indexed_attestation) @@ -701,20 +701,20 @@ def compute_committee(indices: Sequence[ValidatorIndex], return [indices[compute_shuffled_index(ValidatorIndex(i), len(indices), seed)] for i in range(start, end)] ``` -#### `compute_slot_epoch` +#### `compute_epoch_of_slot` ```python -def compute_slot_epoch(slot: Slot) -> Epoch: +def compute_epoch_of_slot(slot: Slot) -> Epoch: """ Return the epoch number of ``slot``. """ return Epoch(slot // SLOTS_PER_EPOCH) ``` -#### `compute_epoch_start_slot` +#### `compute_start_slot_of_epoch` ```python -def compute_epoch_start_slot(epoch: Epoch) -> Slot: +def compute_start_slot_of_epoch(epoch: Epoch) -> Slot: """ Return the start slot of ``epoch``. """ @@ -783,7 +783,7 @@ def get_current_epoch(state: BeaconState) -> Epoch: """ Return the current epoch. """ - return compute_slot_epoch(state.slot) + return compute_epoch_of_slot(state.slot) ``` #### `get_previous_epoch` @@ -804,7 +804,7 @@ def get_block_root(state: BeaconState, epoch: Epoch) -> Hash: """ Return the block root at the start of a recent ``epoch``. """ - return get_block_root_at_slot(state, compute_epoch_start_slot(epoch)) + return get_block_root_at_slot(state, compute_start_slot_of_epoch(epoch)) ``` #### `get_block_root_at_slot` @@ -950,7 +950,7 @@ def get_attestation_data_slot(state: BeaconState, data: AttestationData) -> Slot """ committee_count = get_committee_count(state, data.target.epoch) offset = (data.crosslink.shard + SHARD_COUNT - get_start_shard(state, data.target.epoch)) % SHARD_COUNT - return Slot(compute_epoch_start_slot(data.target.epoch) + offset // (committee_count // SLOTS_PER_EPOCH)) + return Slot(compute_start_slot_of_epoch(data.target.epoch) + offset // (committee_count // SLOTS_PER_EPOCH)) ``` #### `get_compact_committees_root` @@ -1585,14 +1585,15 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: def process_proposer_slashing(state: BeaconState, proposer_slashing: ProposerSlashing) -> None: proposer = state.validators[proposer_slashing.proposer_index] # Verify that the epoch is the same - assert compute_slot_epoch(proposer_slashing.header_1.slot) == compute_slot_epoch(proposer_slashing.header_2.slot) + assert (compute_epoch_of_slot(proposer_slashing.header_1.slot) + == compute_epoch_of_slot(proposer_slashing.header_2.slot)) # But the headers are different assert proposer_slashing.header_1 != proposer_slashing.header_2 # Check proposer is slashable assert is_slashable_validator(proposer, get_current_epoch(state)) # Signatures are valid for header in (proposer_slashing.header_1, proposer_slashing.header_2): - domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_slot_epoch(header.slot)) + domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_of_slot(header.slot)) assert bls_verify(proposer.pubkey, signing_root(header), header.signature, domain) slash_validator(state, proposer_slashing.proposer_index) diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 28ff93e1c..ef0761940 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -124,7 +124,7 @@ def get_latest_attesting_balance(store: Store, root: Hash) -> Gwei: def get_head(store: Store) -> Hash: # Execute the LMD-GHOST fork choice head = store.justified_checkpoint.root - justified_slot = compute_epoch_start_slot(store.justified_checkpoint.epoch) + justified_slot = compute_start_slot_of_epoch(store.justified_checkpoint.epoch) while True: children = [ root for root in store.blocks.keys() @@ -162,7 +162,7 @@ def on_block(store: Store, block: BeaconBlock) -> None: store.finalized_checkpoint.root ) # Check that block is later than the finalized epoch slot - assert block.slot > compute_epoch_start_slot(store.finalized_checkpoint.epoch) + assert block.slot > compute_start_slot_of_epoch(store.finalized_checkpoint.epoch) # Check the block is valid and compute the post-state state = state_transition(pre_state, block) # Add new state for this block to the store @@ -190,11 +190,11 @@ def on_attestation(store: Store, attestation: Attestation) -> None: # Attestations cannot be from future epochs. If they are, delay consideration until the epoch arrives base_state = store.block_states[target.root].copy() - assert store.time >= base_state.genesis_time + compute_epoch_start_slot(target.epoch) * SECONDS_PER_SLOT + assert store.time >= base_state.genesis_time + compute_start_slot_of_epoch(target.epoch) * SECONDS_PER_SLOT # Store target checkpoint state if not yet seen if target not in store.checkpoint_states: - process_slots(base_state, compute_epoch_start_slot(target.epoch)) + process_slots(base_state, compute_start_slot_of_epoch(target.epoch)) store.checkpoint_states[target] = base_state target_state = store.checkpoint_states[target] diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index b79a203f8..69931af04 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -474,7 +474,8 @@ def process_chunk_challenge(state: BeaconState, challenge: CustodyChunkChallenge # Verify the attestation validate_indexed_attestation(state, get_indexed_attestation(state, challenge.attestation)) # Verify it is not too late to challenge - assert compute_slot_epoch(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY + assert (compute_epoch_of_slot(challenge.attestation.data.slot) + >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY) responder = state.validators[challenge.responder_index] assert responder.exit_epoch >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY # Verify the responder participated in the attestation @@ -515,7 +516,7 @@ For each `challenge` in `block.body.custody_bit_challenges`, run the following f ```python def process_bit_challenge(state: BeaconState, challenge: CustodyBitChallenge) -> None: attestation = challenge.attestation - epoch = compute_slot_epoch(attestation.data.slot) + epoch = compute_epoch_of_slot(attestation.data.slot) shard = attestation.data.crosslink.shard # Verify challenge signature diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index e0f3648be..1358a860f 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -163,7 +163,7 @@ def get_persistent_committee(state: BeaconState, """ Return the persistent committee for the given ``shard`` at the given ``slot``. """ - epoch = compute_slot_epoch(slot) + epoch = compute_epoch_of_slot(slot) earlier_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD * 2) later_start_epoch = Epoch(epoch - (epoch % PERSISTENT_COMMITTEE_PERIOD) - PERSISTENT_COMMITTEE_PERIOD) @@ -240,7 +240,7 @@ def verify_shard_attestation_signature(state: BeaconState, pubkey=bls_aggregate_pubkeys(pubkeys), message_hash=data.shard_block_root, signature=attestation.aggregate_signature, - domain=get_domain(state, DOMAIN_SHARD_ATTESTER, compute_slot_epoch(data.slot)) + domain=get_domain(state, DOMAIN_SHARD_ATTESTER, compute_epoch_of_slot(data.slot)) ) ``` @@ -339,7 +339,7 @@ def is_valid_shard_block(beacon_blocks: Sequence[BeaconBlock], pubkey=beacon_state.validators[proposer_index].pubkey, message_hash=signing_root(candidate), signature=candidate.signature, - domain=get_domain(beacon_state, DOMAIN_SHARD_PROPOSER, compute_slot_epoch(candidate.slot)), + domain=get_domain(beacon_state, DOMAIN_SHARD_PROPOSER, compute_epoch_of_slot(candidate.slot)), ) return True @@ -403,11 +403,11 @@ def is_valid_beacon_attestation(shard: Shard, None, ) assert previous_attestation is not None - assert candidate.data.previous_attestation.epoch < compute_slot_epoch(candidate.data.slot) + assert candidate.data.previous_attestation.epoch < compute_epoch_of_slot(candidate.data.slot) # Check crosslink data root start_epoch = beacon_state.crosslinks[shard].epoch - end_epoch = min(compute_slot_epoch(candidate.data.slot) - CROSSLINK_LOOKBACK, + end_epoch = min(compute_epoch_of_slot(candidate.data.slot) - CROSSLINK_LOOKBACK, start_epoch + MAX_EPOCHS_PER_CROSSLINK) blocks = [] for slot in range(start_epoch * SLOTS_PER_EPOCH, end_epoch * SLOTS_PER_EPOCH): diff --git a/specs/light_client/sync_protocol.md b/specs/light_client/sync_protocol.md index f9e347d80..41cd9dcb6 100644 --- a/specs/light_client/sync_protocol.md +++ b/specs/light_client/sync_protocol.md @@ -124,7 +124,7 @@ def compute_committee(header: BeaconBlockHeader, maximal_later_committee = validator_memory.later_period_data.committee earlier_start_epoch = get_earlier_start_epoch(header.slot) later_start_epoch = get_later_start_epoch(header.slot) - epoch = compute_slot_epoch(header.slot) + epoch = compute_epoch_of_slot(header.slot) committee_count = max( earlier_validator_count // (SHARD_COUNT * TARGET_COMMITTEE_SIZE), @@ -192,7 +192,7 @@ def verify_block_validity_proof(proof: BlockValidityProof, validator_memory: Val pubkey=group_public_key, message_hash=hash_tree_root(shard_parent_block), signature=proof.shard_aggregate_signature, - domain=get_domain(state, compute_slot_epoch(shard_block.slot), DOMAIN_SHARD_ATTESTER), + domain=get_domain(state, compute_epoch_of_slot(shard_block.slot), DOMAIN_SHARD_ATTESTER), ) ``` diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 15eb4255f..422ea089c 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -147,7 +147,7 @@ def get_committee_assignment( assert epoch <= next_epoch committees_per_slot = get_committee_count(state, epoch) // SLOTS_PER_EPOCH - start_slot = compute_epoch_start_slot(epoch) + start_slot = compute_start_slot_of_epoch(epoch) for slot in range(start_slot, start_slot + SLOTS_PER_EPOCH): offset = committees_per_slot * (slot % SLOTS_PER_EPOCH) slot_start_shard = (get_start_shard(state, epoch) + offset) % SHARD_COUNT @@ -211,10 +211,10 @@ Set `block.randao_reveal = epoch_signature` where `epoch_signature` is defined a ```python epoch_signature = bls_sign( privkey=validator.privkey, # privkey stored locally, not in state - message_hash=hash_tree_root(compute_slot_epoch(block.slot)), + message_hash=hash_tree_root(compute_epoch_of_slot(block.slot)), domain=get_domain( fork=fork, # `fork` is the fork object at the slot `block.slot` - epoch=compute_slot_epoch(block.slot), + epoch=compute_epoch_of_slot(block.slot), domain_type=DOMAIN_RANDAO, ) ) @@ -253,7 +253,7 @@ block_signature = bls_sign( message_hash=signing_root(block), domain=get_domain( fork=fork, # `fork` is the fork object at the slot `block.slot` - epoch=compute_slot_epoch(block.slot), + epoch=compute_epoch_of_slot(block.slot), domain_type=DOMAIN_BEACON_BLOCK, ) ) @@ -309,7 +309,7 @@ Set `attestation_data.beacon_block_root = signing_root(head_block)`. *Note*: `epoch_boundary_block_root` can be looked up in the state using: -- Let `start_slot = compute_epoch_start_slot(get_current_epoch(head_state))`. +- Let `start_slot = compute_start_slot_of_epoch(get_current_epoch(head_state))`. - Let `epoch_boundary_block_root = signing_root(head_block) if start_slot == head_state.slot else get_block_root(state, start_slot)`. ##### Crosslink vote @@ -359,7 +359,7 @@ signed_attestation_data = bls_sign( message_hash=attestation_message, domain=get_domain( fork=fork, # `fork` is the fork object at the slot, `attestation_data.slot` - epoch=compute_slot_epoch(attestation_data.slot), + epoch=compute_epoch_of_slot(attestation_data.slot), domain_type=DOMAIN_ATTESTATION, ) ) @@ -379,7 +379,7 @@ To avoid "proposer slashings", a validator must not sign two conflicting [`Beaco Specifically, when signing a `BeaconBlock`, a validator should perform the following steps in the following order: -1. Save a record to hard disk that a beacon block has been signed for the `epoch=compute_slot_epoch(block.slot)`. +1. Save a record to hard disk that a beacon block has been signed for the `epoch=compute_epoch_of_slot(block.slot)`. 2. Generate and broadcast the block. If the software crashes at some point within this routine, then when the validator comes back online, the hard disk has the record of the *potentially* signed/broadcast block and can effectively avoid slashing. @@ -390,7 +390,7 @@ To avoid "attester slashings", a validator must not sign two conflicting [`Attes Specifically, when signing an `Attestation`, a validator should perform the following steps in the following order: -1. Save a record to hard disk that an attestation has been signed for source (i.e. `attestation_data.source_epoch`) and target (i.e. `compute_slot_epoch(attestation_data.slot)`). +1. Save a record to hard disk that an attestation has been signed for source (i.e. `attestation_data.source_epoch`) and target (i.e. `compute_epoch_of_slot(attestation_data.slot)`). 2. Generate and broadcast attestation. If the software crashes at some point within this routine, then when the validator comes back online, the hard disk has the record of the *potentially* signed/broadcast attestation and can effectively avoid slashing. diff --git a/test_libs/pyspec/eth2spec/test/helpers/attestations.py b/test_libs/pyspec/eth2spec/test/helpers/attestations.py index ba2bd3ca0..868517018 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/attestations.py +++ b/test_libs/pyspec/eth2spec/test/helpers/attestations.py @@ -15,7 +15,7 @@ def build_attestation_data(spec, state, slot, shard): else: block_root = spec.get_block_root_at_slot(state, slot) - current_epoch_start_slot = spec.compute_epoch_start_slot(spec.get_current_epoch(state)) + current_epoch_start_slot = spec.compute_start_slot_of_epoch(spec.get_current_epoch(state)) if slot < current_epoch_start_slot: epoch_boundary_root = spec.get_block_root(state, spec.get_previous_epoch(state)) elif slot == current_epoch_start_slot: @@ -30,7 +30,7 @@ def build_attestation_data(spec, state, slot, shard): source_epoch = state.current_justified_checkpoint.epoch source_root = state.current_justified_checkpoint.root - if spec.compute_slot_epoch(slot) == spec.get_current_epoch(state): + if spec.compute_epoch_of_slot(slot) == spec.get_current_epoch(state): parent_crosslink = state.current_crosslinks[shard] else: parent_crosslink = state.previous_crosslinks[shard] @@ -38,11 +38,11 @@ def build_attestation_data(spec, state, slot, shard): return spec.AttestationData( beacon_block_root=block_root, source=spec.Checkpoint(epoch=source_epoch, root=source_root), - target=spec.Checkpoint(epoch=spec.compute_slot_epoch(slot), root=epoch_boundary_root), + target=spec.Checkpoint(epoch=spec.compute_epoch_of_slot(slot), root=epoch_boundary_root), crosslink=spec.Crosslink( shard=shard, start_epoch=parent_crosslink.end_epoch, - end_epoch=min(spec.compute_slot_epoch(slot), parent_crosslink.end_epoch + spec.MAX_EPOCHS_PER_CROSSLINK), + end_epoch=min(spec.compute_epoch_of_slot(slot), parent_crosslink.end_epoch + spec.MAX_EPOCHS_PER_CROSSLINK), data_root=spec.Hash(), parent_root=hash_tree_root(parent_crosslink), ), @@ -53,7 +53,7 @@ def get_valid_attestation(spec, state, slot=None, signed=False): if slot is None: slot = state.slot - epoch = spec.compute_slot_epoch(slot) + epoch = spec.compute_epoch_of_slot(slot) epoch_start_shard = spec.get_start_shard(state, epoch) committees_per_slot = spec.get_committee_count(state, epoch) // spec.SLOTS_PER_EPOCH shard = (epoch_start_shard + committees_per_slot * (slot % spec.SLOTS_PER_EPOCH)) % spec.SHARD_COUNT diff --git a/test_libs/pyspec/eth2spec/test/helpers/block.py b/test_libs/pyspec/eth2spec/test/helpers/block.py index 830a1e9ec..2682a0c82 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/block.py +++ b/test_libs/pyspec/eth2spec/test/helpers/block.py @@ -14,7 +14,7 @@ def sign_block(spec, state, block, proposer_index=None): if block.slot == state.slot: proposer_index = spec.get_beacon_proposer_index(state) else: - if spec.compute_slot_epoch(state.slot) + 1 > spec.compute_slot_epoch(block.slot): + if spec.compute_epoch_of_slot(state.slot) + 1 > spec.compute_epoch_of_slot(block.slot): print("warning: block slot far away, and no proposer index manually given." " Signing block is slow due to transition for proposer index calculation.") # use stub state to get proposer index of future slot @@ -26,10 +26,10 @@ def sign_block(spec, state, block, proposer_index=None): block.body.randao_reveal = bls_sign( privkey=privkey, - message_hash=hash_tree_root(spec.compute_slot_epoch(block.slot)), + message_hash=hash_tree_root(spec.compute_epoch_of_slot(block.slot)), domain=spec.get_domain( state, - message_epoch=spec.compute_slot_epoch(block.slot), + message_epoch=spec.compute_epoch_of_slot(block.slot), domain_type=spec.DOMAIN_RANDAO, ) ) @@ -39,7 +39,7 @@ def sign_block(spec, state, block, proposer_index=None): domain=spec.get_domain( state, spec.DOMAIN_BEACON_PROPOSER, - spec.compute_slot_epoch(block.slot))) + spec.compute_epoch_of_slot(block.slot))) def apply_empty_block(spec, state): diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py index b7a34b5ee..7dcdb42a4 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py @@ -9,7 +9,7 @@ def run_process_just_and_fin(spec, state): def get_shards_for_slot(spec, state, slot): - epoch = spec.compute_slot_epoch(slot) + epoch = spec.compute_epoch_of_slot(slot) epoch_start_shard = spec.get_start_shard(state, epoch) committees_per_slot = spec.get_committee_count(state, epoch) // spec.SLOTS_PER_EPOCH shard = (epoch_start_shard + committees_per_slot * (slot % spec.SLOTS_PER_EPOCH)) % spec.SHARD_COUNT @@ -33,7 +33,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support total_balance = spec.get_total_active_balance(state) remaining_balance = total_balance * 2 // 3 - start_slot = spec.compute_epoch_start_slot(epoch) + start_slot = spec.compute_start_slot_of_epoch(epoch) for slot in range(start_slot, start_slot + spec.SLOTS_PER_EPOCH): for shard in get_shards_for_slot(spec, state, slot): # Check if we already have had sufficient balance. (and undone if we don't want it). @@ -41,7 +41,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support if remaining_balance < 0: return - committee = spec.get_crosslink_committee(state, spec.compute_slot_epoch(slot), shard) + committee = spec.get_crosslink_committee(state, spec.compute_epoch_of_slot(slot), shard) # Create a bitfield filled with the given count per attestation, # exactly on the right-most part of the committee field. @@ -80,7 +80,7 @@ def get_checkpoints(spec, epoch): def put_checkpoints_in_block_roots(spec, state, checkpoints): for c in checkpoints: - state.block_roots[spec.compute_epoch_start_slot(c.epoch) % spec.SLOTS_PER_HISTORICAL_ROOT] = c.root + state.block_roots[spec.compute_start_slot_of_epoch(c.epoch) % spec.SLOTS_PER_HISTORICAL_ROOT] = c.root def finalize_on_234(spec, state, epoch, sufficient_support): diff --git a/test_libs/pyspec/eth2spec/test/test_finality.py b/test_libs/pyspec/eth2spec/test/test_finality.py index cdeee2351..7d0e5d3db 100644 --- a/test_libs/pyspec/eth2spec/test/test_finality.py +++ b/test_libs/pyspec/eth2spec/test/test_finality.py @@ -43,7 +43,7 @@ def next_epoch_with_attestations(spec, block = build_empty_block_for_next_slot(spec, post_state) if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY: slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1 - if slot_to_attest >= spec.compute_epoch_start_slot(spec.get_current_epoch(post_state)): + if slot_to_attest >= spec.compute_start_slot_of_epoch(spec.get_current_epoch(post_state)): cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest) block.body.attestations.append(cur_attestation) From 41897e779a33ae66f505a4d3f076e57004165495 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Mon, 1 Jul 2019 00:10:28 +0200 Subject: [PATCH 4/7] validate_indexed_attestation -> is_valid_indexed_attestation` --- specs/core/0_beacon-chain.md | 80 +++++++++++++++++++----------------- specs/core/0_fork-choice.md | 2 +- specs/core/1_custody-game.md | 4 +- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index dcc3685f9..7104b7823 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -64,6 +64,7 @@ - [`is_active_validator`](#is_active_validator) - [`is_slashable_validator`](#is_slashable_validator) - [`is_slashable_attestation_data`](#is_slashable_attestation_data) + - [`is_valid_indexed_attestation`](#is_valid_indexed_attestation) - [`is_valid_merkle_branch`](#is_valid_merkle_branch) - [Misc](#misc-1) - [`compute_shuffled_index`](#compute_shuffled_index) @@ -72,7 +73,6 @@ - [`compute_start_slot_of_epoch`](#compute_start_slot_of_epoch) - [`compute_activation_exit_epoch`](#compute_activation_exit_epoch) - [`compute_bls_domain`](#compute_bls_domain) - - [`validate_indexed_attestation`](#validate_indexed_attestation) - [Beacon state accessors](#beacon-state-accessors) - [`get_current_epoch`](#get_current_epoch) - [`get_previous_epoch`](#get_previous_epoch) @@ -645,6 +645,45 @@ def is_slashable_attestation_data(data_1: AttestationData, data_2: AttestationDa ) ``` +#### `is_valid_indexed_attestation` + +```python +def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> bool: + """ + Verify validity of ``indexed_attestation``. + """ + bit_0_indices = indexed_attestation.custody_bit_0_indices + bit_1_indices = indexed_attestation.custody_bit_1_indices + + # Verify no index has custody bit equal to 1 [to be removed in phase 1] + if not len(bit_1_indices) == 0: + return False + # Verify max number of indices + if not len(bit_0_indices) + len(bit_1_indices) <= MAX_VALIDATORS_PER_COMMITTEE: + return False + # Verify index sets are disjoint + if not len(set(bit_0_indices).intersection(bit_1_indices)) == 0: + return False + # Verify indices are sorted + if not bit_0_indices == sorted(bit_0_indices) and bit_1_indices == sorted(bit_1_indices): + return False + # Verify aggregate signature + if not bls_verify_multiple( + pubkeys=[ + bls_aggregate_pubkeys([state.validators[i].pubkey for i in bit_0_indices]), + bls_aggregate_pubkeys([state.validators[i].pubkey for i in bit_1_indices]), + ], + message_hashes=[ + hash_tree_root(AttestationDataAndCustodyBit(data=indexed_attestation.data, custody_bit=0b0)), + hash_tree_root(AttestationDataAndCustodyBit(data=indexed_attestation.data, custody_bit=0b1)), + ], + signature=indexed_attestation.signature, + domain=get_domain(state, DOMAIN_ATTESTATION, indexed_attestation.data.target.epoch), + ): + return False + return True +``` + #### `is_valid_merkle_branch` ```python @@ -742,39 +781,6 @@ def compute_bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> return bytes_to_int(int_to_bytes(domain_type, length=4) + fork_version) ``` -#### `validate_indexed_attestation` - -```python -def validate_indexed_attestation(state: BeaconState, indexed_attestation: IndexedAttestation) -> None: - """ - Verify validity of ``indexed_attestation``. - """ - bit_0_indices = indexed_attestation.custody_bit_0_indices - bit_1_indices = indexed_attestation.custody_bit_1_indices - - # Verify no index has custody bit equal to 1 [to be removed in phase 1] - assert len(bit_1_indices) == 0 - # Verify max number of indices - assert len(bit_0_indices) + len(bit_1_indices) <= MAX_VALIDATORS_PER_COMMITTEE - # Verify index sets are disjoint - assert len(set(bit_0_indices).intersection(bit_1_indices)) == 0 - # Verify indices are sorted - assert bit_0_indices == sorted(bit_0_indices) and bit_1_indices == sorted(bit_1_indices) - # Verify aggregate signature - assert bls_verify_multiple( - pubkeys=[ - bls_aggregate_pubkeys([state.validators[i].pubkey for i in bit_0_indices]), - bls_aggregate_pubkeys([state.validators[i].pubkey for i in bit_1_indices]), - ], - message_hashes=[ - hash_tree_root(AttestationDataAndCustodyBit(data=indexed_attestation.data, custody_bit=0b0)), - hash_tree_root(AttestationDataAndCustodyBit(data=indexed_attestation.data, custody_bit=0b1)), - ], - signature=indexed_attestation.signature, - domain=get_domain(state, DOMAIN_ATTESTATION, indexed_attestation.data.target.epoch), - ) -``` - ### Beacon state accessors #### `get_current_epoch` @@ -1607,8 +1613,8 @@ def process_attester_slashing(state: BeaconState, attester_slashing: AttesterSla attestation_1 = attester_slashing.attestation_1 attestation_2 = attester_slashing.attestation_2 assert is_slashable_attestation_data(attestation_1.data, attestation_2.data) - validate_indexed_attestation(state, attestation_1) - validate_indexed_attestation(state, attestation_2) + assert is_valid_indexed_attestation(state, attestation_1) + assert is_valid_indexed_attestation(state, attestation_2) slashed_any = False attesting_indices_1 = attestation_1.custody_bit_0_indices + attestation_1.custody_bit_1_indices @@ -1654,7 +1660,7 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None: assert data.crosslink.data_root == Hash() # [to be removed in phase 1] # Check signature - validate_indexed_attestation(state, get_indexed_attestation(state, attestation)) + assert is_valid_indexed_attestation(state, get_indexed_attestation(state, attestation)) ``` ##### Deposits diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 82defa9b1..5ffc0e025 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -205,7 +205,7 @@ def on_attestation(store: Store, attestation: Attestation) -> None: # Get state at the `target` to validate attestation and calculate the committees indexed_attestation = get_indexed_attestation(target_state, attestation) - validate_indexed_attestation(target_state, indexed_attestation) + assert is_valid_indexed_attestation(target_state, indexed_attestation) # Update latest messages for i in indexed_attestation.custody_bit_0_indices + indexed_attestation.custody_bit_1_indices: diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index 863497076..dab24d91c 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -474,7 +474,7 @@ For each `challenge` in `block.body.custody_chunk_challenges`, run the following ```python def process_chunk_challenge(state: BeaconState, challenge: CustodyChunkChallenge) -> None: # Verify the attestation - validate_indexed_attestation(state, get_indexed_attestation(state, challenge.attestation)) + assert is_valid_indexed_attestation(state, get_indexed_attestation(state, challenge.attestation)) # Verify it is not too late to challenge assert (compute_epoch_of_slot(challenge.attestation.data.slot) >= get_current_epoch(state) - MAX_CHUNK_CHALLENGE_DELAY) @@ -528,7 +528,7 @@ def process_bit_challenge(state: BeaconState, challenge: CustodyBitChallenge) -> # Verify challenger is slashable assert is_slashable_validator(challenger, get_current_epoch(state)) # Verify attestation - validate_indexed_attestation(state, get_indexed_attestation(state, attestation)) + assert is_valid_indexed_attestation(state, get_indexed_attestation(state, attestation)) # Verify attestation is eligible for challenging responder = state.validators[challenge.responder_index] assert epoch + responder.max_reveal_lateness <= get_reveal_period(state, challenge.responder_index) From aeba6ee8fb4377f262274f25fc2afddd617cff32 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Mon, 1 Jul 2019 00:35:09 +0100 Subject: [PATCH 5/7] compute_domain for consistency with get_domain --- specs/core/0_beacon-chain.md | 12 ++++++------ specs/validator/0_beacon-chain-validator.md | 2 +- test_libs/pyspec/eth2spec/test/helpers/deposits.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7104b7823..9415814ac 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -72,7 +72,7 @@ - [`compute_epoch_of_slot`](#compute_epoch_of_slot) - [`compute_start_slot_of_epoch`](#compute_start_slot_of_epoch) - [`compute_activation_exit_epoch`](#compute_activation_exit_epoch) - - [`compute_bls_domain`](#compute_bls_domain) + - [`compute_domain`](#compute_domain) - [Beacon state accessors](#beacon-state-accessors) - [`get_current_epoch`](#get_current_epoch) - [`get_previous_epoch`](#get_previous_epoch) @@ -771,10 +771,10 @@ def compute_activation_exit_epoch(epoch: Epoch) -> Epoch: return Epoch(epoch + 1 + ACTIVATION_EXIT_DELAY) ``` -#### `compute_bls_domain` +#### `compute_domain` ```python -def compute_bls_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: +def compute_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: """ Return the BLS domain for the ``domain_type`` and ``fork_version``. """ @@ -1010,7 +1010,7 @@ def get_domain(state: BeaconState, domain_type: uint64, message_epoch: Epoch=Non """ epoch = get_current_epoch(state) if message_epoch is None else message_epoch fork_version = state.fork.previous_version if epoch < state.fork.epoch else state.fork.current_version - return compute_bls_domain(domain_type, fork_version) + return compute_domain(domain_type, fork_version) ``` #### `get_indexed_attestation` @@ -1685,8 +1685,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: if pubkey not in validator_pubkeys: # Verify the deposit signature (proof of possession) for new validators. # Note: The deposit contract does not check signatures. - # Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_bls_domain` - domain = compute_bls_domain(DOMAIN_DEPOSIT) + # Note: Deposits are valid across forks, thus the deposit domain is retrieved directly from `compute_domain` + domain = compute_domain(DOMAIN_DEPOSIT) if not bls_verify(pubkey, signing_root(deposit.data), deposit.data.signature, domain): return diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index a7542878b..0e9583a07 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -99,7 +99,7 @@ To submit a deposit: - Pack the validator's [initialization parameters](#initialization) into `deposit_data`, a [`DepositData`](../core/0_beacon-chain.md#depositdata) SSZ object. - Let `amount` be the amount in Gwei to be deposited by the validator where `MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE`. - Set `deposit_data.amount = amount`. -- Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=compute_bls_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `compute_bls_domain` will default to zeroes there). +- Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=compute_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `compute_domain` will default to zeroes there). - Send a transaction on the Ethereum 1.0 chain to `DEPOSIT_CONTRACT_ADDRESS` executing `def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])` along with a deposit of `amount` Gwei. *Note*: Deposits made for the same `pubkey` are treated as for the same validator. A singular `Validator` will be added to `state.validators` with each additional deposit amount added to the validator's balance. A validator can only be activated when total deposits for the validator pubkey meet or exceed `MAX_EFFECTIVE_BALANCE`. diff --git a/test_libs/pyspec/eth2spec/test/helpers/deposits.py b/test_libs/pyspec/eth2spec/test/helpers/deposits.py index 276fa617b..148bc9549 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/deposits.py +++ b/test_libs/pyspec/eth2spec/test/helpers/deposits.py @@ -19,7 +19,7 @@ def build_deposit_data(spec, pubkey, privkey, amount, withdrawal_credentials, st def sign_deposit_data(spec, deposit_data, privkey, state=None): if state is None: # Genesis - domain = spec.compute_bls_domain(spec.DOMAIN_DEPOSIT) + domain = spec.compute_domain(spec.DOMAIN_DEPOSIT) else: domain = spec.get_domain( state, From 1698263621c476850e2eccd012b9ebf3812c84a0 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Mon, 1 Jul 2019 00:36:19 +0100 Subject: [PATCH 6/7] BLS domain => domain --- specs/core/0_beacon-chain.md | 2 +- specs/test_formats/bls/msg_hash_g2_compressed.md | 4 ++-- specs/test_formats/bls/msg_hash_g2_uncompressed.md | 6 +++--- specs/test_formats/bls/sign_msg.md | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 9415814ac..bf7aa4dd5 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -776,7 +776,7 @@ def compute_activation_exit_epoch(epoch: Epoch) -> Epoch: ```python def compute_domain(domain_type: uint64, fork_version: bytes=b'\x00' * 4) -> int: """ - Return the BLS domain for the ``domain_type`` and ``fork_version``. + Return the domain for the ``domain_type`` and ``fork_version``. """ return bytes_to_int(int_to_bytes(domain_type, length=4) + fork_version) ``` diff --git a/specs/test_formats/bls/msg_hash_g2_compressed.md b/specs/test_formats/bls/msg_hash_g2_compressed.md index 44ea8ded7..d82041633 100644 --- a/specs/test_formats/bls/msg_hash_g2_compressed.md +++ b/specs/test_formats/bls/msg_hash_g2_compressed.md @@ -5,9 +5,9 @@ A BLS compressed-hash to G2. ## Test case format ```yaml -input: +input: message: bytes32, - domain: uint64 -- the BLS domain + domain: uint64 -- the domain output: List[bytes48] -- length of two ``` diff --git a/specs/test_formats/bls/msg_hash_g2_uncompressed.md b/specs/test_formats/bls/msg_hash_g2_uncompressed.md index 847b5f61d..873c767d7 100644 --- a/specs/test_formats/bls/msg_hash_g2_uncompressed.md +++ b/specs/test_formats/bls/msg_hash_g2_uncompressed.md @@ -1,13 +1,13 @@ # Test format: BLS hash-uncompressed -A BLS uncompressed-hash to G2. +A BLS uncompressed-hash to G2. ## Test case format ```yaml -input: +input: message: bytes32 - domain: uint64 -- the BLS domain + domain: uint64 -- the domain output: List[List[bytes48]] -- 3 lists, each a length of two ``` diff --git a/specs/test_formats/bls/sign_msg.md b/specs/test_formats/bls/sign_msg.md index b17e6246d..94346edaa 100644 --- a/specs/test_formats/bls/sign_msg.md +++ b/specs/test_formats/bls/sign_msg.md @@ -1,6 +1,6 @@ # Test format: BLS sign message -Message signing with BLS should produce a signature. +Message signing with BLS should produce a signature. ## Test case format @@ -8,7 +8,7 @@ Message signing with BLS should produce a signature. input: privkey: bytes32 -- the private key used for signing message: bytes32 -- input message to sign (a hash) - domain: uint64 -- the BLS domain + domain: uint64 -- the domain output: bytes96 -- expected signature ``` From b08d1d8d73fe1a05fa8a9fa442815f1dea259780 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 30 Jun 2019 20:13:27 -0500 Subject: [PATCH 7/7] fix associtivity in conditional --- 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 bf7aa4dd5..7d26c2dfe 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -665,7 +665,7 @@ def is_valid_indexed_attestation(state: BeaconState, indexed_attestation: Indexe if not len(set(bit_0_indices).intersection(bit_1_indices)) == 0: return False # Verify indices are sorted - if not bit_0_indices == sorted(bit_0_indices) and bit_1_indices == sorted(bit_1_indices): + if not (bit_0_indices == sorted(bit_0_indices) and bit_1_indices == sorted(bit_1_indices)): return False # Verify aggregate signature if not bls_verify_multiple(