Skip to content

Commit d15006b

Browse files
authored
Merge pull request #19 from vulcanize/calc_gas_limit
Calc gas limit
2 parents 7842864 + 3187d3f commit d15006b

File tree

17 files changed

+184
-52
lines changed

17 files changed

+184
-52
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
337337
gaspool := new(core.GasPool).AddGas(math.MaxUint64)
338338
var gp1559 *core.GasPool
339339
if b.config.IsEIP1559(block.Number()) {
340-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
340+
gp1559 = new(core.GasPool).AddGas(math.MaxUint64)
341341
}
342342

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

cmd/geth/retesteth.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,16 @@ func (api *RetestethAPI) mineBlock() error {
491491
if api.chainConfig.DAOForkSupport && api.chainConfig.DAOForkBlock != nil && api.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
492492
misc.ApplyDAOHardFork(statedb)
493493
}
494-
gasPool := new(core.GasPool).AddGas(header.GasLimit)
494+
495495
var gp1559 *core.GasPool
496+
var gasPool *core.GasPool
496497
if api.chainConfig.IsEIP1559(header.Number) {
497-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
498+
gasPool = new(core.GasPool).AddGas(params.MaxGasEIP1559 - header.GasLimit)
499+
gp1559 = new(core.GasPool).AddGas(header.GasLimit)
500+
} else {
501+
gasPool = new(core.GasPool).AddGas(header.GasLimit)
498502
}
503+
499504
txCount := 0
500505
var txs []*types.Transaction
501506
var receipts []*types.Receipt
@@ -664,7 +669,7 @@ func (api *RetestethAPI) AccountRange(ctx context.Context,
664669
vmenv := vm.NewEVM(context, statedb, api.blockchain.Config(), vm.Config{})
665670
var gp1559 *core.GasPool
666671
if vmenv.ChainConfig().IsEIP1559(block.Number()) {
667-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
672+
gp1559 = new(core.GasPool).AddGas(tx.Gas())
668673
}
669674
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()), gp1559); err != nil {
670675
return AccountRangeResult{}, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)
@@ -781,7 +786,7 @@ func (api *RetestethAPI) StorageRangeAt(ctx context.Context,
781786
vmenv := vm.NewEVM(context, statedb, api.blockchain.Config(), vm.Config{})
782787
var gp1559 *core.GasPool
783788
if vmenv.ChainConfig().IsEIP1559(block.Number()) {
784-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
789+
gp1559 = new(core.GasPool).AddGas(tx.Gas())
785790
}
786791
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()), gp1559); err != nil {
787792
return StorageRangeResult{}, fmt.Errorf("transaction %#x failed: %v", tx.Hash(), err)

consensus/ethash/consensus.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
260260
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
261261
}
262262

