1. Check on-time attestations fit `attestation.data.shard_transition_root != hash_tree_root(ShardTransition())`
2. Move `attestation.data.shard_head_root` check to after winning root
This commit is contained in:
Hsiao-Wei Wang 2020-06-23 18:22:18 +08:00
parent 5357bddcf8
commit e52c19896d
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 8 additions and 5 deletions

View File

@ -772,6 +772,8 @@ def validate_attestation(state: BeaconState, attestation: Attestation) -> None:
# Correct shard number
shard = compute_shard_from_committee_index(state, attestation.data.index, attestation.data.slot)
assert attestation.data.shard == shard
# On-time attestations should have a non-empty shard transition root
assert attestation.data.shard_transition_root != hash_tree_root(ShardTransition())
# Type 2: no shard transition
else:
# Ensure delayed attestation
@ -886,11 +888,6 @@ def process_crosslink_for_shard(state: BeaconState,
for attestation in transition_attestations:
participants = get_attesting_indices(state, attestation.data, attestation.aggregation_bits)
transition_participants = transition_participants.union(participants)
if len(shard_transition.shard_states) > 0:
# Is the `shard_transition` candidate
last_offset_index = len(shard_transition.shard_states) - 1
shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root
assert attestation.data.shard_head_root == shard_head_root
enough_online_stake = (
get_total_balance(state, online_indices.intersection(transition_participants)) * 3 >=
@ -903,6 +900,12 @@ def process_crosslink_for_shard(state: BeaconState,
# Attestation <-> shard transition consistency
assert shard_transition_root == hash_tree_root(shard_transition)
# Check `shard_head_root` of the winning root
last_offset_index = len(shard_transition.shard_states) - 1
shard_head_root = shard_transition.shard_states[last_offset_index].latest_block_root
for attestation in transition_attestations:
assert attestation.data.shard_head_root == shard_head_root
# Apply transition
apply_shard_transition(state, shard, shard_transition)
# Apply proposer reward and cost