Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/ava-labs/avalanchego/vms/evm/acp226"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/consensus/misc/eip4844"
"github.com/ava-labs/libevm/core/state"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/trie"
Expand All @@ -25,14 +24,8 @@ import (
)

var (
errUnclesUnsupported = errors.New("uncles unsupported")
ErrInvalidBlockGasCost = errors.New("invalid blockGasCost")
errInvalidExcessBlobGasBeforeCancun = errors.New("invalid excessBlobGas before cancun")
errInvalidBlobGasUsedBeforeCancun = errors.New("invalid blobGasUsed before cancun")
errInvalidParentBeaconRootBeforeCancun = errors.New("invalid parentBeaconRoot before cancun")
errMissingParentBeaconRoot = errors.New("header is missing beaconRoot")
errNonEmptyParentBeaconRoot = errors.New("invalid non-empty parentBeaconRoot")
errBlobsNotEnabled = errors.New("blobs not enabled on avalanche networks")
errUnclesUnsupported = errors.New("uncles unsupported")
ErrInvalidBlockGasCost = errors.New("invalid blockGasCost")
)

type Mode struct {
Expand Down Expand Up @@ -177,31 +170,6 @@ func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
return consensus.ErrInvalidNumber
}
// Verify the existence / non-existence of excessBlobGas
cancun := chain.Config().IsCancun(header.Number, header.Time)
if !cancun {
switch {
case header.ExcessBlobGas != nil:
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *header.ExcessBlobGas)
case header.BlobGasUsed != nil:
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *header.BlobGasUsed)
case header.ParentBeaconRoot != nil:
return fmt.Errorf("%w: have %#x, expected nil", errInvalidParentBeaconRootBeforeCancun, *header.ParentBeaconRoot)
}
} else {
if header.ParentBeaconRoot == nil {
return errMissingParentBeaconRoot
}
if *header.ParentBeaconRoot != (common.Hash{}) {
return fmt.Errorf("%w: have %#x, expected empty", errNonEmptyParentBeaconRoot, *header.ParentBeaconRoot)
}
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {
return err
}
if *header.BlobGasUsed > 0 { // VerifyEIP4844Header ensures BlobGasUsed is non-nil
return fmt.Errorf("%w: used %d blob gas, expected 0", errBlobsNotEnabled, *header.BlobGasUsed)
}
}
return nil
}

Expand Down
41 changes: 18 additions & 23 deletions plugin/evm/wrapped_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
_ snowman.Block = (*wrappedBlock)(nil)
_ block.WithVerifyContext = (*wrappedBlock)(nil)

errInvalidParent = errors.New("parent header not found")
errMissingParentBlock = errors.New("missing parent block")
errInvalidGasUsedRelativeToCapacity = errors.New("invalid gas used relative to capacity")
errTotalIntrinsicGasCostExceedsClaimed = errors.New("total intrinsic gas cost is greater than claimed gas used")
Expand All @@ -43,9 +42,9 @@ var (
var (
errInvalidExcessBlobGasBeforeCancun = errors.New("invalid excessBlobGas before cancun")
errInvalidBlobGasUsedBeforeCancun = errors.New("invalid blobGasUsed before cancun")
errInvalidParent = errors.New("parent header not found")
errInvalidParentBeaconRootBeforeCancun = errors.New("invalid parentBeaconRoot before cancun")
errMissingExcessBlobGas = errors.New("header is missing excessBlobGas")
errMissingBlobGasUsed = errors.New("header is missing blobGasUsed")
errInvalidExcessBlobGas = errors.New("invalid excessBlobGas")
errMissingParentBeaconRoot = errors.New("header is missing parentBeaconRoot")
errParentBeaconRootNonEmpty = errors.New("invalid non-empty parentBeaconRoot")
errBlobGasUsedNilInCancun = errors.New("blob gas used must not be nil in Cancun")
Expand Down Expand Up @@ -391,33 +390,29 @@ func (b *wrappedBlock) syntacticVerify() error {
}

// Verify the existence / non-existence of excessBlobGas
cancun := rules.IsCancun
if !cancun && ethHeader.ExcessBlobGas != nil {
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *ethHeader.ExcessBlobGas)
}
if !cancun && ethHeader.BlobGasUsed != nil {
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *ethHeader.BlobGasUsed)
}
if cancun && ethHeader.ExcessBlobGas == nil {
return errMissingExcessBlobGas
}
if cancun && ethHeader.BlobGasUsed == nil {
return errMissingBlobGasUsed
}
if !cancun && ethHeader.ParentBeaconRoot != nil {
return fmt.Errorf("%w: have %x, expected nil", errInvalidParentBeaconRootBeforeCancun, *ethHeader.ParentBeaconRoot)
}
if cancun {
if rules.IsCancun {
switch {
case ethHeader.ParentBeaconRoot == nil:
return errMissingParentBeaconRoot
case *ethHeader.ParentBeaconRoot != (common.Hash{}):
return fmt.Errorf("%w: have %x, expected empty hash", errParentBeaconRootNonEmpty, ethHeader.ParentBeaconRoot)
}
if ethHeader.BlobGasUsed == nil {
case ethHeader.BlobGasUsed == nil:
return errBlobGasUsedNilInCancun
} else if *ethHeader.BlobGasUsed > 0 {
case *ethHeader.BlobGasUsed != 0:
return fmt.Errorf("%w: used %d blob gas, expected 0", errBlobsNotEnabled, *ethHeader.BlobGasUsed)
case ethHeader.ExcessBlobGas == nil:
return fmt.Errorf("%w: have nil, expected 0", errInvalidExcessBlobGas)
case *ethHeader.ExcessBlobGas != 0:
return fmt.Errorf("%w: have %d, expected 0", errInvalidExcessBlobGas, *ethHeader.ExcessBlobGas)
}
} else {
switch {
case ethHeader.ExcessBlobGas != nil:
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *ethHeader.ExcessBlobGas)
case ethHeader.BlobGasUsed != nil:
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *ethHeader.BlobGasUsed)
case ethHeader.ParentBeaconRoot != nil:
return fmt.Errorf("%w: have %x, expected nil", errInvalidParentBeaconRootBeforeCancun, *ethHeader.ParentBeaconRoot)
}
}

Expand Down
Loading