Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
26 changes: 0 additions & 26 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/big"

"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 Down Expand Up @@ -165,31 +164,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("invalid excessBlobGas: have %d, expected nil", *header.ExcessBlobGas)
case header.BlobGasUsed != nil:
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", *header.BlobGasUsed)
case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", *header.ParentBeaconRoot)
}
} else {
if header.ParentBeaconRoot == nil {
return errors.New("header is missing beaconRoot")
}
if *header.ParentBeaconRoot != (common.Hash{}) {
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected empty", *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("blobs not enabled on avalanche networks: used %d blob gas, expected 0", *header.BlobGasUsed)
}
}
return nil
}

Expand Down
56 changes: 31 additions & 25 deletions plugin/evm/wrapped_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ 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")
)

// wrappedBlock implements the snowman.Block interface by wrapping a libevm block
// Sentinel errors for header validation in this file
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")
errInvalidExcessBlobGas = errors.New("invalid excessBlobGas")
errParentBeaconRootNonEmpty = errors.New("invalid non-empty parentBeaconRoot")
errBlobGasUsedNilInCancun = errors.New("blob gas used must not be nil in Cancun")
errBlobsNotEnabled = errors.New("blobs not enabled on avalanche networks")
)

// wrappedBlock implements the snowman.wrappedBlock interface
type wrappedBlock struct {
id ids.ID
ethBlock *types.Block
Expand Down Expand Up @@ -285,7 +296,6 @@ func (b *wrappedBlock) semanticVerify() error {
if parent == nil {
return fmt.Errorf("%w: %s at height %d", errInvalidParent, b.ethBlock.ParentHash(), b.ethBlock.NumberU64()-1)
}

// Ensure Time and TimeMilliseconds are consistent with rules.
if err := customheader.VerifyTime(extraConfig, parent, b.ethBlock.Header(), b.vm.clock.Time()); err != nil {
return err
Expand Down Expand Up @@ -374,33 +384,29 @@ func (b *wrappedBlock) syntacticVerify() error {
}

// Verify the existence / non-existence of excessBlobGas
cancun := rules.IsCancun
if !cancun && ethHeader.ExcessBlobGas != nil {
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", *ethHeader.ExcessBlobGas)
}
if !cancun && ethHeader.BlobGasUsed != nil {
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", *ethHeader.BlobGasUsed)
}
if cancun && ethHeader.ExcessBlobGas == nil {
return errors.New("header is missing excessBlobGas")
}
if cancun && ethHeader.BlobGasUsed == nil {
return errors.New("header is missing blobGasUsed")
}
if !cancun && ethHeader.ParentBeaconRoot != nil {
return fmt.Errorf("invalid parentBeaconRoot: have %x, expected nil", *ethHeader.ParentBeaconRoot)
}
if cancun {
if rules.IsCancun {
switch {
case ethHeader.ParentBeaconRoot == nil:
return errors.New("header is missing parentBeaconRoot")
case *ethHeader.ParentBeaconRoot != (common.Hash{}):
return fmt.Errorf("invalid parentBeaconRoot: have %x, expected empty hash", ethHeader.ParentBeaconRoot)
return fmt.Errorf("%w: have %x, expected empty hash", errParentBeaconRootNonEmpty, ethHeader.ParentBeaconRoot)
case ethHeader.BlobGasUsed == nil:
return errBlobGasUsedNilInCancun
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)
}
if ethHeader.BlobGasUsed == nil {
return errors.New("blob gas used must not be nil in Cancun")
} else if *ethHeader.BlobGasUsed > 0 {
return fmt.Errorf("blobs not enabled on avalanche networks: used %d blob gas, expected 0", *ethHeader.BlobGasUsed)
} 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