Skip to content

Commit eab5ad0

Browse files
JonathanOppenheimeralarso16ceyonur
authored
sync: coreth PR #1223: remove duplicate cancun checks (#1790)
Signed-off-by: Jonathan Oppenheimer <jonathan.oppenheimer@avalabs.org> Co-authored-by: Austin Larson <78000745+alarso16@users.noreply.github.com> Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
1 parent a24c432 commit eab5ad0

File tree

2 files changed

+20
-57
lines changed

2 files changed

+20
-57
lines changed

consensus/dummy/consensus.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/ava-labs/avalanchego/vms/evm/acp226"
1212
"github.com/ava-labs/libevm/common"
13-
"github.com/ava-labs/libevm/consensus/misc/eip4844"
1413
"github.com/ava-labs/libevm/core/state"
1514
"github.com/ava-labs/libevm/core/types"
1615
"github.com/ava-labs/libevm/trie"
@@ -25,14 +24,8 @@ import (
2524
)
2625

2726
var (
28-
errUnclesUnsupported = errors.New("uncles unsupported")
29-
ErrInvalidBlockGasCost = errors.New("invalid blockGasCost")
30-
errInvalidExcessBlobGasBeforeCancun = errors.New("invalid excessBlobGas before cancun")
31-
errInvalidBlobGasUsedBeforeCancun = errors.New("invalid blobGasUsed before cancun")
32-
errInvalidParentBeaconRootBeforeCancun = errors.New("invalid parentBeaconRoot before cancun")
33-
errMissingParentBeaconRoot = errors.New("header is missing beaconRoot")
34-
errNonEmptyParentBeaconRoot = errors.New("invalid non-empty parentBeaconRoot")
35-
errBlobsNotEnabled = errors.New("blobs not enabled on avalanche networks")
27+
errUnclesUnsupported = errors.New("uncles unsupported")
28+
ErrInvalidBlockGasCost = errors.New("invalid blockGasCost")
3629
)
3730

3831
type Mode struct {
@@ -177,31 +170,6 @@ func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *
177170
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
178171
return consensus.ErrInvalidNumber
179172
}
180-
// Verify the existence / non-existence of excessBlobGas
181-
cancun := chain.Config().IsCancun(header.Number, header.Time)
182-
if !cancun {
183-
switch {
184-
case header.ExcessBlobGas != nil:
185-
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *header.ExcessBlobGas)
186-
case header.BlobGasUsed != nil:
187-
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *header.BlobGasUsed)
188-
case header.ParentBeaconRoot != nil:
189-
return fmt.Errorf("%w: have %#x, expected nil", errInvalidParentBeaconRootBeforeCancun, *header.ParentBeaconRoot)
190-
}
191-
} else {
192-
if header.ParentBeaconRoot == nil {
193-
return errMissingParentBeaconRoot
194-
}
195-
if *header.ParentBeaconRoot != (common.Hash{}) {
196-
return fmt.Errorf("%w: have %#x, expected empty", errNonEmptyParentBeaconRoot, *header.ParentBeaconRoot)
197-
}
198-
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {
199-
return err
200-
}
201-
if *header.BlobGasUsed > 0 { // VerifyEIP4844Header ensures BlobGasUsed is non-nil
202-
return fmt.Errorf("%w: used %d blob gas, expected 0", errBlobsNotEnabled, *header.BlobGasUsed)
203-
}
204-
}
205173
return nil
206174
}
207175

