Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8a848da
ChainConfig changes, compatibility checks, protocol params
i-norden Sep 12, 2019
6c2bd6b
tx Enode/DecodeRLP methods
i-norden Nov 6, 2019
2a21b89
apply changes across all pkgs
i-norden Nov 7, 2019
d389dce
gencodec for tx
i-norden Nov 8, 2019
09c3345
transaction signing updates; eip1559 tx unit tests
i-norden Nov 14, 2019
666444a
add fields to RPCTransaction
i-norden Nov 18, 2019
a4976e4
simplify EncodeRLP
i-norden Nov 20, 2019
7354dd5
modifications to message struct
i-norden Nov 7, 2019
539c056
apply message changes across all pkgs
i-norden Nov 7, 2019
75e8f67
add fields to CallArgs and SendTxArgs; add guards to DoCall,
i-norden Nov 15, 2019
cc66c49
basefee fields and serialization
i-norden Nov 7, 2019
35d0d2e
gencodec for header; block method to retrieve basefee
i-norden Nov 8, 2019
19b7ce1
add BaseFee field to RPCMarshalHeader
i-norden Nov 15, 2019
854499f
use anon struct in header encode to prevent recursive loop
i-norden Nov 18, 2019
bc03b9c
eip1559 header decode/encode unit tests
i-norden Nov 18, 2019
0d17045
simplify EncodeRLP; cleanup
i-norden Nov 20, 2019
470da15
gas pool/trx execution changes to core
i-norden Nov 8, 2019
4c6d08c
apply gas pool/trx execution changes across pkgs
i-norden Nov 12, 2019
f2050e3
fix refund and coinbase credit
i-norden Nov 19, 2019
1d77388
add guards to backends/simulated.go callContract and SendTransaction
i-norden Nov 19, 2019
52d5c08
simplify calculations in state_transition.go; add guards and derive g…
i-norden Nov 20, 2019
1937670
worker.commitTransaction() calc ratio using MaxGasEIP1559 instead of …
i-norden Nov 22, 2019
b701eea
modify verifyHeader() for ethash
i-norden Nov 20, 2019
783f706
modify ethash.SealHash()
i-norden Nov 20, 2019
939107b
CalcGasLimitAndBaseFee function
i-norden Nov 25, 2019
99bffe5
use new CalcGasLimitAndBaseFee function
i-norden Nov 27, 2019
514bfbf
initialization => activation; calcGasLimitAndBaseFee doesn't need gas…
i-norden Dec 5, 2019
3187d3f
adjust verifyHeaders to validate GasLimit as calculated by new CalcGa…
i-norden Dec 5, 2019
90e5785
IsEWASM after IsEIP1559 forks in config so we don't need EWASM engine…
i-norden Dec 6, 2019
15a8b7d
evm needs to handle nil GasPrice; genesis needs to handle BaseFee
i-norden Dec 6, 2019
506cdd6
begin consensus tests
i-norden Dec 6, 2019
c64ae71
fix guards in simulated.callContract so that bind_tests work
i-norden Dec 6, 2019
f57a93d
mobile feeCap and gasPremium => *BigInt instead of *big.Int; add gett…
i-norden Dec 6, 2019
3933ee7
finish chain_maker_tests for EIP1559
i-norden Dec 6, 2019
93871ed
transaction.Cost() needs to be aware of BaseFee to calculate cost for…
i-norden Dec 9, 2019
8719586
Merge pull request #13 from vulcanize/fork_activation
i-norden Dec 11, 2019
3d958b1
Merge pull request #14 from vulcanize/new_trx_fields_and_serialization
i-norden Dec 11, 2019
262dfc4
Merge pull request #15 from vulcanize/modifications_to_message_struct
i-norden Dec 11, 2019
a50d3c6
Merge pull request #16 from vulcanize/new_basefee_fields_and_serializ…
i-norden Dec 11, 2019
d94599d
tx_pool_tests and benchmarks for EIP1559
i-norden Dec 9, 2019
4f0eaae
fix trx decoding; test
i-norden Dec 11, 2019
0c8dcc0
Merge pull request #17 from vulcanize/transaction_execution
i-norden Dec 11, 2019
7842864
Merge pull request #18 from vulcanize/block_verification
i-norden Dec 11, 2019
d15006b
Merge pull request #19 from vulcanize/calc_gas_limit
i-norden Dec 11, 2019
f4a7c08
block_validator_test and fixes
i-norden Dec 13, 2019
fc7506c
run gencodec on new genesis struct
i-norden Dec 13, 2019
647c8ba
worker_test and fixes
i-norden Dec 13, 2019
42fcd79
blockchain_test
i-norden Dec 13, 2019
5dd38c3
Merge pull request #21 from vulcanize/consensus_tests
i-norden Dec 13, 2019
856c987
build(deps): bump handlebars from 4.1.2 to 4.5.3 in /dashboard/assets
dependabot[bot] Dec 30, 2019
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
43 changes: 41 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,28 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallMsg, block *types.Block, statedb *state.StateDB) ([]byte, uint64, bool, error) {
// Ensure message is initialized properly.
if call.GasPrice == nil {
// EIP1559 guards
// If we have finalized EIP1559 and do not have a properly formed EIP1559 trx, sub in default values
if b.config.IsEIP1559Finalized(block.Number()) && (call.GasPremium == nil || call.FeeCap == nil || call.GasPrice != nil) {
call.GasPremium = big.NewInt(1)
call.FeeCap = big.NewInt(10)
call.GasPrice = nil
}
// If we have not activated EIP1559 and do not have a properly formed legacy trx, sub in default values
if !b.config.IsEIP1559(block.Number()) && (call.GasPremium != nil || call.FeeCap != nil || call.GasPrice == nil) {
call.GasPremium = nil
call.FeeCap = nil
call.GasPrice = big.NewInt(1)
}
// If we are in between activation and finalization
if b.config.IsEIP1559(block.Number()) && !b.config.IsEIP1559Finalized(block.Number()) {
// and we have neither a properly formed legacy or EIP1559 transaction, sub in default legacy values
if (call.GasPremium == nil || call.FeeCap == nil && call.GasPrice == nil) || (call.GasPremium != nil || call.FeeCap != nil && call.GasPrice != nil) {
call.GasPremium = nil
call.FeeCap = nil
call.GasPrice = big.NewInt(1)
}
}
if call.Gas == 0 {
call.Gas = 50000000
}
Expand All @@ -319,8 +338,12 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{})
gaspool := new(core.GasPool).AddGas(math.MaxUint64)
var gp1559 *core.GasPool
if b.config.IsEIP1559(block.Number()) {
gp1559 = new(core.GasPool).AddGas(math.MaxUint64)
}

return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
return core.NewStateTransition(vmenv, msg, gaspool, gp1559).TransitionDb()
}