263-
// If we have not reached the EIP1559 finalization block we need to verify that the GasLimit field is valid
264-
if !chain.Config().IsEIP1559Finalized(header.Number) {
263+
// If EIP1559 is not active we need to verify that the GasLimit field is valid according to the legacy rules
264+
if !chain.Config().IsEIP1559(header.Number) {
265265
// Verify that the gas limit is <= 2^63-1
266266
cap := uint64(0x7fffffffffffffff)
267267
if header.GasLimit > cap {
@@ -282,9 +282,9 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
282282
if uint64(diff) >= limit || header.GasLimit < params.MinGasLimit {
283283
return fmt.Errorf("invalid gas limit: have %d, want %d += %d", header.GasLimit, parent.GasLimit, limit)
284284
}
285-
} else if header.GasLimit != 0 {
286-
// If EIP1559 is finalized, GasLimit should be 0
287-
return errGasLimitSet
285+
// If EIP1559 is active, assert that the GasLimit field is valid according to the EIP1559 rules
286+
} else if err := misc.VerifyEIP1559GasLimit(chain.Config(), header); err != nil {
287+
return err
288288
}
289289

290290
// Verify that the block number is parent's +1

consensus/misc/forks.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ import (
2727
)
2828

2929
var (
30-
errInvalidInitialBaseFee = fmt.Errorf("initial BaseFee must equal %d", params.EIP1559InitialBaseFee)
31-
errInvalidBaseFee = errors.New("invalid BaseFee")
32-
errMissingParentBaseFee = errors.New("parent header is missing BaseFee")
33-
errMissingBaseFee = errors.New("current header is missing BaseFee")
34-
errHaveBaseFee = fmt.Errorf("BaseFee should not be set before block %d", params.EIP1559ForkBlockNumber)
30+
errInvalidInitialBaseFee = fmt.Errorf("initial BaseFee must equal %d", params.EIP1559InitialBaseFee)
31+
errInvalidBaseFee = errors.New("invalid BaseFee")
32+
errMissingParentBaseFee = errors.New("parent header is missing BaseFee")
33+
errMissingBaseFee = errors.New("current header is missing BaseFee")
34+
errHaveBaseFee = fmt.Errorf("BaseFee should not be set before block %d", params.EIP1559ForkBlockNumber)
35+
errInvalidEIP1559FinalizedGasLimit = fmt.Errorf("after EIP1559 finalization, GasLimit must equal %d", params.MaxGasEIP1559)
3536
)
3637

3738
// VerifyForkHashes verifies that blocks conforming to network hard-forks do have
@@ -61,7 +62,7 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
6162
}
6263
return nil
6364
}
64-
// Verify the BaseFee is valid if we are past the EIP1559 initialization block
65+
// Verify the BaseFee is valid if we are past the EIP1559 activation block
6566
if config.IsEIP1559(header.Number) {
6667
// A valid BASEFEE is one such that abs(BASEFEE - PARENT_BASEFEE) <= max(1, PARENT_BASEFEE // BASEFEE_MAX_CHANGE_DENOMINATOR)
6768
if parent.BaseFee == nil {
@@ -83,9 +84,28 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
8384
}
8485
return nil
8586
}
86-
// If we are before the EIP1559 initialization block the current and parent BaseFees should be nil
87+
// If we are before the EIP1559 activation block the current and parent BaseFees should be nil
8788
if header.BaseFee != nil || parent.BaseFee != nil {
8889
return errHaveBaseFee
8990
}
9091
return nil
9192
}
93+
94+
// VerifyEIP1559GasLimit verifies that the header.GasLimit field is valid for the current block height
95+
// Only call this after activation has been confirmed (config.IsEIP1559(header.Number) == true)
96+
func VerifyEIP1559GasLimit(config *params.ChainConfig, header *types.Header) error {
97+
// If EIP1559 has been finalized then header.GasLimit should be equal to the MaxGasEIP1559 (entire limit is in EIP1559 pool)
98+
if config.IsEIP1559Finalized(header.Number) {
99+
if header.GasLimit != params.MaxGasEIP1559 {
100+
return errInvalidEIP1559FinalizedGasLimit
101+
}
102+
return nil
103+
}
104+
// Else if we are between activation and finalization, header.GasLimit must be valid based on the decay function
105+
numOfIncrements := new(big.Int).Sub(header.Number, config.EIP1559Block).Uint64()
106+
expectedGasLimit := (params.MaxGasEIP1559 / 2) + (numOfIncrements * params.EIP1559GasIncrementAmount)
107+
if header.GasLimit != expectedGasLimit {
108+
return fmt.Errorf("invalid GasLimit: have %d, need %d", header.GasLimit, expectedGasLimit)
109+
}
110+
return nil
111+
}

core/block_validator.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package core
1818

