diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index b18c238e30..ffd8d9c63f 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -1902,6 +1902,95 @@ func TestSimulateV1(t *testing.T) { }}, }}, }, + { + name: "basefee-non-validation", + tag: latest, + blocks: []simBlock{{ + StateOverrides: &StateOverride{ + randomAccounts[2].addr: { + Code: hex2Bytes("3a489060005260205260406000f3"), + }, + }, + Calls: []TransactionArgs{{ + From: &accounts[0].addr, + To: &randomAccounts[2].addr, + // 0 gas price + }, { + From: &accounts[0].addr, + To: &randomAccounts[2].addr, + // non-zero gas price + MaxPriorityFeePerGas: newInt(1), + MaxFeePerGas: newInt(2), + }, + }, + }, { + BlockOverrides: &BlockOverrides{ + BaseFeePerGas: (*hexutil.Big)(big.NewInt(1)), + }, + Calls: []TransactionArgs{{ + From: &accounts[0].addr, + To: &randomAccounts[2].addr, + // 0 gas price + }, { + From: &accounts[0].addr, + To: &randomAccounts[2].addr, + // non-zero gas price + MaxPriorityFeePerGas: newInt(1), + MaxFeePerGas: newInt(2), + }, + }, + }, { + // Base fee should be 0 to zero even if it was set in previous block. + Calls: []TransactionArgs{{ + From: &accounts[0].addr, + To: &randomAccounts[2].addr, + }}, + }}, + want: []blockRes{{ + Number: "0xb", + GasLimit: "0x47e7c4", + GasUsed: "0xa44e", + Miner: coinbase, + Calls: []callRes{{ + ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + GasUsed: "0x5227", + Logs: []log{}, + Status: "0x1", + }, { + ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000", + GasUsed: "0x5227", + Logs: []log{}, + Status: "0x1", + }}, + }, { + Number: "0xc", + GasLimit: "0x47e7c4", + GasUsed: "0xa44e", + Miner: coinbase, + Calls: []callRes{{ + ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", + GasUsed: "0x5227", + Logs: []log{}, + Status: "0x1", + }, { + ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001", + GasUsed: "0x5227", + Logs: []log{}, + Status: "0x1", + }}, + }, { + Number: "0xd", + GasLimit: "0x47e7c4", + GasUsed: "0x5227", + Miner: coinbase, + Calls: []callRes{{ + ReturnValue: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + GasUsed: "0x5227", + Logs: []log{}, + Status: "0x1", + }}, + }}, + }, } for _, tc := range testSuite { diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index 79178e8222..f6c41a8654 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -136,9 +136,15 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header, // Parent hash is needed for evm.GetHashFn to work. header.ParentHash = parent.Hash() if config.IsLondon(header.Number) { + // In non-validation mode base fee is set to 0 if it is not overridden. + // This is because it creates an edge case in EVM where gasPrice < baseFee. // Base fee could have been overridden. if header.BaseFee == nil { - header.BaseFee = eip1559.CalcBaseFee(config, parent) + if sim.validate { + header.BaseFee = eip1559.CalcBaseFee(config, parent) + } else { + header.BaseFee = big.NewInt(0) + } } } if config.IsCancun(header.Number, header.Time) {