Skip to content

Commit 7fb55f7

Browse files
authored
Document attestation target clamping as defensive guard (#214)
## Motivation A spec-to-code compliance audit (FINDING-003) identified that `get_attestation_target` adds a clamping guard to `latest_justified` that the spec does not have. The code was correct but lacked explanation of why the guard exists and that it diverges from the spec. ## Description Clarifies the comment on the `latest_justified` clamping in `get_attestation_target` to explain: - The spec's justifiability walk-back has no lower bound and can produce attestations where `target.slot < source.slot` - These would fail `is_valid_vote` Rule 5 and be discarded, but producing them wastes work and pollutes the network - The clamping is our defensive addition, not spec behavior - This edge case triggers when a block advances `latest_justified` between `safe_target` updates (interval 2) ## How to Test Documentation-only change. `cargo test --workspace --release` passes.
1 parent 3e54039 commit 7fb55f7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

crates/blockchain/src/store.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,16 @@ pub fn get_attestation_target(store: &Store) -> Checkpoint {
693693
.get_block_header(&target_block_root)
694694
.expect("parent block exists");
695695
}
696-
// Ensure target is at or after the source (latest_justified) to maintain
697-
// the invariant: source.slot <= target.slot. When a block advances
698-
// latest_justified between safe_target updates (interval 2), the walk-back
699-
// above can land on a slot behind the new justified checkpoint.
696+
// Guard: clamp target to latest_justified (not in the spec).
697+
//
698+
// The spec's walk-back has no lower bound, so it can produce attestations
699+
// where target.slot < source.slot (source = latest_justified). These would
700+
// fail is_valid_vote Rule 5 (target.slot > source.slot) and be discarded,
701+
// but producing them wastes work and pollutes the network.
702+
//
703+
// This happens when a block advances latest_justified between safe_target
704+
// updates (interval 2), causing the walk-back to land behind the new
705+
// justified checkpoint.
700706
//
701707
// See https://github.com/blockblaz/zeam/blob/697c293879e922942965cdb1da3c6044187ae00e/pkgs/node/src/forkchoice.zig#L654-L659
702708
let latest_justified = store.latest_justified();

0 commit comments

Comments
 (0)