-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconsensus_specs_test.go
847 lines (806 loc) · 37.3 KB
/
consensus_specs_test.go
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
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
847
// ssz: Go Simple Serialize (SSZ) codec library
// Copyright 2024 ssz Authors
// SPDX-License-Identifier: BSD-3-Clause
package tests
import (
"bytes"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"reflect"
"strings"
"sync"
"testing"
"github.com/golang/snappy"
"github.com/karalabe/ssz"
types "github.com/karalabe/ssz/tests/testtypes/consensus-spec-tests"
"gopkg.in/yaml.v3"
)
var (
// consensusSpecTestsBasicsRoot is the folder where the basic ssz tests are located.
consensusSpecTestsBasicsRoot = filepath.Join("testdata", "consensus-spec-tests", "tests", "general", "phase0", "ssz_generic", "containers")
// consensusSpecTestsRoot is the folder where the consensus ssz tests are located.
consensusSpecTestsRoot = filepath.Join("testdata", "consensus-spec-tests", "tests", "mainnet")
// consensusSpecTestsDone tracks which types have had their tests ran, so all the
// untested stuff can fail noisily.
consensusSpecTestsDone = make(map[string]map[string]struct{})
consensusSpecTestsLock sync.Mutex
)
// commonPrefix returns the common prefix in two byte slices.
func commonPrefix(a []byte, b []byte) []byte {
var prefix []byte
for len(a) > 0 && len(b) > 0 && a[0] == b[0] {
prefix = append(prefix, a[0])
a, b = a[1:], b[1:]
}
return prefix
}
// TestConsensusSpecBasics iterates over the basic container tests from the
// consensus spec tests repo and runs the encoding/decoding/hashing round.
func TestConsensusSpecBasics(t *testing.T) {
// Run through all the basic tests as simple types
testConsensusSpecBasicType[*types.SingleFieldTestStruct](t, "SingleFieldTestStruct")
testConsensusSpecBasicType[*types.SmallTestStruct](t, "SmallTestStruct")
testConsensusSpecBasicType[*types.FixedTestStruct](t, "FixedTestStruct")
testConsensusSpecBasicType[*types.BitsStruct](t, "BitsStruct")
// Add monolith variations to the basic types
testConsensusSpecBasicType[*types.SingleFieldTestStructMonolith](t, "SingleFieldTestStruct")
testConsensusSpecBasicType[*types.SmallTestStructMonolith](t, "SmallTestStruct")
testConsensusSpecBasicType[*types.FixedTestStructMonolith](t, "FixedTestStruct")
testConsensusSpecBasicType[*types.BitsStructMonolith](t, "BitsStruct")
}
func testConsensusSpecBasicType[T newableObject[U], U any](t *testing.T, kind string) {
// Sanity check that the zero values can be handled before diving into the
// actual test datasets. This is mostly to catch implementation faults with
// uninitialized field handling.
t.Run(fmt.Sprintf("zero/%s", kind), func(t *testing.T) {
testZeroValue[T, U](t, ssz.ForkUnknown)
})
// Filter out the valid tests for this specific type
path := filepath.Join(consensusSpecTestsBasicsRoot, "valid")
tests, err := os.ReadDir(path)
if err != nil {
t.Errorf("failed to walk valid test collection %v: %v", path, err)
return
}
for i := 0; i < len(tests); i++ {
if !strings.HasPrefix(tests[i].Name(), kind+"_") {
tests = append(tests[:i], tests[i+1:]...)
i--
}
}
// Run all the valid tests
for _, test := range tests {
t.Run(fmt.Sprintf("valid/%s/%s", kind, test.Name()), func(t *testing.T) {
// Parse the input SSZ data and the expected root for the test
inSnappy, err := os.ReadFile(filepath.Join(path, test.Name(), "serialized.ssz_snappy"))
if err != nil {
t.Fatalf("failed to load snapy ssz binary: %v", err)
}
inSSZ, err := snappy.Decode(nil, inSnappy)
if err != nil {
t.Fatalf("failed to parse snappy ssz binary: %v", err)
}
inYAML, err := os.ReadFile(filepath.Join(path, test.Name(), "meta.yaml"))
if err != nil {
t.Fatalf("failed to load yaml root: %v", err)
}
inRoot := struct {
Root string `yaml:"root"`
}{}
if err = yaml.Unmarshal(inYAML, &inRoot); err != nil {
t.Fatalf("failed to parse yaml root: %v", err)
}
// Do a decode/encode round. Would be nicer to parse out the value
// from yaml and check that too, but hex-in-yaml makes everything
// beyond annoying. C'est la vie.
obj := T(new(U))
if err := ssz.DecodeFromStream(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ))); err != nil {
t.Fatalf("failed to decode SSZ stream: %v", err)
}
blob := new(bytes.Buffer)
if err := ssz.EncodeToStream(blob, obj); err != nil {
t.Fatalf("failed to re-encode SSZ stream: %v", err)
}
if !bytes.Equal(blob.Bytes(), inSSZ) {
prefix := commonPrefix(blob.Bytes(), inSSZ)
t.Fatalf("re-encoded stream mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), blob.Bytes()[len(prefix):], inSSZ[len(prefix):])
}
obj = T(new(U))
if err := ssz.DecodeFromBytes(inSSZ, obj); err != nil {
t.Fatalf("failed to decode SSZ buffer: %v", err)
}
bin := make([]byte, ssz.Size(obj))
if err := ssz.EncodeToBytes(bin, obj); err != nil {
t.Fatalf("failed to re-encode SSZ buffer: %v", err)
}
if !bytes.Equal(bin, inSSZ) {
prefix := commonPrefix(bin, inSSZ)
t.Fatalf("re-encoded bytes mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
}
// Encoder/decoder seems to work, check if the size reported by the
// encoded object actually matches the encoded stream
if size := ssz.Size(obj); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
hash := ssz.HashSequential(obj)
if fmt.Sprintf("%#x", hash) != inRoot.Root {
t.Fatalf("sequential merkle root mismatch: have %#x, want %s", hash, inRoot.Root)
}
hash = ssz.HashConcurrent(obj)
if fmt.Sprintf("%#x", hash) != inRoot.Root {
t.Fatalf("concurrent merkle root mismatch: have %#x, want %s", hash, inRoot.Root)
}
})
}
// Filter out the valid tests for this specific type
path = filepath.Join(consensusSpecTestsBasicsRoot, "invalid")
tests, err = os.ReadDir(path)
if err != nil {
t.Errorf("failed to walk invalid test collection %v: %v", path, err)
return
}
for i := 0; i < len(tests); i++ {
if !strings.HasPrefix(tests[i].Name(), kind+"_") {
tests = append(tests[:i], tests[i+1:]...)
i--
}
}
// Run all the valid tests
for _, test := range tests {
t.Run(fmt.Sprintf("invalid/%s/%s", kind, test.Name()), func(t *testing.T) {
// Parse the input SSZ data and the expected root for the test
inSnappy, err := os.ReadFile(filepath.Join(path, test.Name(), "serialized.ssz_snappy"))
if err != nil {
t.Fatalf("failed to load snapy ssz binary: %v", err)
}
inSSZ, err := snappy.Decode(nil, inSnappy)
if err != nil {
t.Fatalf("failed to parse snappy ssz binary: %v", err)
}
// Try to decode, it should fail
obj := T(new(U))
if err := ssz.DecodeFromStream(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ))); err == nil {
t.Fatalf("succeeded in decoding invalid SSZ stream")
}
obj = T(new(U))
if err := ssz.DecodeFromBytes(inSSZ, obj); err == nil {
t.Fatalf("succeeded in decoding invalid SSZ buffer")
}
})
}
}
// TestConsensusSpecs iterates over all the (supported) consensus SSZ types and
// runs the encoding/decoding/hashing round.
func TestConsensusSpecs(t *testing.T) {
// Run through all the consensus specs as simple types
testConsensusSpecType[*types.AggregateAndProof](t, "AggregateAndProof", "altair", "bellatrix", "capella", "deneb", "eip7594", "phase0", "whisk")
testConsensusSpecType[*types.Attestation](t, "Attestation", "altair", "bellatrix", "capella", "deneb", "eip7594", "phase0", "whisk")
testConsensusSpecType[*types.AttestationData](t, "AttestationData")
testConsensusSpecType[*types.AttesterSlashing](t, "AttesterSlashing", "phase0", "altair", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.BeaconBlock](t, "BeaconBlock", "phase0")
testConsensusSpecType[*types.BeaconBlockBody](t, "BeaconBlockBody", "phase0")
testConsensusSpecType[*types.BeaconBlockBodyAltair](t, "BeaconBlockBody", "altair")
testConsensusSpecType[*types.BeaconBlockBodyBellatrix](t, "BeaconBlockBody", "bellatrix")
testConsensusSpecType[*types.BeaconBlockBodyCapella](t, "BeaconBlockBody", "capella")
testConsensusSpecType[*types.BeaconBlockBodyDeneb](t, "BeaconBlockBody", "deneb", "eip7594")
testConsensusSpecType[*types.BeaconBlockHeader](t, "BeaconBlockHeader")
testConsensusSpecType[*types.BeaconState](t, "BeaconState", "phase0")
testConsensusSpecType[*types.BeaconStateAltair](t, "BeaconState", "altair")
testConsensusSpecType[*types.BeaconStateCapella](t, "BeaconState", "capella")
testConsensusSpecType[*types.BeaconStateDeneb](t, "BeaconState", "deneb")
testConsensusSpecType[*types.BLSToExecutionChange](t, "BLSToExecutionChange")
testConsensusSpecType[*types.Checkpoint](t, "Checkpoint")
testConsensusSpecType[*types.Deposit](t, "Deposit")
testConsensusSpecType[*types.DepositData](t, "DepositData")
testConsensusSpecType[*types.DepositMessage](t, "DepositMessage")
testConsensusSpecType[*types.Eth1Block](t, "Eth1Block")
testConsensusSpecType[*types.Eth1Data](t, "Eth1Data")
testConsensusSpecType[*types.ExecutionPayload](t, "ExecutionPayload", "bellatrix")
testConsensusSpecType[*types.ExecutionPayloadHeader](t, "ExecutionPayloadHeader", "bellatrix")
testConsensusSpecType[*types.ExecutionPayloadCapella](t, "ExecutionPayload", "capella")
testConsensusSpecType[*types.ExecutionPayloadHeaderCapella](t, "ExecutionPayloadHeader", "capella")
testConsensusSpecType[*types.ExecutionPayloadDeneb](t, "ExecutionPayload", "deneb", "eip7594")
testConsensusSpecType[*types.ExecutionPayloadHeaderDeneb](t, "ExecutionPayloadHeader", "deneb", "eip7594")
testConsensusSpecType[*types.Fork](t, "Fork")
testConsensusSpecType[*types.HistoricalBatch](t, "HistoricalBatch")
testConsensusSpecType[*types.HistoricalSummary](t, "HistoricalSummary")
testConsensusSpecType[*types.IndexedAttestation](t, "IndexedAttestation", "phase0", "altair", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.PendingAttestation](t, "PendingAttestation")
testConsensusSpecType[*types.ProposerSlashing](t, "ProposerSlashing")
testConsensusSpecType[*types.SignedBeaconBlockHeader](t, "SignedBeaconBlockHeader")
testConsensusSpecType[*types.SignedBLSToExecutionChange](t, "SignedBLSToExecutionChange")
testConsensusSpecType[*types.SignedVoluntaryExit](t, "SignedVoluntaryExit")
testConsensusSpecType[*types.SyncAggregate](t, "SyncAggregate")
testConsensusSpecType[*types.SyncCommittee](t, "SyncCommittee")
testConsensusSpecType[*types.Validator](t, "Validator")
testConsensusSpecType[*types.VoluntaryExit](t, "VoluntaryExit")
testConsensusSpecType[*types.Withdrawal](t, "Withdrawal")
// Add monolith variations to the consensus types
testConsensusSpecType[*types.BeaconBlockBodyMonolith](t, "BeaconBlockBody", "phase0", "altair", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.BeaconStateMonolith](t, "BeaconState", "phase0", "altair", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.ExecutionPayloadMonolith](t, "ExecutionPayload", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.ExecutionPayloadMonolith2](t, "ExecutionPayload", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.ExecutionPayloadHeaderMonolith](t, "ExecutionPayloadHeader", "bellatrix", "capella", "deneb")
testConsensusSpecType[*types.ValidatorMonolith](t, "Validator")
// Add some API variations to test different codec implementations
testConsensusSpecType[*types.ExecutionPayloadVariation](t, "ExecutionPayload", "bellatrix")
testConsensusSpecType[*types.HistoricalBatchVariation](t, "HistoricalBatch")
testConsensusSpecType[*types.WithdrawalVariation](t, "Withdrawal")
testConsensusSpecType[*types.AttestationVariation1](t, "Attestation", "altair", "bellatrix", "capella", "deneb", "eip7594", "phase0", "whisk")
testConsensusSpecType[*types.AttestationVariation2](t, "Attestation", "altair", "bellatrix", "capella", "deneb", "eip7594", "phase0", "whisk")
testConsensusSpecType[*types.AttestationVariation3](t, "Attestation", "altair", "bellatrix", "capella", "deneb", "eip7594", "phase0", "whisk")
testConsensusSpecType[*types.AttestationDataVariation1](t, "AttestationData")
testConsensusSpecType[*types.AttestationDataVariation2](t, "AttestationData")
testConsensusSpecType[*types.AttestationDataVariation3](t, "AttestationData")
// Iterate over all the untouched tests and report them
// forks, err := os.ReadDir(consensusSpecTestsRoot)
// if err != nil {
// t.Fatalf("failed to walk fork collection: %v", err)
// }
// for _, fork := range forks {
// if _, ok := consensusSpecTestsDone[fork.Name()]; !ok {
// t.Errorf("no tests ran for %v", fork.Name())
// continue
// }
// types, err := os.ReadDir(filepath.Join(consensusSpecTestsRoot, fork.Name(), "ssz_static"))
// if err != nil {
// t.Fatalf("failed to walk type collection of %v: %v", fork, err)
// }
// for _, kind := range types {
// if _, ok := consensusSpecTestsDone[fork.Name()][kind.Name()]; !ok {
// t.Errorf("no tests ran for %v/%v", fork.Name(), kind.Name())
// }
// }
// }
}
// newableObject is a generic type whose purpose is to enforce that ssz.Object
// is specifically implemented on a struct pointer. That's needed to allow us
// to instantiate new structs via `new` when parsing.
type newableObject[U any] interface {
ssz.Object
*U
}
func testConsensusSpecType[T newableObject[U], U any](t *testing.T, kind string, forks ...string) {
// If no fork was specified, iterate over all of them and use the same type
if len(forks) == 0 {
forks, err := os.ReadDir(consensusSpecTestsRoot)
if err != nil {
t.Errorf("failed to walk spec collection %v: %v", consensusSpecTestsRoot, err)
return
}
for _, fork := range forks {
if _, err := os.Stat(filepath.Join(consensusSpecTestsRoot, fork.Name(), "ssz_static", kind, "ssz_random")); err == nil {
testConsensusSpecType[T, U](t, kind, fork.Name())
}
}
return
}
// Some specific fork was requested, look that up explicitly
for _, fork := range forks {
// Sanity check that the zero values can be handled before diving into the
// actual test datasets. This is mostly to catch implementation faults with
// uninitialized field handling.
t.Run(fmt.Sprintf("zero/%s/%s", fork, kind), func(t *testing.T) {
testZeroValue[T, U](t, ssz.ForkMapping[fork])
})
// Zero value on this specific fork ok, pull in the consensus dataset
path := filepath.Join(consensusSpecTestsRoot, fork, "ssz_static", kind, "ssz_random")
tests, err := os.ReadDir(path)
if err != nil {
t.Errorf("failed to walk test collection %v: %v", path, err)
return
}
// Track this test suite done, whether succeeds of fails is irrelevant
consensusSpecTestsLock.Lock()
if _, ok := consensusSpecTestsDone[fork]; !ok {
consensusSpecTestsDone[fork] = make(map[string]struct{})
}
consensusSpecTestsDone[fork][kind] = struct{}{}
consensusSpecTestsLock.Unlock()
// Run all the subtests found in the folder
for _, test := range tests {
t.Run(fmt.Sprintf("%s/%s/%s", fork, reflect.TypeFor[U]().Name(), test.Name()), func(t *testing.T) {
// Parse the input SSZ data and the expected root for the test
inSnappy, err := os.ReadFile(filepath.Join(path, test.Name(), "serialized.ssz_snappy"))
if err != nil {
t.Fatalf("failed to load snapy ssz binary: %v", err)
}
inSSZ, err := snappy.Decode(nil, inSnappy)
if err != nil {
t.Fatalf("failed to parse snappy ssz binary: %v", err)
}
inYAML, err := os.ReadFile(filepath.Join(path, test.Name(), "roots.yaml"))
if err != nil {
t.Fatalf("failed to load yaml root: %v", err)
}
inRoot := struct {
Root string `yaml:"root"`
}{}
if err = yaml.Unmarshal(inYAML, &inRoot); err != nil {
t.Fatalf("failed to parse yaml root: %v", err)
}
// Do a decode/encode round. Would be nicer to parse out the value
// from yaml and check that too, but hex-in-yaml makes everything
// beyond annoying. C'est la vie.
obj := T(new(U))
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ)), ssz.ForkMapping[fork]); err != nil {
t.Fatalf("failed to decode SSZ stream: %v", err)
}
blob := new(bytes.Buffer)
if err := ssz.EncodeToStreamOnFork(blob, obj, ssz.ForkMapping[fork]); err != nil {
t.Fatalf("failed to re-encode SSZ stream: %v", err)
}
if !bytes.Equal(blob.Bytes(), inSSZ) {
prefix := commonPrefix(blob.Bytes(), inSSZ)
t.Fatalf("re-encoded stream mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), blob.Bytes()[len(prefix):], inSSZ[len(prefix):])
}
obj = T(new(U))
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkMapping[fork]); err != nil {
t.Fatalf("failed to decode SSZ buffer: %v", err)
}
bin := make([]byte, ssz.SizeOnFork(obj, ssz.ForkMapping[fork]))
if err := ssz.EncodeToBytesOnFork(bin, obj, ssz.ForkMapping[fork]); err != nil {
t.Fatalf("failed to re-encode SSZ buffer: %v", err)
}
if !bytes.Equal(bin, inSSZ) {
prefix := commonPrefix(bin, inSSZ)
t.Fatalf("re-encoded bytes mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
}
// Encoder/decoder seems to work, check if the size reported by the
// encoded object actually matches the encoded stream
if size := ssz.SizeOnFork(obj, ssz.ForkMapping[fork]); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
hash := ssz.HashSequentialOnFork(obj, ssz.ForkMapping[fork])
if fmt.Sprintf("%#x", hash) != inRoot.Root {
t.Fatalf("sequential merkle root mismatch: have %#x, want %s", hash, inRoot.Root)
}
hash = ssz.HashConcurrentOnFork(obj, ssz.ForkMapping[fork])
if fmt.Sprintf("%#x", hash) != inRoot.Root {
t.Fatalf("concurrent merkle root mismatch: have %#x, want %s", hash, inRoot.Root)
}
})
}
}
}
// BenchmarkConsensusSpecs iterates over all the (supported) consensus SSZ types and
// runs the encoding/decoding/hashing benchmark round.
func BenchmarkConsensusSpecs(b *testing.B) {
benchmarkConsensusSpecType[*types.AggregateAndProof](b, "deneb", "AggregateAndProof")
benchmarkConsensusSpecType[*types.Attestation](b, "deneb", "Attestation")
benchmarkConsensusSpecType[*types.AttestationData](b, "deneb", "AttestationData")
benchmarkConsensusSpecType[*types.AttesterSlashing](b, "deneb", "AttesterSlashing")
benchmarkConsensusSpecType[*types.BeaconBlock](b, "phase0", "BeaconBlock")
benchmarkConsensusSpecType[*types.BeaconBlockBodyDeneb](b, "deneb", "BeaconBlockBody")
benchmarkConsensusSpecType[*types.BeaconBlockBodyMonolith](b, "deneb", "BeaconBlockBody")
benchmarkConsensusSpecType[*types.BeaconBlockHeader](b, "deneb", "BeaconBlockHeader")
benchmarkConsensusSpecType[*types.BeaconStateDeneb](b, "deneb", "BeaconState")
benchmarkConsensusSpecType[*types.BeaconStateMonolith](b, "deneb", "BeaconState")
benchmarkConsensusSpecType[*types.BLSToExecutionChange](b, "deneb", "BLSToExecutionChange")
benchmarkConsensusSpecType[*types.Checkpoint](b, "deneb", "Checkpoint")
benchmarkConsensusSpecType[*types.Deposit](b, "deneb", "Deposit")
benchmarkConsensusSpecType[*types.DepositData](b, "deneb", "DepositData")
benchmarkConsensusSpecType[*types.DepositMessage](b, "deneb", "DepositMessage")
benchmarkConsensusSpecType[*types.Eth1Block](b, "deneb", "Eth1Block")
benchmarkConsensusSpecType[*types.Eth1Data](b, "deneb", "Eth1Data")
benchmarkConsensusSpecType[*types.ExecutionPayloadDeneb](b, "deneb", "ExecutionPayload")
benchmarkConsensusSpecType[*types.ExecutionPayloadMonolith](b, "deneb", "ExecutionPayload")
benchmarkConsensusSpecType[*types.ExecutionPayloadHeaderDeneb](b, "deneb", "ExecutionPayloadHeader")
benchmarkConsensusSpecType[*types.ExecutionPayloadHeaderMonolith](b, "deneb", "ExecutionPayloadHeader")
benchmarkConsensusSpecType[*types.Fork](b, "deneb", "Fork")
benchmarkConsensusSpecType[*types.HistoricalBatch](b, "deneb", "HistoricalBatch")
benchmarkConsensusSpecType[*types.HistoricalSummary](b, "deneb", "HistoricalSummary")
benchmarkConsensusSpecType[*types.IndexedAttestation](b, "deneb", "IndexedAttestation")
benchmarkConsensusSpecType[*types.PendingAttestation](b, "deneb", "PendingAttestation")
benchmarkConsensusSpecType[*types.ProposerSlashing](b, "deneb", "ProposerSlashing")
benchmarkConsensusSpecType[*types.SignedBeaconBlockHeader](b, "deneb", "SignedBeaconBlockHeader")
benchmarkConsensusSpecType[*types.SignedBLSToExecutionChange](b, "deneb", "SignedBLSToExecutionChange")
benchmarkConsensusSpecType[*types.SignedVoluntaryExit](b, "deneb", "SignedVoluntaryExit")
benchmarkConsensusSpecType[*types.SyncAggregate](b, "deneb", "SyncAggregate")
benchmarkConsensusSpecType[*types.SyncCommittee](b, "deneb", "SyncCommittee")
benchmarkConsensusSpecType[*types.Validator](b, "deneb", "Validator")
benchmarkConsensusSpecType[*types.VoluntaryExit](b, "deneb", "VoluntaryExit")
benchmarkConsensusSpecType[*types.Withdrawal](b, "deneb", "Withdrawal")
}
func benchmarkConsensusSpecType[T newableObject[U], U any](b *testing.B, fork, kind string) {
path := filepath.Join(consensusSpecTestsRoot, fork, "ssz_static", kind, "ssz_random", "case_4")
// Parse the input SSZ data for this specific dataset and decode it
inSnappy, err := os.ReadFile(filepath.Join(path, "serialized.ssz_snappy"))
if err != nil {
b.Fatalf("failed to load snapy ssz binary: %v", err)
}
inSSZ, err := snappy.Decode(nil, inSnappy)
if err != nil {
b.Fatalf("failed to parse snappy ssz binary: %v", err)
}
inObj := T(new(U))
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), inObj, uint32(len(inSSZ)), ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to decode SSZ stream: %v", err)
}
// Start the benchmarks for all the different operations
b.Run(fmt.Sprintf("%s/encode-stream", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := ssz.EncodeToStreamOnFork(io.Discard, inObj, ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to encode SSZ stream: %v", err)
}
}
})
b.Run(fmt.Sprintf("%s/encode-buffer", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
blob := make([]byte, len(inSSZ))
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := ssz.EncodeToBytesOnFork(blob, inObj, ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to encode SSZ bytes: %v", err)
}
}
})
b.Run(fmt.Sprintf("%s/decode-stream", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
obj := T(new(U))
r := bytes.NewReader(inSSZ)
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := ssz.DecodeFromStreamOnFork(r, obj, uint32(len(inSSZ)), ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to decode SSZ stream: %v", err)
}
r.Reset(inSSZ)
}
})
b.Run(fmt.Sprintf("%s/decode-buffer", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
obj := T(new(U))
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to decode SSZ stream: %v", err)
}
}
})
b.Run(fmt.Sprintf("%s/merkleize-sequential", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
obj := T(new(U))
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to decode SSZ stream: %v", err)
}
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ssz.HashSequentialOnFork(obj, ssz.ForkMapping[fork])
}
})
b.Run(fmt.Sprintf("%s/merkleize-concurrent", reflect.TypeOf(inObj).Elem().Name()), func(b *testing.B) {
obj := T(new(U))
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkMapping[fork]); err != nil {
b.Fatalf("failed to decode SSZ stream: %v", err)
}
b.SetBytes(int64(len(inSSZ)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
ssz.HashConcurrentOnFork(obj, ssz.ForkMapping[fork])
}
})
}
// Various fuzz targets can be found below, one for each consensus spec type. The
// methods will start by feeding all the consensus spec test data and then will do
// infinite decoding runs. Anything that succeeds will get re-encoded, re-decoded,
// etc. to test different functions.
func FuzzConsensusSpecsAggregateAndProof(f *testing.F) {
fuzzConsensusSpecType[*types.AggregateAndProof](f, "AggregateAndProof")
}
func FuzzConsensusSpecsAttestation(f *testing.F) {
fuzzConsensusSpecType[*types.Attestation](f, "Attestation")
}
func FuzzConsensusSpecsAttestationData(f *testing.F) {
fuzzConsensusSpecType[*types.AttestationData](f, "AttestationData")
}
func FuzzConsensusSpecsAttesterSlashing(f *testing.F) {
fuzzConsensusSpecType[*types.AttesterSlashing](f, "AttesterSlashing")
}
func FuzzConsensusSpecsBeaconBlock(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlock](f, "BeaconBlock")
}
func FuzzConsensusSpecsBeaconBlockBody(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBody](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconBlockBodyAltair(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBodyAltair](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconBlockBodyBellatrix(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBodyBellatrix](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconBlockBodyCapella(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBodyCapella](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconBlockBodyDeneb(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBodyDeneb](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconBlockHeader(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockHeader](f, "BeaconBlockHeader")
}
func FuzzConsensusSpecsBeaconState(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconState](f, "BeaconState")
}
func FuzzConsensusSpecsBeaconStateAltair(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconStateAltair](f, "BeaconState")
}
func FuzzConsensusSpecsBeaconStateBellatrix(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconStateBellatrix](f, "BeaconState")
}
func FuzzConsensusSpecsBeaconStateCapella(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconStateCapella](f, "BeaconState")
}
func FuzzConsensusSpecsBeaconStateDeneb(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconStateDeneb](f, "BeaconState")
}
func FuzzConsensusSpecsBLSToExecutionChange(f *testing.F) {
fuzzConsensusSpecType[*types.BLSToExecutionChange](f, "BLSToExecutionChange")
}
func FuzzConsensusSpecsCheckpoint(f *testing.F) {
fuzzConsensusSpecType[*types.Checkpoint](f, "Checkpoint")
}
func FuzzConsensusSpecsDeposit(f *testing.F) {
fuzzConsensusSpecType[*types.Deposit](f, "Deposit")
}
func FuzzConsensusSpecsDepositData(f *testing.F) {
fuzzConsensusSpecType[*types.DepositData](f, "DepositData")
}
func FuzzConsensusSpecsDepositMessage(f *testing.F) {
fuzzConsensusSpecType[*types.DepositMessage](f, "DepositMessage")
}
func FuzzConsensusSpecsEth1Block(f *testing.F) {
fuzzConsensusSpecType[*types.Eth1Block](f, "Eth1Block")
}
func FuzzConsensusSpecsEth1Data(f *testing.F) {
fuzzConsensusSpecType[*types.Eth1Data](f, "Eth1Data")
}
func FuzzConsensusSpecsExecutionPayload(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayload](f, "ExecutionPayload")
}
func FuzzConsensusSpecsExecutionPayloadCapella(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadCapella](f, "ExecutionPayload")
}
func FuzzConsensusSpecsExecutionPayloadDeneb(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadDeneb](f, "ExecutionPayload")
}
func FuzzConsensusSpecsExecutionPayloadHeader(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadHeader](f, "ExecutionPayloadHeader")
}
func FuzzConsensusSpecsExecutionPayloadHeaderCapella(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadHeaderCapella](f, "ExecutionPayloadHeader")
}
func FuzzConsensusSpecsExecutionPayloadHeaderDeneb(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadHeaderDeneb](f, "ExecutionPayloadHeader")
}
func FuzzConsensusSpecsFork(f *testing.F) {
fuzzConsensusSpecType[*types.Fork](f, "Fork")
}
func FuzzConsensusSpecsHistoricalBatch(f *testing.F) {
fuzzConsensusSpecType[*types.HistoricalBatch](f, "HistoricalBatch")
}
func FuzzConsensusSpecsHistoricalSummary(f *testing.F) {
fuzzConsensusSpecType[*types.HistoricalSummary](f, "HistoricalSummary")
}
func FuzzConsensusSpecsIndexedAttestation(f *testing.F) {
fuzzConsensusSpecType[*types.IndexedAttestation](f, "IndexedAttestation")
}
func FuzzConsensusSpecsPendingAttestation(f *testing.F) {
fuzzConsensusSpecType[*types.PendingAttestation](f, "PendingAttestation")
}
func FuzzConsensusSpecsProposerSlashing(f *testing.F) {
fuzzConsensusSpecType[*types.ProposerSlashing](f, "ProposerSlashing")
}
func FuzzConsensusSpecsSignedBeaconBlockHeader(f *testing.F) {
fuzzConsensusSpecType[*types.SignedBeaconBlockHeader](f, "SignedBeaconBlockHeader")
}
func FuzzConsensusSpecsSignedBLSToExecutionChange(f *testing.F) {
fuzzConsensusSpecType[*types.SignedBLSToExecutionChange](f, "SignedBLSToExecutionChange")
}
func FuzzConsensusSpecsSignedVoluntaryExit(f *testing.F) {
fuzzConsensusSpecType[*types.SignedVoluntaryExit](f, "SignedVoluntaryExit")
}
func FuzzConsensusSpecsSyncAggregate(f *testing.F) {
fuzzConsensusSpecType[*types.SyncAggregate](f, "SyncAggregate")
}
func FuzzConsensusSpecsSyncCommittee(f *testing.F) {
fuzzConsensusSpecType[*types.SyncCommittee](f, "SyncCommittee")
}
func FuzzConsensusSpecsValidator(f *testing.F) {
fuzzConsensusSpecType[*types.Validator](f, "Validator")
}
func FuzzConsensusSpecsVoluntaryExit(f *testing.F) {
fuzzConsensusSpecType[*types.VoluntaryExit](f, "VoluntaryExit")
}
func FuzzConsensusSpecsWithdrawal(f *testing.F) {
fuzzConsensusSpecType[*types.Withdrawal](f, "Withdrawal")
}
func FuzzConsensusSpecsBeaconBlockBodyMonolith(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconBlockBodyMonolith](f, "BeaconBlockBody")
}
func FuzzConsensusSpecsBeaconStateMonolith(f *testing.F) {
fuzzConsensusSpecType[*types.BeaconStateMonolith](f, "BeaconState")
}
func FuzzConsensusSpecsExecutionPayloadMonolith(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadMonolith](f, "ExecutionPayload")
}
func FuzzConsensusSpecsExecutionPayloadHeaderMonolith(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadHeaderMonolith](f, "ExecutionPayloadHeader")
}
func FuzzConsensusSpecsExecutionPayloadVariation(f *testing.F) {
fuzzConsensusSpecType[*types.ExecutionPayloadVariation](f, "ExecutionPayload")
}
func FuzzConsensusSpecsHistoricalBatchVariation(f *testing.F) {
fuzzConsensusSpecType[*types.HistoricalBatchVariation](f, "HistoricalBatch")
}
func FuzzConsensusSpecsWithdrawalVariation(f *testing.F) {
fuzzConsensusSpecType[*types.WithdrawalVariation](f, "Withdrawal")
}
func fuzzConsensusSpecType[T newableObject[U], U any](f *testing.F, kind string) {
// Iterate over all the forks and collect all the sample data
forks, err := os.ReadDir(consensusSpecTestsRoot)
if err != nil {
f.Errorf("failed to walk spec collection %v: %v", consensusSpecTestsRoot, err)
return
}
var valids [][]byte
for _, fork := range forks {
// Skip test cases for types introduced in later forks
path := filepath.Join(consensusSpecTestsRoot, fork.Name(), "ssz_static", kind, "ssz_random")
if _, err := os.Stat(path); err != nil {
continue
}
tests, err := os.ReadDir(path)
if err != nil {
f.Errorf("failed to walk test collection %v: %v", path, err)
return
}
// Feed all the valid test data into the fuzzer
for _, test := range tests {
inSnappy, err := os.ReadFile(filepath.Join(path, test.Name(), "serialized.ssz_snappy"))
if err != nil {
f.Fatalf("failed to load snapy ssz binary: %v", err)
}
inSSZ, err := snappy.Decode(nil, inSnappy)
if err != nil {
f.Fatalf("failed to parse snappy ssz binary: %v", err)
}
obj := T(new(U))
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ)), ssz.ForkFuture); err == nil {
// Stash away all valid ssz streams so we can play with decoding
// into previously used objects
valids = append(valids, inSSZ)
// Add the valid ssz stream to the fuzzer
f.Add(inSSZ)
}
}
}
// Run the fuzzer
f.Fuzz(func(t *testing.T, inSSZ []byte) {
// Track whether the testcase is valid
var valid bool
// Try the stream encoder/decoder
obj := T(new(U))
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ)), ssz.ForkFuture); err == nil {
// Stream decoder succeeded, make sure it re-encodes correctly and
// that the buffer decoder also succeeds parsing
blob := new(bytes.Buffer)
if err := ssz.EncodeToStreamOnFork(blob, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to re-encode stream: %v", err)
}
if !bytes.Equal(blob.Bytes(), inSSZ) {
prefix := commonPrefix(blob.Bytes(), inSSZ)
t.Fatalf("re-encoded stream mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), blob.Bytes()[len(prefix):], inSSZ[len(prefix):])
}
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to decode buffer: %v", err)
}
// Sanity check that hashing and size retrieval works
hash1 := ssz.HashSequentialOnFork(obj, ssz.ForkFuture)
hash2 := ssz.HashConcurrentOnFork(obj, ssz.ForkFuture)
if hash1 != hash2 {
t.Fatalf("sequential/concurrent hash mismatch: sequencial %x, concurrent %x", hash1, hash2)
}
if size := ssz.SizeOnFork(obj, ssz.ForkFuture); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
valid = true
}
// Try the buffer encoder/decoder
obj = T(new(U))
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkFuture); err == nil {
// Buffer decoder succeeded, make sure it re-encodes correctly and
// that the stream decoder also succeeds parsing
bin := make([]byte, ssz.SizeOnFork(obj, ssz.ForkFuture))
if err := ssz.EncodeToBytesOnFork(bin, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to re-encode buffer: %v", err)
}
if !bytes.Equal(bin, inSSZ) {
prefix := commonPrefix(bin, inSSZ)
t.Fatalf("re-encoded buffer mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
bin, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
}
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ)), ssz.ForkFuture); err != nil {
t.Fatalf("failed to decode stream: %v", err)
}
// Sanity check that hashing and size retrieval works
hash1 := ssz.HashSequentialOnFork(obj, ssz.ForkFuture)
hash2 := ssz.HashConcurrentOnFork(obj, ssz.ForkFuture)
if hash1 != hash2 {
t.Fatalf("sequential/concurrent hash mismatch: sequencial %x, concurrent %x", hash1, hash2)
}
if size := ssz.SizeOnFork(obj, ssz.ForkFuture); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
}
// If the testcase was valid, try decoding it into a used object
if valid {
// Pick a random starting object
vSSZ := valids[rand.Intn(len(valids))]
// Try the stream encoder/decoder into a prepped object
obj = T(new(U))
if err := ssz.DecodeFromBytesOnFork(vSSZ, obj, ssz.ForkFuture); err != nil {
panic(err) // we've already decoded this, cannot fail
}
if err := ssz.DecodeFromStreamOnFork(bytes.NewReader(inSSZ), obj, uint32(len(inSSZ)), ssz.ForkFuture); err != nil {
t.Fatalf("failed to decode stream into used object: %v", err)
}
blob := new(bytes.Buffer)
if err := ssz.EncodeToStreamOnFork(blob, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to re-encode stream from used object: %v", err)
}
if !bytes.Equal(blob.Bytes(), inSSZ) {
prefix := commonPrefix(blob.Bytes(), inSSZ)
t.Fatalf("re-encoded stream from used object mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), blob.Bytes()[len(prefix):], inSSZ[len(prefix):])
}
hash1 := ssz.HashSequentialOnFork(obj, ssz.ForkFuture)
hash2 := ssz.HashConcurrentOnFork(obj, ssz.ForkFuture)
if hash1 != hash2 {
t.Fatalf("sequential/concurrent hash mismatch: sequencial %x, concurrent %x", hash1, hash2)
}
if size := ssz.SizeOnFork(obj, ssz.ForkFuture); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
// Try the buffer encoder/decoder into a prepped object
obj = T(new(U))
if err := ssz.DecodeFromBytesOnFork(vSSZ, obj, ssz.ForkFuture); err != nil {
panic(err) // we've already decoded this, cannot fail
}
if err := ssz.DecodeFromBytesOnFork(inSSZ, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to decode buffer into used object: %v", err)
}
bin := make([]byte, ssz.SizeOnFork(obj, ssz.ForkFuture))
if err := ssz.EncodeToBytesOnFork(bin, obj, ssz.ForkFuture); err != nil {
t.Fatalf("failed to re-encode buffer from used object: %v", err)
}
if !bytes.Equal(bin, inSSZ) {
prefix := commonPrefix(bin, inSSZ)
t.Fatalf("re-encoded buffer from used object mismatch: have %x, want %x, common prefix %d, have left %x, want left %x",
blob, inSSZ, len(prefix), bin[len(prefix):], inSSZ[len(prefix):])
}
hash1 = ssz.HashSequentialOnFork(obj, ssz.ForkFuture)
hash2 = ssz.HashConcurrentOnFork(obj, ssz.ForkFuture)
if hash1 != hash2 {
t.Fatalf("sequential/concurrent hash mismatch: sequencial %x, concurrent %x", hash1, hash2)
}
if size := ssz.SizeOnFork(obj, ssz.ForkFuture); size != uint32(len(inSSZ)) {
t.Fatalf("reported/generated size mismatch: reported %v, generated %v", size, len(inSSZ))
}
}
})
}