Commit d96e524
authored
fix(fork-choice): bound a block's slot before the state transition (leanSpec #1182) (#501)
## What
Ports leanSpec
[#1182](leanEthereum/leanSpec#1182): bound a
block's slot in `on_block` before the state transition runs.
## Why
`on_block` had a lower slot bound but no upper bound. The transition
advances the state one slot at a time from the parent up to
`block.slot`, and the proposer of a slot is `slot % num_validators`, so
one key is a valid proposer for infinitely many slots. A single
validly-signed block on a reachable parent (e.g. genesis) could
therefore drive an unbounded empty-slot walk.
ethlambda is not vulnerable to the unbounded *loop* (`process_slots`
jumps straight to the target slot rather than iterating) and
`process_block_header` already caps the `historical_block_hashes`
allocation via `SlotGapTooLarge`. This PR adds the spec's two guards at
the untrusted-input boundary so a crafted block is rejected *cheaply*,
before signature verification.
## Changes
`crates/blockchain/src/store.rs`, in `on_block_core` before signature
verification:
- **Parent-gap cap:** reject `block.slot - parent.slot >
HISTORICAL_ROOTS_LIMIT` (`BlockSlotGapTooLarge`). Clock-independent;
bounds the walk directly.
- **Clock horizon:** reject `block.slot > current_slot + 1`
(`BlockTooFarInFuture`). Whole-slot margin, so an intended early block
still imports (mirrors the attestation future-slot guard, but with a
whole-slot rather than one-interval margin).
The existing STF-level `SlotGapTooLarge` in `process_block_header` is
kept as defense-in-depth.
## Tests
- `on_block_rejects_block_too_far_in_future`
- `on_block_rejects_block_slot_gap_too_large`
`cargo fmt`, `clippy -D warnings`, and the blockchain lib tests pass.
> 1 parent 699599c commit d96e524
1 file changed
Lines changed: 110 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
538 | 563 | | |
539 | 564 | | |
540 | 565 | | |
| |||
949 | 974 | | |
950 | 975 | | |
951 | 976 | | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
952 | 983 | | |
953 | 984 | | |
954 | 985 | | |
| |||
1500 | 1531 | | |
1501 | 1532 | | |
1502 | 1533 | | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
1503 | 1612 | | |
0 commit comments