Commit 699599c
authored
fix(state-transition): reject malformed justification state with typed errors (leanSpec #1178) (#502)
## What
Ports the reachable robustness guards from leanSpec
[#1178](leanEthereum/leanSpec#1178): reject a
malformed justification-bookkeeping `State` in `process_attestations`
with typed errors instead of silently mis-counting.
## Why
`process_attestations` unpacks the flat `justifications_validators` bit
list as one validator-sized segment per tracked root. A `State`
reconstructed from untrusted bytes (checkpoint sync) satisfies SSZ yet
can still break the cross-field invariant
`len(justifications_validators) == len(justifications_roots) *
validator_count` — SSZ decoding cannot enforce it. ethlambda's
index-range unpack (`.get(j)`) does not crash on a mismatch, but it
silently produces short/wrong vote segments. These guards close that
gap.
## Changes
`crates/blockchain/state_transition/src/lib.rs`, in
`process_attestations`, before the unpack:
- **Empty registry:** reject `validator_count == 0` (`NoValidators`).
Belt-and-suspenders — the header stage rejects this first in the normal
flow — but the unpack relies on a non-zero segment width directly.
- **Vote-list length mismatch:** reject `justifications_validators.len()
!= justifications_roots.len() * validator_count` (new
`JustificationVotesLengthMismatch`).
Checks are ordered to match the spec (registry → length → zero-hash).
The zero-hash-root guard and the totality of `slot_is_justifiable_after`
(the other two items in #1178) were already present in ethlambda, so
they are unchanged.
For a well-formed state none of these fire, so honest operation and
state roots are unaffected.
## Tests
- `process_attestations_rejects_justification_votes_length_mismatch`
- `process_attestations_rejects_empty_validator_registry`
`cargo fmt`, `clippy -D warnings`, and the state-transition lib tests
pass.1 parent f55fe5c commit 699599c
1 file changed
Lines changed: 121 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
241 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
242 | 272 | | |
243 | 273 | | |
244 | 274 | | |
245 | 275 | | |
246 | 276 | | |
247 | 277 | | |
248 | 278 | | |
249 | | - | |
| 279 | + | |
250 | 280 | | |
251 | 281 | | |
252 | 282 | | |
| |||
854 | 884 | | |
855 | 885 | | |
856 | 886 | | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
857 | 976 | | |
0 commit comments