plugin/evm/wrapped_block.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var (
3333
_ snowman.Block = (*wrappedBlock)(nil)
3434
_ block.WithVerifyContext = (*wrappedBlock)(nil)
3535

36-
errInvalidParent = errors.New("parent header not found")
3736
errMissingParentBlock = errors.New("missing parent block")
3837
errInvalidGasUsedRelativeToCapacity = errors.New("invalid gas used relative to capacity")
3938
errTotalIntrinsicGasCostExceedsClaimed = errors.New("total intrinsic gas cost is greater than claimed gas used")
@@ -43,9 +42,9 @@ var (
4342
var (
4443
errInvalidExcessBlobGasBeforeCancun = errors.New("invalid excessBlobGas before cancun")
4544
errInvalidBlobGasUsedBeforeCancun = errors.New("invalid blobGasUsed before cancun")
45+
errInvalidParent = errors.New("parent header not found")
4646
errInvalidParentBeaconRootBeforeCancun = errors.New("invalid parentBeaconRoot before cancun")
47-
errMissingExcessBlobGas = errors.New("header is missing excessBlobGas")
48-
errMissingBlobGasUsed = errors.New("header is missing blobGasUsed")
47+
errInvalidExcessBlobGas = errors.New("invalid excessBlobGas")
4948
errMissingParentBeaconRoot = errors.New("header is missing parentBeaconRoot")
5049
errParentBeaconRootNonEmpty = errors.New("invalid non-empty parentBeaconRoot")
5150
errBlobGasUsedNilInCancun = errors.New("blob gas used must not be nil in Cancun")
@@ -391,33 +390,29 @@ func (b *wrappedBlock) syntacticVerify() error {
391390
}
392391

393392
// Verify the existence / non-existence of excessBlobGas
394-
cancun := rules.IsCancun
395-
if !cancun && ethHeader.ExcessBlobGas != nil {
396-
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *ethHeader.ExcessBlobGas)
397-
}
398-
if !cancun && ethHeader.BlobGasUsed != nil {
399-
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *ethHeader.BlobGasUsed)
400-
}
401-
if cancun && ethHeader.ExcessBlobGas == nil {
402-
return errMissingExcessBlobGas
403-
}
404-
if cancun && ethHeader.BlobGasUsed == nil {
405-
return errMissingBlobGasUsed
406-
}
407-
if !cancun && ethHeader.ParentBeaconRoot != nil {
408-
return fmt.Errorf("%w: have %x, expected nil", errInvalidParentBeaconRootBeforeCancun, *ethHeader.ParentBeaconRoot)
409-
}
410-
if cancun {
393+
if rules.IsCancun {
411394
switch {
412395
case ethHeader.ParentBeaconRoot == nil:
413396
return errMissingParentBeaconRoot
414397
case *ethHeader.ParentBeaconRoot != (common.Hash{}):
415398
return fmt.Errorf("%w: have %x, expected empty hash", errParentBeaconRootNonEmpty, ethHeader.ParentBeaconRoot)
416-
}
417-
if ethHeader.BlobGasUsed == nil {
399+
case ethHeader.BlobGasUsed == nil:
418400
return errBlobGasUsedNilInCancun
419-
} else if *ethHeader.BlobGasUsed > 0 {
401+
case *ethHeader.BlobGasUsed != 0:
420402
return fmt.Errorf("%w: used %d blob gas, expected 0", errBlobsNotEnabled, *ethHeader.BlobGasUsed)
403+
case ethHeader.ExcessBlobGas == nil:
404+
return fmt.Errorf("%w: have nil, expected 0", errInvalidExcessBlobGas)
405+
case *ethHeader.ExcessBlobGas != 0:
406+
return fmt.Errorf("%w: have %d, expected 0", errInvalidExcessBlobGas, *ethHeader.ExcessBlobGas)
407+
}
408+
} else {
409+
switch {
410+
case ethHeader.ExcessBlobGas != nil:
411+
return fmt.Errorf("%w: have %d, expected nil", errInvalidExcessBlobGasBeforeCancun, *ethHeader.ExcessBlobGas)
412+
case ethHeader.BlobGasUsed != nil:
413+
return fmt.Errorf("%w: have %d, expected nil", errInvalidBlobGasUsedBeforeCancun, *ethHeader.BlobGasUsed)
414+
case ethHeader.ParentBeaconRoot != nil:
415+
return fmt.Errorf("%w: have %x, expected nil", errInvalidParentBeaconRootBeforeCancun, *ethHeader.ParentBeaconRoot)
421416
}
422417
}
423418

0 commit comments

Comments
 (0)