Skip to content

fix: reject uint64 values above MAX_SAFE_INTEGER in UintNumberType deserialization - #564

Merged
wemeetagain merged 2 commits into
masterfrom
nflaig/uint64-reject-unsafe-deserialize
Nov 20, 2026
Merged

wemeetagain merged 2 commits into
masterfrom
nflaig/uint64-reject-unsafe-deserialize

Conversation

@nflaig

@nflaig nflaig commented Nov 20, 2026

Copy link
Copy Markdown
Member

UintNumberType(8) decodes a uint64 into a Number, which rounds any value above Number.MAX_SAFE_INTEGER, so the decoded value no longer matches the encoded bytes. fromJson already throws for these values to prevent precision errors downstream, deserialization now does the same.

  • throw in value_deserializeFromBytes when the high 32 bits exceed 0x1fffff, tree_deserializeFromBytes and container decoding go through the same check
  • 2^64-1 still decodes to Infinity with clipInfinity
  • tests for MAX_SAFE_INTEGER round trips and for rejected values, directly and as container fields

…` deserialization

`UintNumberType(8)` decodes a uint64 into a `Number`, which rounds any value above `Number.MAX_SAFE_INTEGER`, so the decoded value no longer matches the encoded bytes. `fromJson` already throws for these values, deserialization now does the same. `2^64-1` still decodes to `Infinity` with `clipInfinity`.
@nflaig
nflaig requested a review from a team as a code owner November 20, 2026 10:36
nflaig added a commit to ChainSafe/lodestar that referenced this pull request Nov 20, 2026
The check now lives in `UintNumberType`, see ChainSafe/ssz#564. Validator identities type `activationEpoch` as `EpochInf` since a pending validator has `FAR_FUTURE_EPOCH`.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T10:37:31.496872Z 348f94f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: f5ed195 Previous: 73a3ced Ratio
digestTwoHashObjects 50023 times 33.998 ms/op 38.602 ms/op 0.88
digest2Bytes32 50023 times 38.794 ms/op 42.605 ms/op 0.91
digest 50023 times 38.324 ms/op 41.429 ms/op 0.93
input length 32 771.00 ns/op 906.00 ns/op 0.85
input length 64 938.00 ns/op 1.0290 us/op 0.91
input length 128 1.6690 us/op 1.7700 us/op 0.94
input length 256 2.5960 us/op 2.6370 us/op 0.98
input length 512 4.3710 us/op 4.3530 us/op 1.00
input length 1024 8.3900 us/op 8.3450 us/op 1.01
digest 1000000 times 587.28 ms/op 648.33 ms/op 0.91
hashObjectToByteArray 50023 times 977.70 us/op 980.61 us/op 1.00
byteArrayToHashObject 50023 times 1.2173 ms/op 1.0785 ms/op 1.13
digest64 200092 times 154.34 ms/op 166.22 ms/op 0.93
hash 200092 times using batchHash4UintArray64s 88.503 ms/op 181.66 ms/op 0.49
digest64HashObjects 200092 times 137.50 ms/op 153.88 ms/op 0.89
hash 200092 times using batchHash4HashObjectInputs 66.979 ms/op 163.11 ms/op 0.41
getGindicesAtDepth 2.8200 us/op 3.2790 us/op 0.86
iterateAtDepth 5.3850 us/op 5.8140 us/op 0.93
getGindexBits 299.00 ns/op 346.00 ns/op 0.86
gindexIterator 881.00 ns/op 780.00 ns/op 1.13
HashComputationLevel.push then loop 33.487 ms/op 25.839 ms/op 1.30
HashComputation[] push then loop 67.701 ms/op 41.370 ms/op 1.64
hash 2 32 bytes Uint8Array 500000 times - hashtree 122.98 ms/op 144.63 ms/op 0.85
batch hash 16 x 64 Uint8Array 31250 times - hashtree 36.746 ms/op 24.539 ms/op 1.50
hashTwoObjects 500000 times - hashtree 143.44 ms/op 169.37 ms/op 0.85
executeHashComputations - hashtree 9.2854 ms/op 6.8311 ms/op 1.36
hash 2 32 bytes Uint8Array 500000 times - as-sha256 338.94 ms/op 397.04 ms/op 0.85
batch hash 16 x 64 Uint8Array 31250 times - as-sha256 165.95 ms/op 410.82 ms/op 0.40
hashTwoObjects 500000 times - as-sha256 350.31 ms/op 406.40 ms/op 0.86
executeHashComputations - as-sha256 16.257 ms/op 36.367 ms/op 0.45
hash 2 32 bytes Uint8Array 500000 times - noble 1.1893 s/op 899.80 ms/op 1.32
batch hash 16 x 64 Uint8Array 31250 times - noble 1.2023 s/op 865.07 ms/op 1.39
hashTwoObjects 500000 times - noble 2.5242 s/op 1.3521 s/op 1.87
executeHashComputations - noble 30.615 ms/op 28.537 ms/op 1.07
getHashComputations 2.1918 ms/op 1.4024 ms/op 1.56
executeHashComputations 8.9683 ms/op 6.7177 ms/op 1.34
get root 12.440 ms/op 12.374 ms/op 1.01
getNodeH() x7812.5 avg hindex 13.847 us/op 12.210 us/op 1.13
getNodeH() x7812.5 index 0 4.4260 us/op 4.6900 us/op 0.94
getNodeH() x7812.5 index 7 4.4210 us/op 4.6850 us/op 0.94
getNodeH() x7812.5 index 7 with key array 4.4190 us/op 4.6850 us/op 0.94
new LeafNode() x7812.5 265.26 us/op 257.13 us/op 1.03
getHashComputations 250000 nodes 9.2709 ms/op 10.156 ms/op 0.91
batchHash 250000 nodes 72.000 ms/op 62.929 ms/op 1.14
get root 250000 nodes 84.641 ms/op 93.044 ms/op 0.91
getHashComputations 500000 nodes 16.282 ms/op 18.721 ms/op 0.87
batchHash 500000 nodes 162.96 ms/op 147.81 ms/op 1.10
get root 500000 nodes 166.74 ms/op 184.04 ms/op 0.91
getHashComputations 1000000 nodes 34.305 ms/op 40.250 ms/op 0.85
batchHash 1000000 nodes 288.81 ms/op 265.39 ms/op 1.09
get root 1000000 nodes 332.44 ms/op 372.63 ms/op 0.89
multiproof - depth 15, 1 requested leaves 6.3720 us/op 6.3780 us/op 1.00
tree offset multiproof - depth 15, 1 requested leaves 15.027 us/op 15.312 us/op 0.98
compact multiproof - depth 15, 1 requested leaves 2.6360 us/op 2.4280 us/op 1.09
multiproof - depth 15, 2 requested leaves 9.2850 us/op 9.7340 us/op 0.95
tree offset multiproof - depth 15, 2 requested leaves 17.570 us/op 18.246 us/op 0.96
compact multiproof - depth 15, 2 requested leaves 2.6780 us/op 2.4320 us/op 1.10
multiproof - depth 15, 3 requested leaves 13.300 us/op 14.034 us/op 0.95
tree offset multiproof - depth 15, 3 requested leaves 22.685 us/op 23.886 us/op 0.95
compact multiproof - depth 15, 3 requested leaves 2.9930 us/op 2.7200 us/op 1.10
multiproof - depth 15, 4 requested leaves 17.500 us/op 18.708 us/op 0.94
tree offset multiproof - depth 15, 4 requested leaves 28.159 us/op 29.608 us/op 0.95
compact multiproof - depth 15, 4 requested leaves 3.5200 us/op 3.1630 us/op 1.11
packedRootsBytesToLeafNodes bytes 4000 offset 0 4.3670 us/op 4.5520 us/op 0.96
packedRootsBytesToLeafNodes bytes 4000 offset 1 4.3730 us/op 4.5680 us/op 0.96
packedRootsBytesToLeafNodes bytes 4000 offset 2 4.4050 us/op 4.5620 us/op 0.97
packedRootsBytesToLeafNodes bytes 4000 offset 3 4.3920 us/op 4.5620 us/op 0.96
subtreeFillToContents depth 40 count 250000 17.632 ms/op 16.227 ms/op 1.09
setRoot - gindexBitstring 20.505 ms/op 17.996 ms/op 1.14
setRoot - gindex 21.410 ms/op 18.355 ms/op 1.17
getRoot - gindexBitstring 2.1307 ms/op 1.9508 ms/op 1.09
getRoot - gindex 2.9096 ms/op 2.5955 ms/op 1.12
getHashObject then setHashObject 22.633 ms/op 19.193 ms/op 1.18
setNodeWithFn 19.864 ms/op 17.578 ms/op 1.13
getNodeAtDepth depth 0 x100000 218.86 us/op 216.00 us/op 1.01
setNodeAtDepth depth 0 x100000 1.8147 ms/op 1.8137 ms/op 1.00
getNodesAtDepth depth 0 x100000 290.05 us/op 280.96 us/op 1.03
setNodesAtDepth depth 0 x100000 571.87 us/op 692.99 us/op 0.83
getNodeAtDepth depth 1 x100000 302.88 us/op 280.58 us/op 1.08
setNodeAtDepth depth 1 x100000 6.7340 ms/op 6.6033 ms/op 1.02
getNodesAtDepth depth 1 x100000 414.15 us/op 405.82 us/op 1.02
setNodesAtDepth depth 1 x100000 7.8420 ms/op 5.8601 ms/op 1.34
getNodeAtDepth depth 2 x100000 691.50 us/op 653.19 us/op 1.06
setNodeAtDepth depth 2 x100000 13.217 ms/op 13.000 ms/op 1.02
getNodesAtDepth depth 2 x100000 15.494 ms/op 16.765 ms/op 0.92
setNodesAtDepth depth 2 x100000 23.491 ms/op 22.105 ms/op 1.06
tree.getNodesAtDepth - gindexes 7.5461 ms/op 4.8792 ms/op 1.55
tree.getNodesAtDepth - push all nodes 1.4486 ms/op 1.0247 ms/op 1.41
tree.getNodesAtDepth - navigation 167.16 us/op 154.34 us/op 1.08
tree.setNodesAtDepth - indexes 598.74 us/op 584.31 us/op 1.02
set at depth 8 774.00 ns/op 648.00 ns/op 1.19
set at depth 16 1.0190 us/op 948.00 ns/op 1.07
set at depth 32 1.6610 us/op 1.5700 us/op 1.06
iterateNodesAtDepth 8 256 11.761 us/op 12.008 us/op 0.98
getNodesAtDepth 8 256 3.5380 us/op 3.1210 us/op 1.13
iterateNodesAtDepth 16 65536 3.6571 ms/op 3.7276 ms/op 0.98
getNodesAtDepth 16 65536 1.0557 ms/op 949.30 us/op 1.11
iterateNodesAtDepth 32 250000 14.083 ms/op 13.963 ms/op 1.01
getNodesAtDepth 32 250000 4.0124 ms/op 3.5932 ms/op 1.12
iterateNodesAtDepth 40 250000 14.217 ms/op 13.930 ms/op 1.02
getNodesAtDepth 40 250000 3.9945 ms/op 3.5646 ms/op 1.12
250000 validators root getter 86.065 ms/op 94.571 ms/op 0.91
250000 validators batchHash() 68.868 ms/op 58.153 ms/op 1.18
250000 validators hashComputations 8.9006 ms/op 9.7048 ms/op 0.92
bitlist bytes to struct (120,90) 351.00 ns/op 351.00 ns/op 1.00
bitlist bytes to tree (120,90) 1.7560 us/op 1.6580 us/op 1.06
bitlist bytes to struct (2048,2048) 613.00 ns/op 655.00 ns/op 0.94
bitlist bytes to tree (2048,2048) 2.6370 us/op 2.6750 us/op 0.99
ByteListType - deserialize 9.8640 ms/op 6.0915 ms/op 1.62
BasicListType - deserialize 10.226 ms/op 8.6125 ms/op 1.19
ByteListType - serialize 10.969 ms/op 7.3445 ms/op 1.49
BasicListType - serialize 16.265 ms/op 10.555 ms/op 1.54
BasicListType - tree_convertToStruct 25.662 ms/op 17.653 ms/op 1.45
List[uint8, 68719476736] len 300000 ViewDU.getAll() + iterate 3.1405 ms/op 3.9442 ms/op 0.80
List[uint8, 68719476736] len 300000 ViewDU.get(i) 2.7356 ms/op 3.9317 ms/op 0.70
Array.push len 300000 empty Array - number 4.9332 ms/op 4.0131 ms/op 1.23
Array.set len 300000 from new Array - number 1.2980 ms/op 935.54 us/op 1.39
Array.set len 300000 - number 5.0321 ms/op 3.9937 ms/op 1.26
Uint8Array.set len 300000 368.90 us/op 263.43 us/op 1.40
Uint32Array.set len 300000 736.62 us/op 637.16 us/op 1.16
Container({a: uint8, b: uint8}) getViewDU x300000 30.818 ms/op 34.245 ms/op 0.90
ContainerNodeStruct({a: uint8, b: uint8}) getViewDU x300000 10.466 ms/op 9.2335 ms/op 1.13
List(Container) len 300000 ViewDU.getAllReadonly() + iterate 105.51 ms/op 90.998 ms/op 1.16
List(Container) len 300000 ViewDU.getAllReadonlyValues() + iterate 429.04 ms/op 218.46 ms/op 1.96
List(Container) len 300000 ViewDU.get(i) 13.206 ms/op 7.4891 ms/op 1.76
List(Container) len 300000 ViewDU.getReadonly(i) 13.247 ms/op 7.3469 ms/op 1.80
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonly() + iterate 16.678 ms/op 14.681 ms/op 1.14
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonlyValues() + iterate 4.4546 ms/op 3.0898 ms/op 1.44
List(ContainerNodeStruct) len 300000 ViewDU.get(i) 10.897 ms/op 6.7795 ms/op 1.61
List(ContainerNodeStruct) len 300000 ViewDU.getReadonly(i) 10.642 ms/op 6.7596 ms/op 1.57
Array.push len 300000 empty Array - object 5.1172 ms/op 4.0797 ms/op 1.25
Array.set len 300000 from new Array - object 1.3457 ms/op 1.2048 ms/op 1.12
Array.set len 300000 - object 5.2466 ms/op 4.1853 ms/op 1.25
List 300 txs of 500 bytes Uint8Array[] deserialize 174.50 us/op 188.78 us/op 0.92
List 300 txs of 500 bytes SerializedList deserialize 106.33 us/op 114.24 us/op 0.93
List 300 txs of 500 bytes Uint8Array[] serialize 62.766 us/op 64.848 us/op 0.97
List 300 txs of 500 bytes SerializedList serialize 45.509 us/op 86.540 us/op 0.53
List 300 txs of 500 bytes Uint8Array[] hashTreeRoot 4.0994 ms/op 4.1963 ms/op 0.98
List 300 txs of 500 bytes SerializedList hashTreeRoot 4.0960 ms/op 4.1704 ms/op 0.98
List 1048576 empty txs Uint8Array[] deserialize 165.09 ms/op 139.12 ms/op 1.19
List 1048576 empty txs SerializedList deserialize 11.651 ms/op 12.162 ms/op 0.96
List 1048576 empty txs Uint8Array[] serialize 41.375 ms/op 41.793 ms/op 0.99
List 1048576 empty txs SerializedList serialize 1.4664 ms/op 761.52 us/op 1.93
List 1048576 empty txs Uint8Array[] hashTreeRoot 570.42 ms/op 598.86 ms/op 0.95
List 1048576 empty txs SerializedList hashTreeRoot 554.01 ms/op 589.68 ms/op 0.94
ProgressiveList 300 txs of 500 bytes Uint8Array[] deserialize 145.55 us/op 197.51 us/op 0.74
ProgressiveList 300 txs of 500 bytes SerializedList deserialize 77.387 us/op 98.719 us/op 0.78
ProgressiveList 300 txs of 500 bytes Uint8Array[] serialize 61.263 us/op 55.844 us/op 1.10
ProgressiveList 300 txs of 500 bytes SerializedList serialize 41.716 us/op 51.827 us/op 0.80
ProgressiveList 300 txs of 500 bytes Uint8Array[] hashTreeRoot 1.5199 ms/op 1.4565 ms/op 1.04
ProgressiveList 300 txs of 500 bytes SerializedList hashTreeRoot 1.5239 ms/op 1.4626 ms/op 1.04
ProgressiveList 1048576 empty txs Uint8Array[] deserialize 166.60 ms/op 141.29 ms/op 1.18
ProgressiveList 1048576 empty txs SerializedList deserialize 12.698 ms/op 14.681 ms/op 0.86
ProgressiveList 1048576 empty txs Uint8Array[] serialize 42.559 ms/op 37.454 ms/op 1.14
ProgressiveList 1048576 empty txs SerializedList serialize 1.2824 ms/op 730.73 us/op 1.75
ProgressiveList 1048576 empty txs Uint8Array[] hashTreeRoot 600.94 ms/op 639.01 ms/op 0.94
ProgressiveList 1048576 empty txs SerializedList hashTreeRoot 589.64 ms/op 650.97 ms/op 0.91
cachePermanentRootStruct no cache 2.4030 us/op 2.6930 us/op 0.89
cachePermanentRootStruct with cache 189.00 ns/op 162.00 ns/op 1.17
epochParticipation len 250000 rws 7813 2.3530 ms/op 2.2481 ms/op 1.05
Deneb BeaconBlock.hashTreeRoot(), numTransaction=200 3.9564 ms/op 4.1858 ms/op 0.95
BeaconState ViewDU batchHashTreeRoot vc=200000 mod=100000 234.16 ms/op 191.85 ms/op 1.22
BeaconState ViewDU batchHashTreeRoot - commit step vc=200000 mod=100000 195.18 ms/op 154.85 ms/op 1.26
BeaconState ViewDU batchHashTreeRoot - hash step vc=200000 mod=100000 41.943 ms/op 27.743 ms/op 1.51
BeaconState ViewDU hashTreeRoot() vc=200000 mod=100000 654.28 ms/op 633.25 ms/op 1.03
BeaconState ViewDU hashTreeRoot - commit step vc=200000 mod=100000 43.042 ms/op 51.020 ms/op 0.84
BeaconState ViewDU hashTreeRoot - validator tree creation vc=100000 mod=100000 276.73 ms/op 222.98 ms/op 1.24
sweep 16384 balances after clone + commit 21.343 ns/op 21.746 ns/op 0.98
deserialize Attestation - tree 3.0540 us/op 3.0510 us/op 1.00
deserialize Attestation - struct 1.6000 us/op 1.5900 us/op 1.01
deserialize Attestation - struct (reuse bytes) 1.1230 us/op 1.1480 us/op 0.98
deserialize SignedAggregateAndProof - tree 4.1670 us/op 4.2020 us/op 0.99
deserialize SignedAggregateAndProof - struct 4.1250 us/op 2.5440 us/op 1.62
deserialize SignedAggregateAndProof - struct (reuse bytes) 1.4380 us/op 1.5300 us/op 0.94
deserialize SyncCommitteeMessage - tree 1.1190 us/op 1.1500 us/op 0.97
deserialize SyncCommitteeMessage - struct 1.0500 us/op 944.00 ns/op 1.11
deserialize SyncCommitteeMessage - struct (reuse bytes) 614.00 ns/op 599.00 ns/op 1.03
deserialize SignedContributionAndProof - tree 2.4180 us/op 2.5720 us/op 0.94
deserialize SignedContributionAndProof - struct 1.9680 us/op 1.9560 us/op 1.01
deserialize SignedContributionAndProof - struct (reuse bytes) 1.0370 us/op 999.00 ns/op 1.04
deserialize SignedBeaconBlock - tree 237.21 us/op 234.80 us/op 1.01
deserialize SignedBeaconBlock - struct 220.63 us/op 105.25 us/op 2.10
deserialize SignedBeaconBlock - struct (reuse bytes) 63.842 us/op 64.447 us/op 0.99
BeaconState vc 300000 - deserialize tree 328.73 ms/op 316.09 ms/op 1.04
BeaconState vc 300000 - serialize tree 106.49 ms/op 97.728 ms/op 1.09
BeaconState.historicalRoots vc 300000 - deserialize tree 616.00 ns/op 594.00 ns/op 1.04
BeaconState.historicalRoots vc 300000 - serialize tree 551.00 ns/op 540.00 ns/op 1.02
BeaconState.validators vc 300000 - deserialize tree 306.84 ms/op 290.12 ms/op 1.06
BeaconState.validators vc 300000 - serialize tree 54.816 ms/op 44.034 ms/op 1.24
BeaconState.balances vc 300000 - deserialize tree 18.094 ms/op 7.9099 ms/op 2.29
BeaconState.balances vc 300000 - serialize tree 5.9944 ms/op 6.1967 ms/op 0.97
BeaconState.previousEpochParticipation vc 300000 - deserialize tree 711.67 us/op 689.74 us/op 1.03
BeaconState.previousEpochParticipation vc 300000 - serialize tree 598.00 us/op 507.68 us/op 1.18
BeaconState.currentEpochParticipation vc 300000 - deserialize tree 713.08 us/op 689.20 us/op 1.03
BeaconState.currentEpochParticipation vc 300000 - serialize tree 604.27 us/op 528.88 us/op 1.14
BeaconState.inactivityScores vc 300000 - deserialize tree 8.5168 ms/op 8.0445 ms/op 1.06
BeaconState.inactivityScores vc 300000 - serialize tree 6.4577 ms/op 5.2102 ms/op 1.24
hashTreeRoot Attestation - struct 7.1820 us/op 7.7900 us/op 0.92
hashTreeRoot Attestation - tree 6.5300 us/op 7.1630 us/op 0.91
hashTreeRoot SignedAggregateAndProof - struct 10.275 us/op 11.216 us/op 0.92
hashTreeRoot SignedAggregateAndProof - tree 9.7700 us/op 10.808 us/op 0.90
hashTreeRoot SyncCommitteeMessage - struct 2.4110 us/op 2.7340 us/op 0.88
hashTreeRoot SyncCommitteeMessage - tree 2.5360 us/op 2.6790 us/op 0.95
hashTreeRoot SignedContributionAndProof - struct 6.4610 us/op 6.7970 us/op 0.95
hashTreeRoot SignedContributionAndProof - tree 6.7750 us/op 7.4600 us/op 0.91
hashTreeRoot SignedBeaconBlock - struct 628.35 us/op 683.26 us/op 0.92
hashTreeRoot SignedBeaconBlock - tree 563.66 us/op 646.64 us/op 0.87
hashTreeRoot Validator - struct 3.2290 us/op 3.5870 us/op 0.90
hashTreeRoot Validator - tree 5.1490 us/op 5.3310 us/op 0.97
BeaconState vc 300000 - hashTreeRoot tree 1.8346 s/op 1.7360 s/op 1.06
BeaconState vc 300000 - batchHashTreeRoot tree 3.7221 s/op 3.2920 s/op 1.13
BeaconState.historicalRoots vc 300000 - hashTreeRoot tree 767.00 ns/op 840.00 ns/op 0.91
BeaconState.validators vc 300000 - hashTreeRoot tree 1.8414 s/op 1.7160 s/op 1.07
BeaconState.balances vc 300000 - hashTreeRoot tree 25.539 ms/op 27.978 ms/op 0.91
BeaconState.previousEpochParticipation vc 300000 - hashTreeRoot tree 3.0720 ms/op 3.4363 ms/op 0.89
BeaconState.currentEpochParticipation vc 300000 - hashTreeRoot tree 3.0512 ms/op 3.4314 ms/op 0.89
BeaconState.inactivityScores vc 300000 - hashTreeRoot tree 24.624 ms/op 27.947 ms/op 0.88
hash64 x18 5.3710 us/op 6.3280 us/op 0.85
hashTwoObjects x18 5.5020 us/op 6.2290 us/op 0.88
hash64 x1740 494.33 us/op 582.02 us/op 0.85
hashTwoObjects x1740 510.61 us/op 567.70 us/op 0.90
hash64 x2700000 792.72 ms/op 920.30 ms/op 0.86
hashTwoObjects x2700000 773.53 ms/op 886.90 ms/op 0.87
get_exitEpoch - ContainerType 143.00 ns/op 167.00 ns/op 0.86
get_exitEpoch - ContainerNodeStructType 146.00 ns/op 168.00 ns/op 0.87
set_exitEpoch - ContainerType 157.00 ns/op 186.00 ns/op 0.84
set_exitEpoch - ContainerNodeStructType 153.00 ns/op 183.00 ns/op 0.84
get_pubkey - ContainerType 788.00 ns/op 713.00 ns/op 1.11
get_pubkey - ContainerNodeStructType 141.00 ns/op 160.00 ns/op 0.88
hashTreeRoot - ContainerType 265.00 ns/op 295.00 ns/op 0.90
hashTreeRoot - ContainerNodeStructType 255.00 ns/op 286.00 ns/op 0.89
createProof - ContainerType 3.0780 us/op 2.9820 us/op 1.03
createProof - ContainerNodeStructType 16.996 us/op 17.063 us/op 1.00
serialize - ContainerType 1.2320 us/op 1.2900 us/op 0.96
serialize - ContainerNodeStructType 836.00 ns/op 889.00 ns/op 0.94
set_exitEpoch_and_hashTreeRoot - ContainerType 2.0530 us/op 2.1690 us/op 0.95
set_exitEpoch_and_hashTreeRoot - ContainerNodeStructType 5.7350 us/op 5.8540 us/op 0.98
doBatchHashTreeRootValidators 4.0070 us/op 3.3610 us/op 1.19
ContainerNodeStructViewDU hashTreeRoot 20.133 us/op 20.332 us/op 0.99
Array - for of 5.6550 us/op 6.5700 us/op 0.86
Array - for(;;) 3.8360 us/op 6.1660 us/op 0.62
basicListValue.readonlyValuesArray() 3.1075 ms/op 3.0591 ms/op 1.02
basicListValue.readonlyValuesArray() + loop all 4.0636 ms/op 3.7058 ms/op 1.10
compositeListValue.readonlyValuesArray() 11.132 ms/op 11.459 ms/op 0.97
compositeListValue.readonlyValuesArray() + loop all 13.414 ms/op 11.568 ms/op 1.16
Number64UintType - get balances list 2.6556 ms/op 2.6200 ms/op 1.01
Number64UintType - set balances list 9.2830 ms/op 9.9925 ms/op 0.93
Number64UintType - get and increase 10 then set 42.953 ms/op 26.032 ms/op 1.65
Number64UintType - increase 10 using applyDelta 14.021 ms/op 14.616 ms/op 0.96
Number64UintType - increase 10 using applyDeltaInBatch 14.061 ms/op 14.627 ms/op 0.96
tree_newTreeFromUint64Deltas 12.625 ms/op 11.820 ms/op 1.07
unsafeUint8ArrayToTree 20.999 ms/op 21.348 ms/op 0.98
bitLength(50) 153.00 ns/op 178.00 ns/op 0.86
bitLengthStr(50) 158.00 ns/op 184.00 ns/op 0.86
bitLength(8000) 147.00 ns/op 178.00 ns/op 0.83
bitLengthStr(8000) 208.00 ns/op 230.00 ns/op 0.90
bitLength(250000) 151.00 ns/op 179.00 ns/op 0.84
bitLengthStr(250000) 246.00 ns/op 263.00 ns/op 0.94
merkleize 32 chunks 9.6060 us/op 11.154 us/op 0.86
merkleizeBlocksBytes 32 chunks 3.3450 us/op 2.6240 us/op 1.27
merkleizeBlockArray 32 chunks 5.4690 us/op 4.8450 us/op 1.13
merkleize 128 chunks 37.600 us/op 43.234 us/op 0.87
merkleizeBlocksBytes 128 chunks 9.9040 us/op 6.6170 us/op 1.50
merkleizeBlockArray 128 chunks 17.093 us/op 14.165 us/op 1.21
merkleize 512 chunks 151.27 us/op 175.82 us/op 0.86
merkleizeBlocksBytes 512 chunks 34.882 us/op 21.380 us/op 1.63
merkleizeBlockArray 512 chunks 60.947 us/op 49.123 us/op 1.24
merkleize 1024 chunks 302.65 us/op 350.75 us/op 0.86
merkleizeBlocksBytes 1024 chunks 67.943 us/op 40.739 us/op 1.67
merkleizeBlockArray 1024 chunks 118.86 us/op 95.235 us/op 1.25
floor - Math.floor (53) 0.42043 ns/op 0.35010 ns/op 1.20
floor - << 0 (53) 0.42064 ns/op 0.35012 ns/op 1.20
floor - Math.floor (512) 0.42077 ns/op 0.35030 ns/op 1.20
floor - << 0 (512) 0.42047 ns/op 0.35027 ns/op 1.20
fnIf(0) 2.0165 ns/op 1.4985 ns/op 1.35
fnSwitch(0) 3.0257 ns/op 2.4890 ns/op 1.22
fnObj(0) 0.42041 ns/op 0.35019 ns/op 1.20
fnArr(0) 0.42081 ns/op 0.35023 ns/op 1.20
fnIf(4) 2.6892 ns/op 2.1775 ns/op 1.24
fnSwitch(4) 2.6891 ns/op 2.1763 ns/op 1.24
fnObj(4) 0.42041 ns/op 0.35018 ns/op 1.20
fnArr(4) 0.42052 ns/op 0.35017 ns/op 1.20
fnIf(9) 3.5292 ns/op 3.1096 ns/op 1.13
fnSwitch(9) 2.6892 ns/op 2.1775 ns/op 1.23
fnObj(9) 0.42050 ns/op 0.35028 ns/op 1.20
fnArr(9) 0.42056 ns/op 0.35027 ns/op 1.20
Container {a,b,vec} - as struct x100000 41.876 us/op 34.832 us/op 1.20
Container {a,b,vec} - as tree x100000 549.29 us/op 653.66 us/op 0.84
Container {a,vec,b} - as struct x100000 100.33 us/op 77.214 us/op 1.30
Container {a,vec,b} - as tree x100000 807.23 us/op 653.60 us/op 1.24
get 2 props x1000000 - rawObject 336.60 us/op 311.30 us/op 1.08
get 2 props x1000000 - proxy 90.213 ms/op 77.908 ms/op 1.16
get 2 props x1000000 - customObj 336.69 us/op 311.41 us/op 1.08
Simple object binary -> struct 382.00 ns/op 440.00 ns/op 0.87
Simple object binary -> tree_backed 983.00 ns/op 943.00 ns/op 1.04
Simple object struct -> tree_backed 1.4010 us/op 1.4140 us/op 0.99
Simple object tree_backed -> struct 1.2680 us/op 1.2250 us/op 1.04
Simple object struct -> binary 716.00 ns/op 696.00 ns/op 1.03
Simple object tree_backed -> binary 1.1430 us/op 1.0330 us/op 1.11
aggregationBits binary -> struct 373.00 ns/op 380.00 ns/op 0.98
aggregationBits binary -> tree_backed 1.8100 us/op 1.6800 us/op 1.08
aggregationBits struct -> tree_backed 3.6350 us/op 1.9260 us/op 1.89
aggregationBits tree_backed -> struct 902.00 ns/op 797.00 ns/op 1.13
aggregationBits struct -> binary 624.00 ns/op 574.00 ns/op 1.09
aggregationBits tree_backed -> binary 768.00 ns/op 693.00 ns/op 1.11
List(uint8) 100000 binary -> struct 742.09 us/op 701.25 us/op 1.06
List(uint8) 100000 binary -> tree_backed 231.81 us/op 228.81 us/op 1.01
List(uint8) 100000 struct -> tree_backed 1.3947 ms/op 1.4803 ms/op 0.94
List(uint8) 100000 tree_backed -> struct 835.76 us/op 782.12 us/op 1.07
List(uint8) 100000 struct -> binary 1.1268 ms/op 1.3504 ms/op 0.83
List(uint8) 100000 tree_backed -> binary 170.33 us/op 184.13 us/op 0.93
List(uint64Number) 100000 binary -> struct 976.57 us/op 1.0429 ms/op 0.94
List(uint64Number) 100000 binary -> tree_backed 1.9778 ms/op 1.9328 ms/op 1.02
List(uint64Number) 100000 struct -> tree_backed 3.6841 ms/op 3.6314 ms/op 1.01
List(uint64Number) 100000 tree_backed -> struct 1.8573 ms/op 1.8019 ms/op 1.03
List(uint64Number) 100000 struct -> binary 2.1564 ms/op 2.3970 ms/op 0.90
List(uint64Number) 100000 tree_backed -> binary 865.39 us/op 699.59 us/op 1.24
List(Uint64Bigint) 100000 binary -> struct 1.7149 ms/op 1.5488 ms/op 1.11
List(Uint64Bigint) 100000 binary -> tree_backed 1.9634 ms/op 1.9437 ms/op 1.01
List(Uint64Bigint) 100000 struct -> tree_backed 3.4119 ms/op 3.4722 ms/op 0.98
List(Uint64Bigint) 100000 tree_backed -> struct 2.7167 ms/op 2.3303 ms/op 1.17
List(Uint64Bigint) 100000 struct -> binary 1.8254 ms/op 2.3078 ms/op 0.79
List(Uint64Bigint) 100000 tree_backed -> binary 1.5861 ms/op 1.6580 ms/op 0.96
Vector(Root) 100000 binary -> struct 12.356 ms/op 10.641 ms/op 1.16
Vector(Root) 100000 binary -> tree_backed 22.060 ms/op 17.939 ms/op 1.23
Vector(Root) 100000 struct -> tree_backed 24.752 ms/op 21.693 ms/op 1.14
Vector(Root) 100000 tree_backed -> struct 15.054 ms/op 16.547 ms/op 0.91
Vector(Root) 100000 struct -> binary 4.6245 ms/op 6.1491 ms/op 0.75
Vector(Root) 100000 tree_backed -> binary 4.5673 ms/op 4.4983 ms/op 1.02
List(Validator) 100000 binary -> struct 70.494 ms/op 65.765 ms/op 1.07
List(Validator) 100000 binary -> tree_backed 217.06 ms/op 189.74 ms/op 1.14
List(Validator) 100000 struct -> tree_backed 240.63 ms/op 220.08 ms/op 1.09
List(Validator) 100000 tree_backed -> struct 136.12 ms/op 145.78 ms/op 0.93
List(Validator) 100000 struct -> binary 40.171 ms/op 46.343 ms/op 0.87
List(Validator) 100000 tree_backed -> binary 60.279 ms/op 76.893 ms/op 0.78
List(Validator-NS) 100000 binary -> struct 72.278 ms/op 67.246 ms/op 1.07
List(Validator-NS) 100000 binary -> tree_backed 103.70 ms/op 100.37 ms/op 1.03
List(Validator-NS) 100000 struct -> tree_backed 132.26 ms/op 113.05 ms/op 1.17
List(Validator-NS) 100000 tree_backed -> struct 106.32 ms/op 100.81 ms/op 1.05
List(Validator-NS) 100000 struct -> binary 14.323 ms/op 12.782 ms/op 1.12
List(Validator-NS) 100000 tree_backed -> binary 20.056 ms/op 13.907 ms/op 1.44
get epochStatuses - MutableVector 116.02 us/op 123.42 us/op 0.94
get epochStatuses - ViewDU 195.99 us/op 169.46 us/op 1.16
set epochStatuses - ListTreeView 2.0674 ms/op 4.9592 ms/op 0.42
set epochStatuses - ListTreeView - set() 545.21 us/op 480.89 us/op 1.13
set epochStatuses - ListTreeView - commit() 873.22 us/op 746.13 us/op 1.17
bitstring 467.10 ns/op 462.51 ns/op 1.01
bit mask 8.4095 ns/op 7.1873 ns/op 1.17
struct - increase slot to 1000000 393.87 us/op 350.24 us/op 1.12
UintNumberType - increase slot to 1000000 23.873 ms/op 31.790 ms/op 0.75
UintBigintType - increase slot to 1000000 201.37 ms/op 168.81 ms/op 1.19
UintBigint8 x 100000 tree_deserialize 6.5513 ms/op 5.1235 ms/op 1.28
UintBigint8 x 100000 tree_serialize 1.0776 ms/op 1.2457 ms/op 0.87
UintBigint16 x 100000 tree_deserialize 7.1598 ms/op 6.5435 ms/op 1.09
UintBigint16 x 100000 tree_serialize 1.1526 ms/op 1.2795 ms/op 0.90
UintBigint32 x 100000 tree_deserialize 6.5463 ms/op 5.0822 ms/op 1.29
UintBigint32 x 100000 tree_serialize 1.7661 ms/op 1.5992 ms/op 1.10
UintBigint64 x 100000 tree_deserialize 6.6937 ms/op 5.1618 ms/op 1.30
UintBigint64 x 100000 tree_serialize 1.7418 ms/op 1.5772 ms/op 1.10
UintBigint8 x 100000 value_deserialize 454.15 us/op 404.73 us/op 1.12
UintBigint8 x 100000 value_serialize 670.18 us/op 371.81 us/op 1.80
UintBigint16 x 100000 value_deserialize 502.24 us/op 467.08 us/op 1.08
UintBigint16 x 100000 value_serialize 695.45 us/op 362.17 us/op 1.92
UintBigint32 x 100000 value_deserialize 504.93 us/op 466.90 us/op 1.08
UintBigint32 x 100000 value_serialize 704.47 us/op 398.38 us/op 1.77
UintBigint64 x 100000 value_deserialize 579.29 us/op 529.14 us/op 1.09
UintBigint64 x 100000 value_serialize 820.61 us/op 521.64 us/op 1.57
UintBigint8 x 100000 deserialize 2.2341 ms/op 1.9236 ms/op 1.16
UintBigint8 x 100000 serialize 1.2670 ms/op 1.4920 ms/op 0.85
UintBigint16 x 100000 deserialize 2.2670 ms/op 1.9977 ms/op 1.13
UintBigint16 x 100000 serialize 1.3204 ms/op 1.5415 ms/op 0.86
UintBigint32 x 100000 deserialize 2.2693 ms/op 1.8894 ms/op 1.20
UintBigint32 x 100000 serialize 2.5102 ms/op 2.6960 ms/op 0.93
UintBigint64 x 100000 deserialize 2.2187 ms/op 1.9149 ms/op 1.16
UintBigint64 x 100000 serialize 1.0840 ms/op 1.2399 ms/op 0.87
UintBigint128 x 100000 deserialize 2.3051 ms/op 2.1905 ms/op 1.05
UintBigint128 x 100000 serialize 19.039 ms/op 11.840 ms/op 1.61
UintBigint256 x 100000 deserialize 3.3974 ms/op 3.0094 ms/op 1.13
UintBigint256 x 100000 serialize 34.646 ms/op 37.712 ms/op 0.92
Slice from Uint8Array x25000 1.1672 ms/op 935.35 us/op 1.25
Slice from ArrayBuffer x25000 27.129 ms/op 11.098 ms/op 2.44
Slice from ArrayBuffer x25000 + new Uint8Array 33.202 ms/op 17.981 ms/op 1.85
Copy Uint8Array 100000 iterate 1.0431 ms/op 826.98 us/op 1.26
Copy Uint8Array 100000 slice 216.28 us/op 176.42 us/op 1.23
Copy Uint8Array 100000 Uint8Array.prototype.slice.call 115.85 us/op 80.387 us/op 1.44
Copy Buffer 100000 Uint8Array.prototype.slice.call 120.31 us/op 80.689 us/op 1.49
Copy Uint8Array 100000 slice + set 259.56 us/op 156.29 us/op 1.66
Copy Uint8Array 100000 subarray + set 116.15 us/op 73.446 us/op 1.58
Copy Uint8Array 100000 slice arrayBuffer 116.96 us/op 73.286 us/op 1.60
Uint64 deserialize 100000 - iterate Uint8Array 1.3933 ms/op 1.2530 ms/op 1.11
Uint64 deserialize 100000 - by Uint32A 1.3096 ms/op 1.2463 ms/op 1.05
Uint64 deserialize 100000 - by DataView.getUint32 x2 1.3978 ms/op 1.4162 ms/op 0.99
Uint64 deserialize 100000 - by DataView.getBigUint64 3.3069 ms/op 3.6564 ms/op 0.90
Uint64 deserialize 100000 - by byte 13.217 ms/op 15.754 ms/op 0.84

by benchmarkbot/action

spiral-ladder
spiral-ladder previously approved these changes Nov 20, 2026
@erkancamli

Copy link
Copy Markdown

Follow-up from ChainSafe/lodestar#10688: on 348f94f the check covers deserialize and container fields, but not basic arrays deserialized to a tree. tree_deserializeFromBytesArrayBasic (arrayBasic.ts:145) packs the bytes straight into leaf nodes with packedRootsBytesToNode without decoding the elements, and reads then go through tree_getFromPackedNode, so the new check never runs. A probe test on this branch:

const U = new UintNumberType(8);
const S = new ContainerType({x: U, slashings: new VectorBasicType(U, 4), balances: new ListUintNum64Type(16), scores: new ListBasicType(U, 16)});
// bytes: 2^53 + 1 as the first element of each array
S.deserialize(bytes);                          // throws "Invalid serialized number > MAX_SAFE_INTEGER"
S.deserializeToViewDU(bytes).slashings.get(0); // 9007199254740992
S.deserializeToViewDU(bytes).balances.get(0);  // 9007199254740992
S.deserializeToViewDU(bytes).scores.get(0);    // 9007199254740992

In Lodestar these are Slashings, Balances and InactivityScores in the beacon state, which is loaded with deserializeToViewDU.

One option that leaves reads untouched: in tree_deserializeFromBytesArrayBasic, when the element type is an 8 byte UintNumberType, check the high 32 bits of each element (every 8 bytes, at offset 4) before packing, with the same clipInfinity exception. That is a single pass over the bytes at load time.

@nflaig

nflaig commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Thanks, reproduced. This is intended: the fix targets decoded values whose root no longer matches the bytes. Tree-backed packed arrays keep the original bytes, so their root stays exact.

A load-time check would also reject values above 2^53 that a Number holds exactly. For example, slashings entries are sums of effective balances (multiples of 10^9) and are read back exactly today, so a node could fail to load its own state after a large slashing event.

Clarified the doc comment in 80f19b8.

@wemeetagain
wemeetagain merged commit 930bac4 into master Nov 20, 2026
12 checks passed
@wemeetagain
wemeetagain deleted the nflaig/uint64-reject-unsafe-deserialize branch November 20, 2026 15:16
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
nflaig pushed a commit that referenced this pull request Nov 20, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>ssz: 1.9.1</summary>

##
[1.9.1](ssz-v1.9.0...ssz-v1.9.1)
(2026-11-20)


### Bug Fixes

* reject uint64 values above `MAX_SAFE_INTEGER` in `UintNumberType`
deserialization ([#564](#564))
([930bac4](930bac4))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
wemeetagain pushed a commit to ChainSafe/lodestar that referenced this pull request Nov 23, 2026
…ization (#10688)

Bumps `@chainsafe/ssz` to 1.9.1, which includes
ChainSafe/ssz#564 and makes `UintNumberType`
reject uint64 values above `Number.MAX_SAFE_INTEGER` on deserialization
instead of silently rounding them. Lodestar assumes `UintNum64` and
`UintNumInf64` fields never exceed that limit, the remaining changes
adapt to the stricter decoding.

- type `activationEpoch` of validator identities as `EpochInf`, a
pending validator has `FAR_FUTURE_EPOCH`
- run `invalid_large_withdrawable_epoch` as an expected decode error
instead of skipping it
- decode `merkle_proof` vector inputs with bigint types, as the test
already does for these vectors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants