28
28
import tech .pegasys .teku .fuzz .input .BlockFuzzInput ;
29
29
import tech .pegasys .teku .fuzz .input .BlockHeaderFuzzInput ;
30
30
import tech .pegasys .teku .fuzz .input .BlsToExecutionChangeFuzzInput ;
31
+ import tech .pegasys .teku .fuzz .input .ConsolidationRequestFuzzInput ;
31
32
import tech .pegasys .teku .fuzz .input .DepositFuzzInput ;
33
+ import tech .pegasys .teku .fuzz .input .DepositRequestFuzzInput ;
32
34
import tech .pegasys .teku .fuzz .input .ProposerSlashingFuzzInput ;
33
35
import tech .pegasys .teku .fuzz .input .SyncAggregateFuzzInput ;
34
36
import tech .pegasys .teku .fuzz .input .VoluntaryExitFuzzInput ;
37
+ import tech .pegasys .teku .fuzz .input .WithdrawalRequestFuzzInput ;
35
38
import tech .pegasys .teku .infrastructure .ssz .SszData ;
36
39
import tech .pegasys .teku .infrastructure .ssz .SszList ;
37
40
import tech .pegasys .teku .infrastructure .ssz .schema .SszSchema ;
40
43
import tech .pegasys .teku .spec .SpecMilestone ;
41
44
import tech .pegasys .teku .spec .SpecVersion ;
42
45
import tech .pegasys .teku .spec .TestSpecFactory ;
46
+ import tech .pegasys .teku .spec .config .SpecConfigElectra ;
43
47
import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .altair .SyncAggregate ;
44
- import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .capella .BeaconBlockBodyCapella ;
45
- import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .capella .BeaconBlockBodySchemaCapella ;
48
+ import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .electra .BeaconBlockBodyElectra ;
49
+ import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .electra .BeaconBlockBodySchemaElectra ;
50
+ import tech .pegasys .teku .spec .datastructures .execution .versions .electra .ConsolidationRequest ;
51
+ import tech .pegasys .teku .spec .datastructures .execution .versions .electra .DepositRequest ;
52
+ import tech .pegasys .teku .spec .datastructures .execution .versions .electra .WithdrawalRequest ;
46
53
import tech .pegasys .teku .spec .datastructures .operations .Attestation ;
47
54
import tech .pegasys .teku .spec .datastructures .operations .AttesterSlashing ;
48
55
import tech .pegasys .teku .spec .datastructures .operations .Deposit ;
52
59
import tech .pegasys .teku .spec .datastructures .state .beaconstate .BeaconState ;
53
60
import tech .pegasys .teku .spec .logic .common .statetransition .exceptions .BlockProcessingException ;
54
61
import tech .pegasys .teku .spec .logic .common .statetransition .exceptions .StateTransitionException ;
62
+ import tech .pegasys .teku .spec .logic .versions .electra .helpers .BeaconStateAccessorsElectra ;
63
+ import tech .pegasys .teku .spec .logic .versions .electra .helpers .BeaconStateMutatorsElectra ;
64
+ import tech .pegasys .teku .spec .logic .versions .electra .helpers .MiscHelpersElectra ;
65
+ import tech .pegasys .teku .spec .logic .versions .electra .helpers .PredicatesElectra ;
66
+ import tech .pegasys .teku .spec .schemas .SchemaDefinitionsElectra ;
55
67
56
68
public class FuzzUtil {
57
69
// NOTE: alternatively could also have these all in separate classes, which implement a
58
70
// "FuzzHarness" interface
59
71
60
72
private final Spec spec ;
61
- private final BeaconBlockBodySchemaCapella <?> beaconBlockBodySchema ;
73
+ private final BeaconBlockBodySchemaElectra <?> beaconBlockBodySchema ;
62
74
private final SpecVersion specVersion ;
75
+ private final BeaconStateMutatorsElectra stateMutatorsElectra ;
63
76
64
77
// Size of ValidatorIndex returned by shuffle
65
78
private static final int OUTPUT_INDEX_BYTES = Long .BYTES ;
@@ -70,14 +83,27 @@ public class FuzzUtil {
70
83
public FuzzUtil (final boolean useMainnetConfig , final boolean disableBls ) {
71
84
spec =
72
85
useMainnetConfig
73
- ? TestSpecFactory .createMainnetCapella ()
74
- : TestSpecFactory .createMinimalCapella ();
75
- specVersion = spec .forMilestone (SpecMilestone .CAPELLA );
86
+ ? TestSpecFactory .createMainnetElectra ()
87
+ : TestSpecFactory .createMinimalElectra ();
88
+ specVersion = spec .forMilestone (SpecMilestone .ELECTRA );
76
89
beaconBlockBodySchema =
77
- (BeaconBlockBodySchemaCapella <?>)
90
+ (BeaconBlockBodySchemaElectra <?>)
78
91
specVersion .getSchemaDefinitions ().getBeaconBlockBodySchema ();
79
92
initialize (disableBls );
80
93
this .signatureVerifier = disableBls ? BLSSignatureVerifier .NO_OP : BLSSignatureVerifier .SIMPLE ;
94
+
95
+ final PredicatesElectra predicates = new PredicatesElectra (spec .getGenesisSpecConfig ());
96
+ final SchemaDefinitionsElectra schemaDefinitionsElectra =
97
+ SchemaDefinitionsElectra .required (spec .getGenesisSchemaDefinitions ());
98
+ final SpecConfigElectra specConfig =
99
+ spec .getGenesisSpecConfig ().toVersionElectra ().orElseThrow ();
100
+ final MiscHelpersElectra miscHelpersElectra =
101
+ new MiscHelpersElectra (specConfig , predicates , schemaDefinitionsElectra );
102
+ final BeaconStateAccessorsElectra stateAccessorsElectra =
103
+ new BeaconStateAccessorsElectra (specConfig , predicates , miscHelpersElectra );
104
+ stateMutatorsElectra =
105
+ new BeaconStateMutatorsElectra (
106
+ specConfig , miscHelpersElectra , stateAccessorsElectra , schemaDefinitionsElectra );
81
107
}
82
108
83
109
public static void initialize (final boolean disableBls ) {
@@ -146,7 +172,6 @@ public Optional<byte[]> fuzzBlock(final byte[] input) {
146
172
Bytes output = postState .sszSerialize ();
147
173
return Optional .of (output .toArrayUnsafe ());
148
174
} catch (StateTransitionException e ) {
149
- e .printStackTrace ();
150
175
// "expected error"
151
176
return Optional .empty ();
152
177
}
@@ -293,7 +318,7 @@ public Optional<byte[]> fuzzExecutionPayload(final byte[] input) {
293
318
BeaconBlockBodyFuzzInput structuredPayloadInput =
294
319
deserialize (input , BeaconBlockBodyFuzzInput .createSchema (specVersion ));
295
320
296
- final BeaconBlockBodyCapella beaconBlockBody = structuredPayloadInput .getBeaconBlockBody ();
321
+ final BeaconBlockBodyElectra beaconBlockBody = structuredPayloadInput .getBeaconBlockBody ();
297
322
try {
298
323
BeaconState postState =
299
324
structuredPayloadInput
@@ -334,6 +359,85 @@ public Optional<byte[]> fuzzBlsToExecutionChange(final byte[] input) {
334
359
}
335
360
}
336
361
362
+ public Optional <byte []> fuzzDepositRequest (final byte [] input ) {
363
+ DepositRequestFuzzInput structuredInput =
364
+ deserialize (input , DepositRequestFuzzInput .createSchema (specVersion ));
365
+ SszList <DepositRequest > depositRequests =
366
+ beaconBlockBodySchema
367
+ .getExecutionRequestsSchema ()
368
+ .getDepositRequestsSchema ()
369
+ .of (structuredInput .getDepositRequest ());
370
+
371
+ try {
372
+ BeaconState postState =
373
+ structuredInput
374
+ .getState ()
375
+ .updated (
376
+ state ->
377
+ spec .getBlockProcessor (state .getSlot ())
378
+ .processDepositRequests (state , depositRequests .asList ()));
379
+ Bytes output = postState .sszSerialize ();
380
+ return Optional .of (output .toArrayUnsafe ());
381
+ } catch (BlockProcessingException e ) {
382
+ // "expected error"
383
+ return Optional .empty ();
384
+ }
385
+ }
386
+
387
+ public Optional <byte []> fuzzWithdrawalRequest (final byte [] input ) {
388
+ WithdrawalRequestFuzzInput structuredInput =
389
+ deserialize (input , WithdrawalRequestFuzzInput .createSchema (specVersion ));
390
+ SszList <WithdrawalRequest > withdrawalRequests =
391
+ beaconBlockBodySchema
392
+ .getExecutionRequestsSchema ()
393
+ .getWithdrawalRequestsSchema ()
394
+ .of (structuredInput .getWithdrawalRequest ());
395
+
396
+ try {
397
+ BeaconState postState =
398
+ structuredInput
399
+ .getState ()
400
+ .updated (
401
+ state ->
402
+ spec .getBlockProcessor (state .getSlot ())
403
+ .processWithdrawalRequests (
404
+ state ,
405
+ withdrawalRequests .asList (),
406
+ stateMutatorsElectra .createValidatorExitContextSupplier (
407
+ structuredInput .getState ())));
408
+ Bytes output = postState .sszSerialize ();
409
+ return Optional .of (output .toArrayUnsafe ());
410
+ } catch (BlockProcessingException e ) {
411
+ // "expected error"
412
+ return Optional .empty ();
413
+ }
414
+ }
415
+
416
+ public Optional <byte []> fuzzConsolidationRequest (final byte [] input ) {
417
+ ConsolidationRequestFuzzInput structuredInput =
418
+ deserialize (input , ConsolidationRequestFuzzInput .createSchema (specVersion ));
419
+ SszList <ConsolidationRequest > consolidationRequests =
420
+ beaconBlockBodySchema
421
+ .getExecutionRequestsSchema ()
422
+ .getConsolidationRequestsSchema ()
423
+ .of (structuredInput .getConsolidationRequest ());
424
+
425
+ try {
426
+ BeaconState postState =
427
+ structuredInput
428
+ .getState ()
429
+ .updated (
430
+ state ->
431
+ spec .getBlockProcessor (state .getSlot ())
432
+ .processConsolidationRequests (state , consolidationRequests .asList ()));
433
+ Bytes output = postState .sszSerialize ();
434
+ return Optional .of (output .toArrayUnsafe ());
435
+ } catch (BlockProcessingException e ) {
436
+ // "expected error"
437
+ return Optional .empty ();
438
+ }
439
+ }
440
+
337
441
private <T extends SszData > T deserialize (final byte [] data , final SszSchema <T > type ) {
338
442
// allow exception to propagate on failure - indicates a preprocessing or deserializing error
339
443
T structuredInput = type .sszDeserialize (Bytes .wrap (data ));
0 commit comments