// SendTransaction updates the pending block to include the given transaction.
Expand All @@ -329,6 +352,20 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
b.mu.Lock()
defer b.mu.Unlock()

// EIP1559 guards
if b.config.IsEIP1559Finalized(b.blockchain.CurrentBlock().Number()) && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) {
return core.ErrTxNotEIP1559
}
if !b.config.IsEIP1559(b.blockchain.CurrentBlock().Number()) && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return core.ErrTxIsEIP1559
}
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) {
return core.ErrTxSetsLegacyAndEIP1559Fields
}
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) {
return core.ErrMissingGasFields
}

sender, err := types.Sender(types.NewEIP155Signer(b.config.ChainID), tx)
if err != nil {
panic(fmt.Errorf("invalid transaction: %v", err))
Expand Down Expand Up @@ -455,6 +492,8 @@ func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) GasPremium() *big.Int { return m.CallMsg.GasPremium }
func (m callmsg) FeeCap() *big.Int { return m.CallMsg.FeeCap }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSimulatedBackend(t *testing.T) {
// generate a transaction and confirm you can retrieve it
code := `6060604052600a8060106000396000f360606040526008565b00`
var gas uint64 = 3000000
tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code))
tx := types.NewContractCreation(0, big.NewInt(0), gas, big.NewInt(1), common.FromHex(code), nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, key)

err = sim.SendTransaction(context.Background(), tx)
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
// Create the transaction, sign it and schedule it for execution
var rawTx *types.Transaction
if contract == nil {
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input)
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, nil, nil)
} else {
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input)
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil, nil)
}
if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with")
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestWaitDeployed(t *testing.T) {
defer backend.Close()

// Create the transaction.
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code))
tx := types.NewContractCreation(0, big.NewInt(0), test.gas, big.NewInt(1), common.FromHex(test.code), nil, nil)
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)

// Wait for it to get mined in the background.
Expand Down
1 change: 1 addition & 0 deletions cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ func testExternalUI(api *core.SignerAPI) {
[]byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
common.HexToHash("0x0000H45H"),
types.BlockNonce{},
nil,
}
cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil))
amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil))

tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil)
tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil)
signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID)
if err != nil {
f.lock.Unlock()
Expand Down
24 changes: 21 additions & 3 deletions cmd/geth/retesteth.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ func (api *RetestethAPI) mineBlock() error {
if api.chainConfig.DAOForkSupport && api.chainConfig.DAOForkBlock != nil && api.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
misc.ApplyDAOHardFork(statedb)
}
gasPool := new(core.GasPool).AddGas(header.GasLimit)

var gp1559 *core.GasPool
var gasPool *core.GasPool
if api.chainConfig.IsEIP1559(header.Number) {
gasPool = new(core.GasPool).AddGas(params.MaxGasEIP1559 - header.GasLimit)
gp1559 = new(core.GasPool).AddGas(header.GasLimit)
} else {
gasPool = new(core.GasPool).AddGas(header.GasLimit)
}

txCount := 0
var txs []*types.Transaction
var receipts []*types.Receipt
Expand All @@ -513,6 +522,7 @@ func (api *RetestethAPI) mineBlock() error {
api.blockchain,
&api.author,
gasPool,
gp1559,
statedb,
header, tx, &header.GasUsed, *api.blockchain.GetVMConfig(),
)
Expand Down Expand Up @@ -657,7 +667,11 @@ func (api *RetestethAPI) AccountRange(ctx context.Context,
context := core.NewEVMContext(msg, block.Header(), api.blockchain, nil)
// Not yet the searched for transaction, execute on top of the current state
vmenv := vm.NewEVM(context, statedb, api.blockchain.Config(), vm.Config{})
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
var gp1559 *core.GasPool
if vmenv.ChainConfig().IsEIP1559(block.Number()) {
gp1559 = new(core.GasPool).AddGas(tx.Gas())
}
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()), gp1559); err != nil {
return AccountRangeResult{}, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
}
// Ensure any modifications are committed to the state
Expand Down Expand Up @@ -770,7 +784,11 @@ func (api *RetestethAPI) StorageRangeAt(ctx context.Context,
context := core.NewEVMContext(msg, block.Header(), api.blockchain, nil)
// Not yet the searched for transaction, execute on top of the current state
vmenv := vm.NewEVM(context, statedb, api.blockchain.Config(), vm.Config{})
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas())); err != nil {
var gp1559 *core.GasPool
if vmenv.ChainConfig().IsEIP1559(block.Number()) {
gp1559 = new(core.GasPool).AddGas(tx.Gas())
}
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()), gp1559); err != nil {
return StorageRangeResult{}, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
}
// Ensure any modifications are committed to the state
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestReimportMirroredState(t *testing.T) {
// We want to simulate an empty middle block, having the same state as the
// first one. The last is needs a state change again to force a reorg.
if i != 1 {
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil), signer, key)
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr), common.Address{0x00}, new(big.Int), params.TxGas, nil, nil, nil, nil), signer, key)
if err != nil {
panic(err)
}
Expand Down
96 changes: 64 additions & 32 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
errInvalidDifficulty = errors.New("non-positive difficulty")
errInvalidMixDigest = errors.New("invalid mix digest")
errInvalidPoW = errors.New("invalid proof-of-work")
errGasLimitSet = errors.New("GasLimit should not be set after EIP1559 has finalized")
)

// Author implements consensus.Engine, returning the header's coinbase as the
Expand Down Expand Up @@ -258,26 +259,34 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
if expected.Cmp(header.Difficulty) != 0 {
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
}
// Verify that the gas limit is <= 2^63-1
cap := uint64(0x7fffffffffffffff)
if header.GasLimit > cap {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, cap)
}
// Verify that the gasUsed is <= gasLimit
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
}

// Verify that the gas limit remains within allowed bounds
diff := int64(parent.GasLimit) - int64(header.GasLimit)
if diff < 0 {
diff *= -1
}
limit := parent.GasLimit / params.GasLimitBoundDivisor
// If EIP1559 is not active we need to verify that the GasLimit field is valid according to the legacy rules
if !chain.Config().IsEIP1559(header.Number) {
// Verify that the gas limit is <= 2^63-1
cap := uint64(0x7fffffffffffffff)
if header.GasLimit > cap {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, cap)
}
// Verify that the gasUsed is <= gasLimit
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
}

// Verify that the gas limit remains within allowed bounds
diff := int64(parent.GasLimit) - int64(header.GasLimit)
if diff < 0 {
diff *= -1
}
limit := parent.GasLimit / params.GasLimitBoundDivisor

if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
}
// If EIP1559 is active, assert that the GasLimit field is valid according to the EIP1559 rules
} else if err := misc.VerifyEIP1559GasLimit(chain.Config(), header); err != nil {
return err
}

// Verify that the block number is parent's +1
if diff := new(big.Int).Sub(header.Number, parent.Number); diff.Cmp(big.NewInt(1)) != 0 {
return consensus.ErrInvalidNumber
Expand All @@ -289,6 +298,9 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
}
}
// If all checks passed, validate any special fields for hard forks
if err := misc.VerifyEIP1559BaseFee(chain.Config(), header, parent); err != nil {
return err
}
if err := misc.VerifyDAOHeaderExtraData(chain.Config(), header); err != nil {
return err
}
Expand Down Expand Up @@ -583,21 +595,41 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainReader, header *t
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
hasher := sha3.NewLegacyKeccak256()

rlp.Encode(hasher, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra,
})
if header.BaseFee == nil {
rlp.Encode(hasher, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra,
})
} else {
rlp.Encode(hasher, []interface{}{
header.ParentHash,
header.UncleHash,
header.Coinbase,
header.Root,
header.TxHash,
header.ReceiptHash,
header.Bloom,
header.Difficulty,
header.Number,
header.GasLimit,
header.GasUsed,
header.Time,
header.Extra,
header.BaseFee,
})
}

hasher.Sum(hash[:0])
return hash
}
Expand Down
68 changes: 68 additions & 0 deletions consensus/misc/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@
package misc

import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
)

var (
errInvalidInitialBaseFee = fmt.Errorf("initial BaseFee must equal %d", params.EIP1559InitialBaseFee)
errInvalidBaseFee = errors.New("invalid BaseFee")
errMissingParentBaseFee = errors.New("parent header is missing BaseFee")
errMissingBaseFee = errors.New("current header is missing BaseFee")
errHaveBaseFee = fmt.Errorf("BaseFee should not be set before block %d", params.EIP1559ForkBlockNumber)
errInvalidEIP1559FinalizedGasLimit = fmt.Errorf("after EIP1559 finalization, GasLimit must equal %d", params.MaxGasEIP1559)
)

// VerifyForkHashes verifies that blocks conforming to network hard-forks do have
// the correct hashes, to avoid clients going off on different chains. This is an
// optional feature.
Expand All @@ -41,3 +52,60 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
// All ok, return
return nil
}

// VerifyEIP1559BaseFee verifies that the EIP1559 BaseFee field is valid for the current block height
func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Header) error {
// If we are at the EIP1559 fork block the BaseFee needs to be equal to params.EIP1559InitialBaseFee
if config.EIP1559Block != nil && config.EIP1559Block.Cmp(header.Number) == 0 {
if header.BaseFee == nil || header.BaseFee.Cmp(new(big.Int).SetUint64(params.EIP1559InitialBaseFee)) != 0 {
return errInvalidInitialBaseFee
}
return nil
}
// Verify the BaseFee is valid if we are past the EIP1559 activation block
if config.IsEIP1559(header.Number) {
// A valid BASEFEE is one such that abs(BASEFEE - PARENT_BASEFEE) <= max(1, PARENT_BASEFEE // BASEFEE_MAX_CHANGE_DENOMINATOR)
if parent.BaseFee == nil {
return errMissingParentBaseFee
}
if header.BaseFee == nil {
return errMissingBaseFee
}
diff := new(big.Int).Sub(header.BaseFee, parent.BaseFee)
if diff.Sign() < 0 {
diff.Neg(diff)
}
max := new(big.Int).Div(parent.BaseFee, new(big.Int).SetUint64(params.BaseFeeMaxChangeDenominator))
if max.Cmp(common.Big1) < 0 {
max = common.Big1
}
if diff.Cmp(max) > 0 {
return errInvalidBaseFee
}
return nil
}
// If we are before the EIP1559 activation block the current and parent BaseFees should be nil
if header.BaseFee != nil || parent.BaseFee != nil {
return errHaveBaseFee
}
return nil
}

// VerifyEIP1559GasLimit verifies that the header.GasLimit field is valid for the current block height
// Only call this after activation has been confirmed (config.IsEIP1559(header.Number) == true)
func VerifyEIP1559GasLimit(config *params.ChainConfig, header *types.Header) error {
// If EIP1559 has been finalized then header.GasLimit should be equal to the MaxGasEIP1559 (entire limit is in EIP1559 pool)
if config.IsEIP1559Finalized(header.Number) {
if header.GasLimit != params.MaxGasEIP1559 {
return errInvalidEIP1559FinalizedGasLimit
}
return nil
}
// Else if we are between activation and finalization, header.GasLimit must be valid based on the decay function
numOfIncrements := new(big.Int).Sub(header.Number, config.EIP1559Block).Uint64()
expectedGasLimit := (params.MaxGasEIP1559 / 2) + (numOfIncrements * params.EIP1559GasIncrementAmount)
if header.GasLimit != expectedGasLimit {
return fmt.Errorf("invalid GasLimit: have %d, need %d", header.GasLimit, expectedGasLimit)
}
return nil
}
Loading