Commit 9c30436
fix: use head state's justified checkpoint as attestation source (leanEthereum#506)
* fix: use head state's justified checkpoint as attestation source
produce_attestation_data was using store.latest_justified as the
attestation source, while build_block filters attestations against
head_state.latest_justified. When store.latest_justified diverges
from head_state.latest_justified (caused by processing a non-head-chain
block that crosses the 2/3 supermajority threshold), all attestations
get filtered out during block building, producing blocks with 0
attestations.
Align with the 3sf-mini reference: Staker.vote() uses
post_states[head].latest_justified_hash, not a global max. The
store-wide latest_justified is only used for fork choice (recompute_head,
compute_safe_target), never for voting.
Includes genesis root correction matching build_block's existing pattern:
the stored genesis state has latest_justified.root = Bytes32.zero(),
but attestation validation requires roots that exist in store.blocks.
* test: add regression test for attestation source divergence
Verifies produce_attestation_data uses head_state.latest_justified
(not store.latest_justified) when the two diverge. This scenario
happens when a non-head fork advances store.latest_justified, which
would cause build_block to filter out all attestations.
* docs: improve attestation source documentation and test clarity
Rewrite produce_attestation_data docstring and latest_justified field
docs to teach readers the invariant directly rather than referencing
past bugs or external implementations. Add line-by-line comments to
the unit test explaining each step of the divergence scenario.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test: add spec test vector for attestation source divergence
Fork choice test that creates a justified divergence between the
store-wide global max and the head state. A gossip attestation is
produced via the store's attestation production path and validated.
Fails without the fix: source.slot (1) > target.slot (0) violates
the monotonicity invariant. Passes with the fix: source comes from
the head state (slot 0) instead of the global max.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Thomas Coratger <thomas.coratger@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0deaf57 commit 9c30436
3 files changed
Lines changed: 211 additions & 13 deletions
File tree
- src/lean_spec/subspecs/forkchoice
- tests
- consensus/devnet/fc
- lean_spec/subspecs/forkchoice
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 100 | + | |
103 | 101 | | |
| 102 | + | |
| 103 | + | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
| |||
1186 | 1189 | | |
1187 | 1190 | | |
1188 | 1191 | | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
1192 | 1198 | | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1198 | 1207 | | |
1199 | 1208 | | |
1200 | 1209 | | |
1201 | 1210 | | |
1202 | 1211 | | |
1203 | 1212 | | |
1204 | 1213 | | |
1205 | | - | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1206 | 1226 | | |
1207 | 1227 | | |
1208 | 1228 | | |
| |||
1216 | 1236 | | |
1217 | 1237 | | |
1218 | 1238 | | |
1219 | | - | |
| 1239 | + | |
1220 | 1240 | | |
1221 | 1241 | | |
1222 | 1242 | | |
| |||
Lines changed: 124 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
790 | 791 | | |
791 | 792 | | |
792 | 793 | | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
0 commit comments