@@ -24,14 +24,16 @@ import (
2424 "github.com/ethereum/go-ethereum/common"
2525 "github.com/ethereum/go-ethereum/common/math"
2626 "github.com/ethereum/go-ethereum/consensus/misc"
27+ "github.com/ethereum/go-ethereum/core/state"
28+ "github.com/ethereum/go-ethereum/core/systemcontracts"
2729 "github.com/ethereum/go-ethereum/core/types"
2830 "github.com/ethereum/go-ethereum/params"
2931)
3032
3133// VerifyEIP1559Header verifies some header attributes which were changed in EIP-1559,
3234// - gas limit check
3335// - basefee check
34- func VerifyEIP1559Header (config * params.ChainConfig , parent , header * types.Header ) error {
36+ func VerifyEIP1559Header (config * params.ChainConfig , parent , header * types.Header , state * state. StateDB ) error {
3537 // Verify that the gas limit remains within allowed bounds
3638 parentGasLimit := parent .GasLimit
3739 if ! config .IsLondon (parent .Number ) {
@@ -45,7 +47,7 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
4547 return errors .New ("header is missing baseFee" )
4648 }
4749 // Verify the baseFee is correct based on the parent header.
48- expectedBaseFee := CalcBaseFee (config , parent )
50+ expectedBaseFee := CalcBaseFee (config , parent , state )
4951 if header .BaseFee .Cmp (expectedBaseFee ) != 0 {
5052 return fmt .Errorf ("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d" ,
5153 header .BaseFee , expectedBaseFee , parent .BaseFee , parent .GasUsed )
@@ -54,12 +56,20 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade
5456}
5557
5658// CalcBaseFee calculates the basefee of the header.
57- func CalcBaseFee (config * params.ChainConfig , parent * types.Header ) * big.Int {
59+ func CalcBaseFee (config * params.ChainConfig , parent * types.Header , state * state. StateDB ) * big.Int {
5860 // If the current block is the first EIP-1559 block, return the InitialBaseFee.
5961 if ! config .IsLondon (parent .Number ) {
6062 return new (big.Int ).SetUint64 (params .InitialBaseFee )
6163 }
6264
65+ // Read baseFee from policy if baseFee is set in policy contract
66+ if state != nil {
67+ baseFee := state .GetState (systemcontracts .PolicyProxyHash , systemcontracts .GetBaseFeeStateHash ()).Big ()
68+ if baseFee .Cmp (common .Big0 ) > 0 {
69+ return baseFee
70+ }
71+ }
72+
6373 parentGasTarget := parent .GasLimit / config .ElasticityMultiplier ()
6474 // If the parent gasUsed is the same as the target, the baseFee remains unchanged.
6575 if parent .GasUsed == parentGasTarget {
0 commit comments