Skip to content

fix: clamp attestation target walk to finalized boundary#818

Open
latifkasuli wants to merge 1 commit into
leanEthereum:mainfrom
latifkasuli:fix/stale-safe-target-finalization
Open

fix: clamp attestation target walk to finalized boundary#818
latifkasuli wants to merge 1 commit into
leanEthereum:mainfrom
latifkasuli:fix/stale-safe-target-finalization

Conversation

@latifkasuli
Copy link
Copy Markdown
Contributor

@latifkasuli latifkasuli commented Jun 1, 2026

Summary

Fixes an Lstar attestation-target boundary bug where get_attestation_target() could walk below the latest finalized checkpoint when safe_target was stale behind finalization.

The target-selection walk now uses max(safe_target.slot, latest_finalized.slot) as its lower bound, and the justifiability walk stops at the finalized boundary before calling is_justifiable_after().

Root Cause

safe_target can legally lag behind latest_finalized. In that state, the previous implementation walked backward from head toward the stale safe target, crossed below the finalized slot, and then called:

slot.is_justifiable_after(latest_finalized.slot)

on a candidate slot before finalization. That violates the slot helper invariant and raises:

Candidate slot must not be before finalized slot

Validation

  • Pre-fix targeted regression fails with Candidate slot must not be before finalized slot
  • uv run --group test pytest tests/lean_spec/spec/forks/lstar/forkchoice/test_attestation_target.py -q --no-cov
  • uv run --group test pytest tests/lean_spec/spec/forks/lstar/forkchoice/test_block_production_justification_gap.py tests/lean_spec/spec/forks/lstar/state -q --no-cov
  • uv run --group lint ruff check src/lean_spec/spec/forks/lstar/validator_duties.py tests/lean_spec/spec/forks/lstar/forkchoice/test_attestation_target.py
  • uv run --group lint ruff format --check src/lean_spec/spec/forks/lstar/validator_duties.py tests/lean_spec/spec/forks/lstar/forkchoice/test_attestation_target.py
  • uv run --group lint ty check src/lean_spec/spec/forks/lstar/validator_duties.py tests/lean_spec/spec/forks/lstar/forkchoice/test_attestation_target.py
  • git diff --check

@latifkasuli latifkasuli force-pushed the fix/stale-safe-target-finalization branch from dd851b0 to ab78ec1 Compare June 2, 2026 11:02
@latifkasuli latifkasuli marked this pull request as ready for review June 2, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant