Skip to content

Commit 7b38b1f

Browse files
authored
Refactor get_attestation_participation_flag_indices (#4692)
This PR refactors the function in Altair so that it's easier to make modifications in Gloas. This PR should *not* change any functionality.
1 parent f1c4af5 commit 7b38b1f

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

specs/altair/beacon-chain.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,23 @@ def get_attestation_participation_flag_indices(
365365
"""
366366
Return the flag indices that are satisfied by an attestation.
367367
"""
368+
# Matching source
368369
if data.target.epoch == get_current_epoch(state):
369370
justified_checkpoint = state.current_justified_checkpoint
370371
else:
371372
justified_checkpoint = state.previous_justified_checkpoint
372-
373-
# Matching roots
374373
is_matching_source = data.source == justified_checkpoint
375-
is_matching_target = is_matching_source and data.target.root == get_block_root(
376-
state, data.target.epoch
377-
)
378-
is_matching_head = is_matching_target and data.beacon_block_root == get_block_root_at_slot(
379-
state, data.slot
380-
)
374+
375+
# Matching target
376+
target_root = get_block_root(state, data.target.epoch)
377+
target_root_matches = data.target.root == target_root
378+
is_matching_target = is_matching_source and target_root_matches
379+
380+
# Matching head
381+
head_root = get_block_root_at_slot(state, data.slot)
382+
head_root_matches = data.beacon_block_root == head_root
383+
is_matching_head = is_matching_target and head_root_matches
384+
381385
assert is_matching_source
382386

383387
participation_flag_indices = []

specs/deneb/beacon-chain.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,23 @@ def get_attestation_participation_flag_indices(
237237
"""
238238
Return the flag indices that are satisfied by an attestation.
239239
"""
240+
# Matching source
240241
if data.target.epoch == get_current_epoch(state):
241242
justified_checkpoint = state.current_justified_checkpoint
242243
else:
243244
justified_checkpoint = state.previous_justified_checkpoint
244-
245-
# Matching roots
246245
is_matching_source = data.source == justified_checkpoint
247-
is_matching_target = is_matching_source and data.target.root == get_block_root(
248-
state, data.target.epoch
249-
)
250-
is_matching_head = is_matching_target and data.beacon_block_root == get_block_root_at_slot(
251-
state, data.slot
252-
)
246+
247+
# Matching target
248+
target_root = get_block_root(state, data.target.epoch)
249+
target_root_matches = data.target.root == target_root
250+
is_matching_target = is_matching_source and target_root_matches
251+
252+
# Matching head
253+
head_root = get_block_root_at_slot(state, data.slot)
254+
head_root_matches = data.beacon_block_root == head_root
255+
is_matching_head = is_matching_target and head_root_matches
256+
253257
assert is_matching_source
254258

255259
participation_flag_indices = []

specs/gloas/beacon-chain.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -539,40 +539,42 @@ def get_next_sync_committee_indices(state: BeaconState) -> Sequence[ValidatorInd
539539

540540
#### Modified `get_attestation_participation_flag_indices`
541541

542+
*Note*: The function `get_attestation_participation_flag_indices` is modified to
543+
include a new payload matching constraint to `is_matching_head`.
544+
542545
```python
543546
def get_attestation_participation_flag_indices(
544547
state: BeaconState, data: AttestationData, inclusion_delay: uint64
545548
) -> Sequence[int]:
546549
"""
547550
Return the flag indices that are satisfied by an attestation.
548551
"""
552+
# Matching source
549553
if data.target.epoch == get_current_epoch(state):
550554
justified_checkpoint = state.current_justified_checkpoint
551555
else:
552556
justified_checkpoint = state.previous_justified_checkpoint
553-
554-
# Matching roots
555557
is_matching_source = data.source == justified_checkpoint
556-
is_matching_target = is_matching_source and data.target.root == get_block_root(
557-
state, data.target.epoch
558-
)
558+
559+
# Matching target
560+
target_root = get_block_root(state, data.target.epoch)
561+
target_root_matches = data.target.root == target_root
562+
is_matching_target = is_matching_source and target_root_matches
559563

560564
# [New in Gloas:EIP7732]
561-
is_matching_blockroot = is_matching_target and data.beacon_block_root == get_block_root_at_slot(
562-
state, Slot(data.slot)
563-
)
564-
is_matching_payload = False
565565
if is_attestation_same_slot(state, data):
566566
assert data.index == 0
567-
is_matching_payload = True
567+
payload_matches = True
568568
else:
569-
is_matching_payload = (
570-
data.index
571-
== state.execution_payload_availability[data.slot % SLOTS_PER_HISTORICAL_ROOT]
572-
)
569+
slot_index = data.slot % SLOTS_PER_HISTORICAL_ROOT
570+
payload_index = state.execution_payload_availability[slot_index]
571+
payload_matches = data.index == payload_index
573572

573+
# Matching head
574+
head_root = get_block_root_at_slot(state, data.slot)
575+
head_root_matches = data.beacon_block_root == head_root
574576
# [Modified in Gloas:EIP7732]
575-
is_matching_head = is_matching_blockroot and is_matching_payload
577+
is_matching_head = is_matching_target and head_root_matches and payload_matches
576578

577579
assert is_matching_source
578580

0 commit comments

Comments
 (0)