Commit 02ff520
authored
fix(fork-choice): reject attestation slot before head block slot (lambdaclass#442)
## 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_018pvnQJkom3DobK9oSbK42T1 parent 2aa1d0e commit 02ff520
1 file changed
Lines changed: 92 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
225 | 235 | | |
226 | 236 | | |
227 | 237 | | |
| |||
858 | 868 | | |
859 | 869 | | |
860 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
861 | 877 | | |
862 | 878 | | |
863 | 879 | | |
| |||
1273 | 1289 | | |
1274 | 1290 | | |
1275 | 1291 | | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
1276 | 1367 | | |
1277 | 1368 | | |
1278 | 1369 | | |
| |||
0 commit comments