fix: reject attestations whose head is off the finalized chain#1502
Open
vuonghuuhung wants to merge 2 commits into
Open
fix: reject attestations whose head is off the finalized chain#1502vuonghuuhung wants to merge 2 commits into
vuonghuuhung wants to merge 2 commits into
Conversation
99b6c50 to
2c4474a
Compare
Collaborator
2c4474a to
5032cab
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

What was wrong?
Address leanSpec #1179 (issue #1176)
TL;DR:
validate_attestationnow rejects an attestation whoseheaddoes not descend fromlatest_finalized, mirroring the predicateprune_stale_attestation_dataalready uses.Before this change, admission only checked ancestry between
source,target, andheadagainst each other, never against the store'slatest_finalized. So a vote could be admitted, later dropped by pruning once its head landed on a finalized-orphaned branch, and then be re-admitted unchanged if the same vote was re-gossiped, undoing the prune and forcing repeated signature verification on data that carries zero fork-choice weight (its head is unreachable from the justified root once finalized has moved past it). Not a consensus-safety bug, but a pool-inflation / prune-idempotence gap.How was it fixed?
validate_attestationincrates/common/fork_choice/lean/src/store.rsnow checkscheckpoint_is_ancestor(latest_finalized, head)alongside the existing source→target and target→head ancestry checks. A head equal to the finalized checkpoint still passes, so genesis-adjacent votes aren't wrongly rejected.test_validate_attestation_rejects_head_on_finalized_orphaned_branch: builds a canonical branch and a sibling orphan branch off the same parent, finalizes onto the canonical branch, and asserts a vote whose head is on the orphan branch is now rejected.test_validate_attestation_accepts_head_descending_from_finalized: same setup, asserts a vote whose head descends from the canonical/finalized branch is still accepted.latest_justified(table doc): highest-slot justified checkpoint; the head walk starts here.latest_finalized(table doc) andprune_stale_attestation_data(fn doc): finalized is re-derived from the head every update, so it's reorg-mutable, always an ancestor of the head, never monotone, never a safety guarantee on its own, pruning against it is only sound because of that re-derivation.What's to notice
RejectionReason+ the ancestry check). M-1, M-3 and M-4 are documentation-only in leanSpec's diff too, ported here as doc comments.validate_attestationusesanyhow::ensure!with string messages throughout), so no new error type was introduced.To-Do