Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a number of minor fixes in phase 1 #1120

Merged
merged 1 commit into from
May 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions specs/core/1_shard-data-chains.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_shard_header(block: ShardBlock) -> ShardBlockHeader:
def verify_shard_attestation_signature(state: BeaconState,
attestation: ShardAttestation) -> None:
data = attestation.data
persistent_committee = get_persistent_committee(state, data.crosslink.shard, data.slot)
persistent_committee = get_persistent_committee(state, data.shard, data.slot)
assert verify_bitfield(attestation.aggregation_bitfield, len(persistent_committee))
pubkeys = []
for i, index in enumerate(persistent_committee):
Expand All @@ -225,7 +225,7 @@ def verify_shard_attestation_signature(state: BeaconState,
pubkeys.append(validator.pubkey)
assert bls_verify(
pubkey=bls_aggregate_pubkeys(pubkeys),
message_hash=data.crosslink.shard_block_root,
message_hash=data.shard_block_root,
signature=attestation.aggregate_signature,
domain=get_domain(state, slot_to_epoch(data.slot), DOMAIN_SHARD_ATTESTER)
)
Expand Down Expand Up @@ -280,49 +280,49 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
return True

# Check slot number
assert block.slot >= PHASE_1_GENESIS_SLOT
assert candidate.slot >= PHASE_1_GENESIS_SLOT
assert unix_time >= beacon_state.genesis_time + (block.slot - GENESIS_SLOT) * SECONDS_PER_SLOT

# Check shard number
assert block.shard <= SHARD_COUNT
assert candidate.shard <= SHARD_COUNT

# Check beacon block
beacon_block = beacon_blocks[block.slot]
assert block.beacon_block_root == signing_root(beacon_block)
assert beacon_block.slot <= block.slot:
beacon_block = beacon_blocks[candidate.slot]
assert candidate.beacon_block_root == signing_root(beacon_block)
assert beacon_block.slot <= candidate.slot:

# Check state root
assert block.state_root == ZERO_HASH # [to be removed in phase 2]
assert candidate.state_root == ZERO_HASH # [to be removed in phase 2]

# Check parent block
if block.slot == PHASE_1_GENESIS_SLOT:
if candidate.slot == PHASE_1_GENESIS_SLOT:
assert candidate.parent_root == ZERO_HASH
else:
parent_block = next(
block for block in valid_shard_blocks if
signing_root(block) == candidate.parent_root
, None)
assert parent_block != None
assert parent_block.shard == block.shard
assert parent_block.slot < block.slot
assert parent_block.shard == candidate.shard
assert parent_block.slot < candidate.slot
assert signing_root(beacon_blocks[parent_block.slot]) == parent_block.beacon_chain_root

# Check attestations
assert len(block.attestations) <= MAX_SHARD_ATTESTIONS
for _, attestation in enumerate(block.attestations):
assert max(GENESIS_SHARD_SLOT, block.slot - SLOTS_PER_EPOCH) <= attestation.data.slot
assert attestation.data.slot <= block.slot - MIN_ATTESTATION_INCLUSION_DELAY
assert attestation.data.crosslink.shard == block.shard
assert len(candidate.attestations) <= MAX_SHARD_ATTESTIONS
for _, attestation in enumerate(candidate.attestations):
assert max(GENESIS_SHARD_SLOT, candidate.slot - SLOTS_PER_EPOCH) <= attestation.data.slot
assert attestation.data.slot <= candidate.slot - MIN_ATTESTATION_INCLUSION_DELAY
assert attestation.data.crosslink.shard == candidate.shard
verify_shard_attestation_signature(beacon_state, attestation)

# Check signature
proposer_index = get_shard_proposer_index(beacon_state, block.shard, block.slot)
proposer_index = get_shard_proposer_index(beacon_state, candidate.shard, candidate.slot)
assert proposer_index is not None
assert bls_verify(
pubkey=validators[proposer_index].pubkey,
message_hash=signing_root(block),
signature=block.signature,
domain=get_domain(beacon_state, slot_to_epoch(block.slot), DOMAIN_SHARD_PROPOSER)
signature=candidate.signature,
domain=get_domain(beacon_state, slot_to_epoch(candidate.slot), DOMAIN_SHARD_PROPOSER)
)

return True
Expand All @@ -339,18 +339,18 @@ Let:
```python
def is_valid_shard_attestation(valid_shard_blocks: List[ShardBlock],
beacon_state: BeaconState,
candidate: Attestation) -> bool:
candidate: ShardAttestation) -> bool:
# Check shard block
shard_block = next(
block for block in valid_shard_blocks if
signing_root(block) == candidate.attestation.data.crosslink.shard_block_root
signing_root(block) == candidate.data.shard_block_root
, None)
assert shard_block != None
assert shard_block.slot == attestation.data.slot
assert shard_block.shard == attestation.data.crosslink.shard
assert shard_block.slot == candidate.data.slot
assert shard_block.shard == candidate.data.shard

# Check signature
verify_shard_attestation_signature(beacon_state, attestation)
verify_shard_attestation_signature(beacon_state, candidate)

return True
```
Expand Down