From 1684eaec9990450b4ff46dda2dec81863f454b0a Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Tue, 29 Apr 2025 15:49:50 +0530 Subject: [PATCH] core: fixed calls to NewEVM and call --- accounts/abi/bind/backends/simulated.go | 3 +-- consensus/bor/statefull/processor.go | 6 +++--- core/parallel_state_processor.go | 4 ++-- core/state_processor.go | 4 ++-- eth/tracers/api_bor.go | 3 +-- eth/tracers/api_test.go | 5 ++--- miner/worker.go | 6 +++--- 7 files changed, 14 insertions(+), 17 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index ba92dc02c4..597fad5d8b 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -707,9 +707,8 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM // Create a new environment which holds all relevant information // about the transaction and calling mechanisms. - txContext := core.NewEVMTxContext(msg) evmContext := core.NewEVMBlockContext(header, b.blockchain, nil) - vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true}) + vmEnv := vm.NewEVM(evmContext, stateDB, b.config, vm.Config{NoBaseFee: true}) gasPool := new(core.GasPool).AddGas(gomath.MaxUint64) return core.ApplyMessage(vmEnv, msg, gasPool, context.Background()) diff --git a/consensus/bor/statefull/processor.go b/consensus/bor/statefull/processor.go index d208125c1f..a58193e3f6 100644 --- a/consensus/bor/statefull/processor.go +++ b/consensus/bor/statefull/processor.go @@ -81,12 +81,12 @@ func ApplyMessage( // Create a new environment which holds all relevant information // about the transaction and calling mechanisms. - vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{}) + vmenv := vm.NewEVM(blockContext, state, chainConfig, vm.Config{}) // nolint : contextcheck // Apply the transaction to the current state (included in the env) ret, gasLeft, err := vmenv.Call( - vm.AccountRef(msg.From()), + msg.From(), *msg.To(), msg.Data(), msg.Gas(), @@ -124,7 +124,7 @@ func ApplyBorMessage(vmenv *vm.EVM, msg Callmsg) (*core.ExecutionResult, error) // Apply the transaction to the current state (included in the env) ret, gasLeft, err := vmenv.Call( - vm.AccountRef(msg.From()), + msg.From(), *msg.To(), msg.Data(), msg.Gas(), diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index 4dff3b7c67..3e58530f59 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -100,7 +100,7 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er task.statedb.SetMVHashmap(mvh) task.statedb.SetIncarnation(incarnation) - evm := vm.NewEVM(task.blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig) + evm := vm.NewEVM(task.blockContext, task.statedb, task.config, task.evmConfig) // Create a new context to be used in the EVM environment. txContext := NewEVMTxContext(&task.msg) @@ -303,7 +303,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat blockContext := NewEVMBlockContext(header, p.bc, nil) context := NewEVMBlockContext(header, p.bc.hc, nil) - vmenv := vm.NewEVM(context, vm.TxContext{}, statedb, p.config, cfg) + vmenv := vm.NewEVM(context, statedb, p.config, cfg) var tracingStateDB = vm.StateDB(statedb) if hooks := cfg.Tracer; hooks != nil { tracingStateDB = state.NewHookedState(statedb, hooks) diff --git a/core/state_processor.go b/core/state_processor.go index e8478d7aab..99a880b116 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -294,7 +294,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) { } evm.SetTxContext(NewEVMTxContext(msg)) evm.StateDB.AddAddressToAccessList(params.BeaconRootsAddress) - _, _, _ = evm.Call(msg.From, *msg.To, msg.Data, 30_000_000, common.U2560) + _, _, _ = evm.Call(msg.From, *msg.To, msg.Data, 30_000_000, common.U2560, nil) evm.StateDB.Finalise(true) } @@ -357,7 +357,7 @@ func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte } evm.SetTxContext(NewEVMTxContext(msg)) evm.StateDB.AddAddressToAccessList(addr) - ret, _, _ := evm.Call(msg.From, *msg.To, msg.Data, 30_000_000, common.U2560) + ret, _, _ := evm.Call(msg.From, *msg.To, msg.Data, 30_000_000, common.U2560, nil) evm.StateDB.Finalise(true) if len(ret) == 0 { return // skip empty output diff --git a/eth/tracers/api_bor.go b/eth/tracers/api_bor.go index 0b1408ecc3..856d356d57 100644 --- a/eth/tracers/api_bor.go +++ b/eth/tracers/api_bor.go @@ -77,7 +77,6 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T traceTxn := func(indx int, tx *types.Transaction, borTx bool, stateSyncHash common.Hash) *TxTraceResult { message, _ := core.TransactionToMessage(tx, signer, block.BaseFee()) - txContext := core.NewEVMTxContext(message) txHash := tx.Hash() if borTx { txHash = stateSyncHash @@ -86,7 +85,7 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T tracer := logger.NewStructLogger(config.Config) // Run the transaction with tracing enabled. - vmenv := vm.NewEVM(blockCtx, txContext, statedb, api.backend.ChainConfig(), vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true}) + vmenv := vm.NewEVM(blockCtx, statedb, api.backend.ChainConfig(), vm.Config{Tracer: tracer.Hooks(), NoBaseFee: true}) // Call Prepare to clear out the statedb access list // Not sure if we need to do this diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index e28689a3ce..c63c6aecfc 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -187,11 +187,10 @@ func (b *testBackend) StateAtTransaction(ctx context.Context, block *types.Block } // Recompute transactions up to the target index. signer := types.MakeSigner(b.chainConfig, block.Number(), block.Time()) - context := core.NewEVMBlockContext(block.Header(), b.chain, nil) - evm := vm.NewEVM(context, statedb, b.chainConfig, vm.Config{}) + blockContext := core.NewEVMBlockContext(block.Header(), b.chain, nil) + evm := vm.NewEVM(blockContext, statedb, b.chainConfig, vm.Config{}) for idx, tx := range block.Transactions() { msg, _ := core.TransactionToMessage(tx, signer, block.BaseFee()) - txContext := core.NewEVMTxContext(msg) blockContext := core.NewEVMBlockContext(block.Header(), b.chain, nil) if idx == txIndex { diff --git a/miner/worker.go b/miner/worker.go index aab3b49e39..f45294dcf3 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1306,12 +1306,12 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm } if header.ParentBeaconRoot != nil { context := core.NewEVMBlockContext(header, w.chain, nil) - vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{}) + vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{}) core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state) } if w.chainConfig.IsPrague(header.Number) { context := core.NewEVMBlockContext(header, w.chain, nil) - vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{}) + vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{}) core.ProcessParentBlockHash(header.ParentHash, vmenv, env.state) } return env, nil @@ -1437,7 +1437,7 @@ func (w *worker) generateWork(params *generateParams, witness bool) *newPayloadR requests = append(requests, depositRequests) // create EVM for system calls blockContext := core.NewEVMBlockContext(work.header, w.chain, &work.header.Coinbase) - vmenv := vm.NewEVM(blockContext, vm.TxContext{}, work.state, w.chainConfig, vm.Config{}) + vmenv := vm.NewEVM(blockContext, work.state, w.chainConfig, vm.Config{}) // EIP-7002 withdrawals withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, work.state) requests = append(requests, withdrawalRequests)