1919
import (
2020
"fmt"
21+
"math/big"
22+
23+
"github.com/ethereum/go-ethereum/common"
2124

2225
"github.com/ethereum/go-ethereum/consensus"
2326
"github.com/ethereum/go-ethereum/core/state"
@@ -137,3 +140,65 @@ func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
137140
}
138141
return limit
139142
}
143+
144+
func CalcGasLimitAndBaseFee(config *params.ChainConfig, parent *types.Block, gasFloor, gasCeil uint64) (uint64, *big.Int) {
145+
if !config.IsEIP1559(new(big.Int).Add(parent.Number(), common.Big1)) {
146+
return CalcGasLimit(parent, gasFloor, gasCeil), nil
147+
}
148+
return calcGasLimitAndBaseFee(config, parent)
149+
}
150+
151+
// start at 50 : 50 and then shift to 0 : 100
152+
// calcGasLimitAndBaseFee returns the EIP1559GasLimit and the BaseFee
153+
// The GasLimit for the legacy pool is (params.MaxGasEIP1559 - EIP1559GasLimit)
154+
func calcGasLimitAndBaseFee(config *params.ChainConfig, parent *types.Block) (uint64, *big.Int) {
155+
// panic if we do not have a block number set for EIP1559 activation
156+
if config.EIP1559Block == nil {
157+
panic("chain config is missing EIP1559Block")
158+
}
159+
height := new(big.Int).Add(parent.Number(), common.Big1)
160+
161+
// If we are at the block of EIP1559 activation then the BaseFee is set to the initial value
162+
// and the GasLimit is split evenly between the two pools
163+
if config.EIP1559Block.Cmp(height) == 0 {
164+
return params.MaxGasEIP1559 / 2, new(big.Int).SetUint64(params.EIP1559InitialBaseFee)
165+
}
166+
167+
/*
168+
Otherwise, calculate the BaseFee
169+
As a default strategy, miners set BASEFEE as follows. Let delta = block.gas_used - TARGET_GASUSED (possibly negative).
170+
Set BASEFEE = PARENT_BASEFEE + PARENT_BASEFEE * delta // TARGET_GASUSED // BASEFEE_MAX_CHANGE_DENOMINATOR,
171+
clamping this result inside of the allowable bounds if needed (with the parameter setting above clamping will not be required).
172+
*/
173+
174+
delta := new(big.Int).Sub(new(big.Int).SetUint64(parent.GasUsed()), new(big.Int).SetUint64(params.TargetGasUsed))
175+
mul := new(big.Int).Mul(parent.BaseFee(), delta)
176+
div := new(big.Int).Div(mul, new(big.Int).SetUint64(params.TargetGasUsed))
177+
div2 := new(big.Int).Div(div, new(big.Int).SetUint64(params.BaseFeeMaxChangeDenominator))
178+
baseFee := new(big.Int).Add(parent.BaseFee(), div2)
179+
180+
// Panic is the BaseFee is not valid
181+
// A valid BASEFEE is one such that abs(BASEFEE - PARENT_BASEFEE) <= max(1, PARENT_BASEFEE // BASEFEE_MAX_CHANGE_DENOMINATOR)
182+
diff := new(big.Int).Sub(baseFee, parent.BaseFee())
183+
if diff.Sign() < 0 {
184+
diff.Neg(diff)
185+
}
186+
max := new(big.Int).Div(parent.BaseFee(), new(big.Int).SetUint64(params.BaseFeeMaxChangeDenominator))
187+
if max.Cmp(common.Big1) < 0 {
188+
max = common.Big1
189+
}
190+
if diff.Cmp(max) > 0 {
191+
panic("invalid BaseFee")
192+
}
193+
194+
// If EIP1559 is finalized, our limit for the EIP1559 pool is the entire max limit
195+
if config.IsEIP1559Finalized(new(big.Int).Add(parent.Number(), common.Big1)) {
196+
return params.MaxGasEIP1559, baseFee
197+
}
198+
199+
// Otherwise calculate how much of the MaxGasEIP1559 serves as the limit for the EIP1559 pool
200+
// The GasLimit for the legacy pool is (params.MaxGasEIP1559 - eip1559GasLimit)
201+
numOfIncrements := new(big.Int).Sub(height, config.EIP1559Block).Uint64()
202+
eip1559GasLimit := (params.MaxGasEIP1559 / 2) + (numOfIncrements * params.EIP1559GasIncrementAmount)
203+
return eip1559GasLimit, baseFee
204+
}

core/chain_makers.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ func (b *BlockGen) SetCoinbase(addr common.Address) {
5959
panic("coinbase can only be set once")
6060
}
6161
b.header.Coinbase = addr
62-
b.gasPool = new(GasPool).AddGas(b.header.GasLimit)
62+
// If EIP1559 is initialized then header.GasLimit is for the EIP1559 pool
63+
// and the difference between the MaxGasEIP1559 and header.GasLimit is the limit for the legacy pool
64+
// Once EIP1559 is finalized the header.GasLimit is the entire MaxGasEIP1559
65+
// so no gas will be allocated to the legacy pool
66+
if b.config.IsEIP1559(b.header.Number) {
67+
b.gasPool = new(GasPool).AddGas(params.MaxGasEIP1559 - b.header.GasLimit)
68+
b.gasPool1559 = new(GasPool).AddGas(b.header.GasLimit)
69+
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
70+
b.gasPool = new(GasPool).AddGas(b.header.GasLimit)
71+
}
6372
}
6473

6574
// SetExtra sets the extra data field of the generated block.
@@ -103,9 +112,7 @@ func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
103112
if b.gasPool == nil {
104113
b.SetCoinbase(common.Address{})
105114
}
106-
if b.gasPool1559 == nil && b.config.IsEIP1559(b.header.Number) {
107-
b.gasPool1559 = new(GasPool).AddGas(params.MaxGasEIP1559)
108-
}
115+
109116
b.statedb.Prepare(tx.Hash(), common.Hash{}, len(b.txs))
110117
receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.gasPool1559, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
111118
if err != nil {
@@ -252,6 +259,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
252259
time = parent.Time() + 10 // block time is fixed at 10 seconds
253260
}
254261

