Skip to content

fix: bound attestation slot against head and store clock#1020

Merged
tcoratger merged 3 commits into
leanEthereum:mainfrom
tcoratger:audit/forks-fix-attestation-slot-bound
Jun 14, 2026
Merged

fix: bound attestation slot against head and store clock#1020
tcoratger merged 3 commits into
leanEthereum:mainfrom
tcoratger:audit/forks-fix-attestation-slot-bound

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Hazard

The gossip attestation validator fed the unbounded wire field attestation_data.slot straight into the slot-to-interval conversion, which multiplies the slot by the intervals-per-slot count and wraps the product in a range-checked unsigned 64-bit constructor. A crafted gossip attestation with a near-2**64 slot raised a pydantic.ValidationError that escapes the gossip handler's rejection-only catch and crashes the importing node. One crafted message downs a node, a remote denial of service.

The deeper cause is that the slot was never tied to the head checkpoint it claims to have seen, so it could be set to an arbitrary value relative to the observed head.

Property at risk

  • Liveness / availability: a single unauthenticated gossip message can crash any node on the network.
  • Soundness: the attestation slot records when the head was observed; an unbounded slot violates the intended 3SF attestation semantics.

Fix

Two checks are added after the topology checks in attestation validation:

  • The vote's slot must not precede the slot of the head block it claims to have seen, surfaced as a new ATTESTATION_SLOT_BEFORE_HEAD rejection. This anchors the wire slot from below by a known block and enforces the head-consistency invariant.
  • The future-time gate now compares in slot units with plain-int arithmetic before constructing any interval, so a near-ceiling slot is rejected cleanly instead of overflowing. The integer comparison is mathematically equivalent to the previous interval comparison: with a positive intervals-per-slot count, slot * intervals_per_slot > horizon is the same as slot > horizon // intervals_per_slot.

Adds two negative consensus vectors: a slot at the unsigned 64-bit ceiling rejected without overflow, and a slot preceding its head. All 115 fork-choice vectors still fill green.

🤖 Generated with Claude Code

tcoratger and others added 3 commits June 14, 2026 14:51
The gossip attestation validator fed the unbounded wire field
attestation_data.slot straight into the interval conversion, which
multiplies it by the intervals-per-slot count and wraps the product in a
range-checked unsigned 64-bit constructor. A crafted gossip attestation
with a near-2**64 slot raised a pydantic validation error that escaped
the gossip handler's rejection-only catch and crashed the node, a
one-message remote denial of service.

The root cause is that the slot was never tied to the head it claims.
This change adds two checks after the topology checks:

- The vote's slot must not precede the slot of the head block it claims
  to have seen, surfaced as a new ATTESTATION_SLOT_BEFORE_HEAD rejection.
  This anchors the wire slot from below by a known block and enforces the
  3SF attestation semantics where the slot records when the head was seen.
- The future-time gate now compares in slot units with plain-int
  arithmetic before constructing any interval, so a near-ceiling slot is
  rejected cleanly instead of overflowing. The integer comparison is
  equivalent to the previous interval comparison.

Adds two negative consensus vectors: one for a slot at the unsigned
64-bit ceiling rejected without overflow, and one for a slot preceding
its head. All 115 fork-choice vectors still fill green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Split multi-clause sentences onto their own lines and replace
code-identifier-style names (intervals_per_slot, horizon) in the
head-consistency and time-check comments with plain English, per
the documentation rules. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cut the head-consistency and time-check comments to their essential
reason (two lines each) and shorten the new rejection-reason docstring.
No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 8382476 into leanEthereum:main Jun 14, 2026
14 checks passed
pablodeymo pushed a commit to lambdaclass/ethlambda that referenced this pull request Jun 18, 2026
## What

Ports the head-consistency guard from [leanSpec PR
#1020](leanEthereum/leanSpec#1020) into
`validate_attestation_data`.

A gossip attestation's slot records *when* the head was observed, so it
cannot precede the slot of the head block it claims to have seen. We did
not enforce this lower bound: the wire `slot` field was untethered from
any real block, free to be set arbitrarily relative to the observed
head.

## Why

| Property | Risk without the guard |
|----------|------------------------|
| Soundness | An unbounded slot violates 3SF attestation semantics: the
slot is meant to anchor when the head was seen. |
| Liveness (spec context) | In leanSpec a crafted near-`2**64` slot
overflowed the slot→interval constructor and crashed the node (remote
DoS). |

**Note on the overflow half:** ethlambda's time check already uses
`saturating_mul` (`data.slot.saturating_mul(INTERVALS_PER_SLOT)`), so a
near-`u64::MAX` slot saturates to `u64::MAX` and is rejected cleanly as
too-far-in-future rather than panicking. The Rust port was never
crashable the way the unchecked Python constructor was, so no change to
the time-check arithmetic is needed; the spec's switch to slot-unit
comparison is mathematically equivalent to the existing interval
comparison. This PR adds the genuinely missing piece: the semantic lower
bound.

## Change

- New `StoreError::AttestationSlotBeforeHead { attestation_slot,
head_slot }` rejection.
- Check `data.slot < data.head.slot` after the ancestry checks, before
the time check (mirrors the spec's ordering).
- Two unit tests: a vote whose slot precedes its head (rejected as
`AttestationSlotBeforeHead`), and a `u64::MAX` ceiling slot (rejected as
`AttestationTooFarInFuture`, confirming no overflow).

Applies to both gossip paths via the shared `validate_attestation_data`
(`on_gossip_attestation` and `on_gossip_aggregated_attestation`).

## Testing

```
cargo test -p ethlambda-blockchain --lib validate_attestation   # 5 passed
cargo fmt --all && cargo clippy -p ethlambda-blockchain --lib    # clean
```

https://claude.ai/code/session_018pvnQJkom3DobK9oSbK42T
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