-
Notifications
You must be signed in to change notification settings - Fork 80
fix: use head state's justified checkpoint as attestation source #506
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
Merged
tcoratger
merged 4 commits into
leanEthereum:main
from
GrapeBaBa:fix/attestation-source-use-head-state-justified-v2
Apr 1, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
93d6366
fix: use head state's justified checkpoint as attestation source
GrapeBaBa 34c31dd
test: add regression test for attestation source divergence
GrapeBaBa e68dc42
docs: improve attestation source documentation and test clarity
tcoratger ecfaf6e
test: add spec test vector for attestation source divergence
tcoratger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
tests/consensus/devnet/fc/test_attestation_source_divergence.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| """Attestation Source Divergence""" | ||
|
|
||
| import pytest | ||
| from consensus_testing import ( | ||
| AggregatedAttestationSpec, | ||
| AttestationStep, | ||
| BlockSpec, | ||
| BlockStep, | ||
| ForkChoiceTestFiller, | ||
| GossipAttestationSpec, | ||
| StoreChecks, | ||
| ) | ||
|
|
||
| from lean_spec.subspecs.containers.slot import Slot | ||
| from lean_spec.subspecs.containers.validator import ValidatorIndex | ||
|
|
||
| pytestmark = pytest.mark.valid_until("Devnet") | ||
|
|
||
|
|
||
| def test_gossip_attestation_accepted_after_fork_advances_justified( | ||
| fork_choice_test: ForkChoiceTestFiller, | ||
| ) -> None: | ||
| """ | ||
| Gossip attestation is valid when the global justified diverges from head. | ||
|
|
||
| Scenario | ||
| -------- | ||
| Four validators. The chain forks at slot 1:: | ||
|
|
||
| genesis ── slot 1 ("common") ─┬── slot 2 ── slot 3 (head, V0 weight) | ||
| └── slot 4 (fork, V1+V2+V3 justify "common") | ||
|
|
||
| The fork block carries attestations from 3 of 4 validators for the fork | ||
| point. This crosses the 2/3 threshold and advances the store-wide justified | ||
| checkpoint to slot 1. | ||
|
|
||
| The head chain has not seen those votes, so its state still holds the | ||
| genesis justified checkpoint (slot 0). After the fork is processed: | ||
|
|
||
| - Store-wide justified: slot 1 | ||
| - Head state justified: slot 0 | ||
|
|
||
| A gossip attestation is then produced at slot 5. The attestation target | ||
| walks back 3 slots from head (slot 3) and lands on genesis (slot 0). | ||
|
|
||
| The source must come from the head state (slot 0) so that the | ||
| monotonicity invariant holds (source.slot <= target.slot). Using the | ||
| store-wide value (slot 1) would violate it and be rejected. | ||
| """ | ||
| fork_choice_test( | ||
| steps=[ | ||
| # Common ancestor — the fork point for both chains. | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(1), label="common"), | ||
| checks=StoreChecks(head_slot=Slot(1)), | ||
| ), | ||
| # Main chain, first extension. | ||
| BlockStep( | ||
| block=BlockSpec(slot=Slot(2), parent_label="common", label="block_2"), | ||
| checks=StoreChecks(head_slot=Slot(2)), | ||
| ), | ||
| # Main chain, second extension. | ||
| # V0 attests for block_2, giving this branch LMD-GHOST weight | ||
| # so that it stays head after the fork block arrives. | ||
| BlockStep( | ||
| block=BlockSpec( | ||
| slot=Slot(3), | ||
| parent_label="block_2", | ||
| label="block_3", | ||
| attestations=[ | ||
| AggregatedAttestationSpec( | ||
| validator_ids=[ValidatorIndex(0)], | ||
| slot=Slot(2), | ||
| target_slot=Slot(2), | ||
| target_root_label="block_2", | ||
| ), | ||
| ], | ||
| ), | ||
| checks=StoreChecks(head_slot=Slot(3)), | ||
| ), | ||
| # Minority fork. V1, V2, V3 attest for the fork point. | ||
| # 3 of 4 validators cross the 2/3 threshold, advancing the | ||
| # store-wide justified checkpoint to slot 1. Head stays on | ||
| # the main chain thanks to V0's weight. | ||
| BlockStep( | ||
| block=BlockSpec( | ||
| slot=Slot(4), | ||
| parent_label="common", | ||
| label="fork_block", | ||
| attestations=[ | ||
| AggregatedAttestationSpec( | ||
| validator_ids=[ | ||
| ValidatorIndex(1), | ||
| ValidatorIndex(2), | ||
| ValidatorIndex(3), | ||
| ], | ||
| slot=Slot(1), | ||
| target_slot=Slot(1), | ||
| target_root_label="common", | ||
| ), | ||
| ], | ||
| ), | ||
| checks=StoreChecks( | ||
| head_slot=Slot(3), | ||
| head_root_label="block_3", | ||
| latest_justified_slot=Slot(1), | ||
| latest_justified_root_label="common", | ||
| ), | ||
| ), | ||
| # Gossip attestation from V3 at slot 5. | ||
| # | ||
| # This exercises the attestation production code path. | ||
| # The target walks back to genesis (slot 0). The source must | ||
| # be slot 0 (head state) so that source <= target holds. | ||
| AttestationStep( | ||
| attestation=GossipAttestationSpec( | ||
| validator_id=ValidatorIndex(3), | ||
| slot=Slot(5), | ||
| target_slot=Slot(3), | ||
| target_root_label="block_3", | ||
| ), | ||
| ), | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.