262+
gasLimit, baseFee := CalcGasLimitAndBaseFee(chain.Config(), parent, parent.GasLimit(), parent.GasLimit())
255263
return &types.Header{
256264
Root: state.IntermediateRoot(chain.Config().IsEIP158(parent.Number())),
257265
ParentHash: parent.Hash(),
@@ -262,7 +270,8 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
262270
Difficulty: parent.Difficulty(),
263271
UncleHash: parent.UncleHash(),
264272
}),
265-
GasLimit: CalcGasLimit(parent, parent.GasLimit(), parent.GasLimit()),
273+
GasLimit: gasLimit,
274+
BaseFee: baseFee,
266275
Number: new(big.Int).Add(parent.Number(), common.Big1),
267276
Time: time,
268277
}

core/state_prefetcher.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,18 @@ func newStatePrefetcher(config *params.ChainConfig, bc *BlockChain, engine conse
5151
func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, cfg vm.Config, interrupt *uint32) {
5252
var (
5353
header = block.Header()
54-
gaspool = new(GasPool).AddGas(block.GasLimit())
54+
gaspool *GasPool
5555
gp1559 *GasPool
5656
)
57+
// If EIP1559 is initialized then header.GasLimit is for the EIP1559 pool
58+
// and the difference between the MaxGasEIP1559 and header.GasLimit is the limit for the legacy pool
59+
// Once EIP1559 is finalized the header.GasLimit is the entire MaxGasEIP1559
60+
// so no gas will be allocated to the legacy pool
5761
if p.config.IsEIP1559(block.Number()) {
58-
gp1559 = new(GasPool).AddGas(params.MaxGasEIP1559)
62+
gaspool = new(GasPool).AddGas(params.MaxGasEIP1559 - block.GasLimit())
63+
gp1559 = new(GasPool).AddGas(block.GasLimit())
64+
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
65+
gaspool = new(GasPool).AddGas(block.GasLimit())
5966
}
6067
// Iterate over and process the individual transactions
6168
for i, tx := range block.Transactions() {

core/state_processor.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
5959
usedGas = new(uint64)
6060
header = block.Header()
6161
allLogs []*types.Log
62-
gp = new(GasPool).AddGas(block.GasLimit())
62+
gp *GasPool
6363
gp1559 *GasPool
6464
)
65+
// If EIP1559 is initialized then header.GasLimit is for the EIP1559 pool
66+
// and the difference between the MaxGasEIP1559 and header.GasLimit is the limit for the legacy pool
67+
// Once EIP1559 is finalized the header.GasLimit is the entire MaxGasEIP1559
68+
// so no gas will be allocated to the legacy pool
6569
if p.config.IsEIP1559(block.Number()) {
66-
gp1559 = new(GasPool).AddGas(params.MaxGasEIP1559)
70+
gp = new(GasPool).AddGas(params.MaxGasEIP1559 - block.GasLimit())
71+
gp1559 = new(GasPool).AddGas(block.GasLimit())
72+
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
73+
gp = new(GasPool).AddGas(block.GasLimit())
6774
}
75+
6876
// Mutate the block and state according to any hard-fork specs
6977
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
7078
misc.ApplyDAOHardFork(statedb)

core/state_transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ func (st *StateTransition) preCheck() error {
223223
if st.evm.ChainConfig().IsEIP1559Finalized(st.evm.BlockNumber) && !st.isEIP1559 {
224224
return ErrTxNotEIP1559
225225
}
226-
// If we are before the EIP1559 initialization block, throw an error if we have EIP1559 fields or do not have a GasPrice
226+
// If we are before the EIP1559 activation block, throw an error if we have EIP1559 fields or do not have a GasPrice
227227
if !st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil || st.gp1559 != nil || st.evm.BaseFee != nil || st.msg.GasPrice() == nil) {
228228
return ErrTxIsEIP1559
229229
}
230230
// If transaction has both legacy and EIP1559 fields, throw an error
231231
if (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil) && st.msg.GasPrice() != nil {
232232
return ErrTxSetsLegacyAndEIP1559Fields
233233
}
234-
// We need a BaseFee if we are past EIP1559 initialization
234+
// We need a BaseFee if we are past EIP1559 activation
235235
if st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && st.evm.BaseFee == nil {
236236
return ErrNoBaseFee
237237
}

core/tx_pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ var (
8181
// and the input transaction does not conform to with EIP1559
8282
ErrTxNotEIP1559 = fmt.Errorf("after block %d EIP1559 is finalized and transactions must contain a GasPremium and FeeCap and not contain a GasPrice", params.EIP1559ForkFinalizedBlockNumber)
8383

84-
// ErrTxIsEIP1559 is returned if we have not reached the EIP1559 initialization block height
84+
// ErrTxIsEIP1559 is returned if we have not reached the EIP1559 activation block height
8585
// and the input transaction is not of the legacy type
8686
ErrTxIsEIP1559 = fmt.Errorf("before block %d EIP1559 is not activated and transactions must contain a GasPrice and not contain a GasPremium or FeeCap", params.EIP1559ForkBlockNumber)
8787

8888
// ErrTxSetsLegacyAndEIP1559Fields is returned if a transaction attempts to set
8989
// both legacy (GasPrice) and EIP1559 (GasPremium and FeeCap) fields
9090
ErrTxSetsLegacyAndEIP1559Fields = errors.New("transaction sets both legacy and EIP1559 fields")
9191

92-
// ErrNoBaseFee is returned if we are past the EIP1559 initialization block but
92+
// ErrNoBaseFee is returned if we are past the EIP1559 activation block but
9393
// the current header does not provide a BaseFee
9494
ErrNoBaseFee = errors.New("current header does not provide the BaseFee needed to process EIP1559 transactions")
9595

eth/api_tracer.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828
"sync"
2929
"time"
3030

31-
"github.com/ethereum/go-ethereum/params"
32-
3331
"github.com/ethereum/go-ethereum/common"
3432
"github.com/ethereum/go-ethereum/common/hexutil"
3533
"github.com/ethereum/go-ethereum/core"
@@ -505,7 +503,7 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
505503
vmctx := core.NewEVMContext(msg, block.Header(), api.eth.blockchain, nil)
506504

507505
if api.eth.blockchain.Config().IsEIP1559(block.Number()) {
508-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
506+
gp1559 = new(core.GasPool).AddGas(msg.Gas())
509507
}
510508
vmenv := vm.NewEVM(vmctx, statedb, api.eth.blockchain.Config(), vm.Config{})
511509
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()), gp1559); err != nil {
@@ -604,7 +602,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
604602
// Execute the transaction and flush any traces to disk
605603
vmenv := vm.NewEVM(vmctx, statedb, api.eth.blockchain.Config(), vmConf)
606604
if api.eth.blockchain.Config().IsEIP1559(block.Number()) {
607-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
605+
gp1559 = new(core.GasPool).AddGas(msg.Gas())
608606
}
609607
_, _, _, err = core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()), gp1559)
610608
if writer != nil {
@@ -740,7 +738,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
740738
gp1559 *core.GasPool
741739
)
742740
if api.eth.blockchain.Config().IsEIP1559(vmctx.BlockNumber) {
743-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
741+
gp1559 = new(core.GasPool).AddGas(message.Gas())
744742
}
745743
switch {
746744
case config != nil && config.Tracer != nil:
@@ -826,7 +824,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
826824
}
827825
var gp1559 *core.GasPool
828826
if api.eth.blockchain.Config().IsEIP1559(block.Number()) {
829-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
827+
gp1559 = new(core.GasPool).AddGas(tx.Gas())
830828
}
831829
// Not yet the searched for transaction, execute on top of the current state
832830
vmenv := vm.NewEVM(context, statedb, api.eth.blockchain.Config(), vm.Config{})

eth/tracers/tracers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func TestCallTracer(t *testing.T) {
259259
}
260260
var gp1559 *core.GasPool
261261
if test.Genesis.Config.IsEIP1559(context.BlockNumber) {
262-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
262+
gp1559 = new(core.GasPool).AddGas(tx.Gas())
263263
}
264264
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.Gas()), gp1559)
265265
if _, _, _, err = st.TransitionDb(); err != nil {

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
882882
gp := new(core.GasPool).AddGas(math.MaxUint64)
883883
var gp1559 *core.GasPool
884884
if evm.ChainConfig().IsEIP1559(header.Number) {
885-
gp1559 = new(core.GasPool).AddGas(params.MaxGasEIP1559)
885+
gp1559 = new(core.GasPool).AddGas(math.MaxUint64)
886886
}
887887
res, gas, failed, err := core.ApplyMessage(evm, msg, gp, gp1559)
888888
if err := vmError(); err != nil {

0 commit comments

Comments
 (0)