@@ -34,13 +34,25 @@ var (
3434 _ snowman.Block = (* wrappedBlock )(nil )
3535 _ block.WithVerifyContext = (* wrappedBlock )(nil )
3636
37- errInvalidParent = errors .New ("parent header not found" )
3837 errMissingParentBlock = errors .New ("missing parent block" )
3938 errInvalidGasUsedRelativeToCapacity = errors .New ("invalid gas used relative to capacity" )
4039 errTotalIntrinsicGasCostExceedsClaimed = errors .New ("total intrinsic gas cost is greater than claimed gas used" )
4140)
4241
43- // wrappedBlock implements the snowman.Block interface by wrapping a libevm block
42+ // Sentinel errors for header validation in this file
43+ var (
44+ errInvalidExcessBlobGasBeforeCancun = errors .New ("invalid excessBlobGas before cancun" )
45+ errInvalidBlobGasUsedBeforeCancun = errors .New ("invalid blobGasUsed before cancun" )
46+ errInvalidParent = errors .New ("parent header not found" )
47+ errInvalidParentBeaconRootBeforeCancun = errors .New ("invalid parentBeaconRoot before cancun" )
48+ errInvalidExcessBlobGas = errors .New ("invalid excessBlobGas" )
49+ errMissingParentBeaconRoot = errors .New ("header is missing parentBeaconRoot" )
50+ errParentBeaconRootNonEmpty = errors .New ("invalid non-empty parentBeaconRoot" )
51+ errBlobGasUsedNilInCancun = errors .New ("blob gas used must not be nil in Cancun" )
52+ errBlobsNotEnabled = errors .New ("blobs not enabled on avalanche networks" )
53+ )
54+
55+ // wrappedBlock implements the snowman.wrappedBlock interface
4456type wrappedBlock struct {
4557 id ids.ID
4658 ethBlock * types.Block
@@ -285,7 +297,6 @@ func (b *wrappedBlock) semanticVerify() error {
285297 if parent == nil {
286298 return fmt .Errorf ("%w: %s at height %d" , errInvalidParent , b .ethBlock .ParentHash (), b .ethBlock .NumberU64 ()- 1 )
287299 }
288-
289300 // Ensure Time and TimeMilliseconds are consistent with rules.
290301 if err := customheader .VerifyTime (extraConfig , parent , b .ethBlock .Header (), b .vm .clock .Time ()); err != nil {
291302 return err
@@ -374,33 +385,29 @@ func (b *wrappedBlock) syntacticVerify() error {
374385 }
375386
376387 // Verify the existence / non-existence of excessBlobGas
377- cancun := rules .IsCancun
378- if ! cancun && ethHeader .ExcessBlobGas != nil {
379- return fmt .Errorf ("invalid excessBlobGas: have %d, expected nil" , * ethHeader .ExcessBlobGas )
380- }
381- if ! cancun && ethHeader .BlobGasUsed != nil {
382- return fmt .Errorf ("invalid blobGasUsed: have %d, expected nil" , * ethHeader .BlobGasUsed )
383- }
384- if cancun && ethHeader .ExcessBlobGas == nil {
385- return errors .New ("header is missing excessBlobGas" )
386- }
387- if cancun && ethHeader .BlobGasUsed == nil {
388- return errors .New ("header is missing blobGasUsed" )
389- }
390- if ! cancun && ethHeader .ParentBeaconRoot != nil {
391- return fmt .Errorf ("invalid parentBeaconRoot: have %x, expected nil" , * ethHeader .ParentBeaconRoot )
392- }
393- if cancun {
388+ if rules .IsCancun {
394389 switch {
395390 case ethHeader .ParentBeaconRoot == nil :
396391 return errors .New ("header is missing parentBeaconRoot" )
397392 case * ethHeader .ParentBeaconRoot != (common.Hash {}):
398- return fmt .Errorf ("invalid parentBeaconRoot: have %x, expected empty hash" , ethHeader .ParentBeaconRoot )
393+ return fmt .Errorf ("%w: have %x, expected empty hash" , errParentBeaconRootNonEmpty , ethHeader .ParentBeaconRoot )
394+ case ethHeader .BlobGasUsed == nil :
395+ return errBlobGasUsedNilInCancun
396+ case * ethHeader .BlobGasUsed != 0 :
397+ return fmt .Errorf ("%w: used %d blob gas, expected 0" , errBlobsNotEnabled , * ethHeader .BlobGasUsed )
398+ case ethHeader .ExcessBlobGas == nil :
399+ return fmt .Errorf ("%w: have nil, expected 0" , errInvalidExcessBlobGas )
400+ case * ethHeader .ExcessBlobGas != 0 :
401+ return fmt .Errorf ("%w: have %d, expected 0" , errInvalidExcessBlobGas , * ethHeader .ExcessBlobGas )
399402 }
400- if ethHeader .BlobGasUsed == nil {
401- return errors .New ("blob gas used must not be nil in Cancun" )
402- } else if * ethHeader .BlobGasUsed > 0 {
403- return fmt .Errorf ("blobs not enabled on avalanche networks: used %d blob gas, expected 0" , * ethHeader .BlobGasUsed )
403+ } else {
404+ switch {
405+ case ethHeader .ExcessBlobGas != nil :
406+ return fmt .Errorf ("%w: have %d, expected nil" , errInvalidExcessBlobGasBeforeCancun , * ethHeader .ExcessBlobGas )
407+ case ethHeader .BlobGasUsed != nil :
408+ return fmt .Errorf ("%w: have %d, expected nil" , errInvalidBlobGasUsedBeforeCancun , * ethHeader .BlobGasUsed )
409+ case ethHeader .ParentBeaconRoot != nil :
410+ return fmt .Errorf ("%w: have %x, expected nil" , errInvalidParentBeaconRootBeforeCancun , * ethHeader .ParentBeaconRoot )
404411 }
405412 }
406413
0 commit comments