core: fixed calls to NewEVM and call

This commit is contained in:
Pratik Patil 2025-04-29 15:49:50 +05:30
parent c23db04a2d
commit 1684eaec99
No known key found for this signature in database
GPG key ID: AFDCA496554874B3
7 changed files with 14 additions and 17 deletions

View file

@ -707,9 +707,8 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// Create a new environment which holds all relevant information // Create a new environment which holds all relevant information
// about the transaction and calling mechanisms. // about the transaction and calling mechanisms.
txContext := core.NewEVMTxContext(msg)
evmContext := core.NewEVMBlockContext(header, b.blockchain, nil) 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) gasPool := new(core.GasPool).AddGas(gomath.MaxUint64)
return core.ApplyMessage(vmEnv, msg, gasPool, context.Background()) return core.ApplyMessage(vmEnv, msg, gasPool, context.Background())

View file

@ -81,12 +81,12 @@ func ApplyMessage(
// Create a new environment which holds all relevant information // Create a new environment which holds all relevant information
// about the transaction and calling mechanisms. // 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 // nolint : contextcheck
// Apply the transaction to the current state (included in the env) // Apply the transaction to the current state (included in the env)
ret, gasLeft, err := vmenv.Call( ret, gasLeft, err := vmenv.Call(
vm.AccountRef(msg.From()), msg.From(),
*msg.To(), *msg.To(),
msg.Data(), msg.Data(),
msg.Gas(), 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) // Apply the transaction to the current state (included in the env)
ret, gasLeft, err := vmenv.Call( ret, gasLeft, err := vmenv.Call(
vm.AccountRef(msg.From()), msg.From(),
*msg.To(), *msg.To(),
msg.Data(), msg.Data(),
msg.Gas(), msg.Gas(),

View file

@ -100,7 +100,7 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er
task.statedb.SetMVHashmap(mvh) task.statedb.SetMVHashmap(mvh)
task.statedb.SetIncarnation(incarnation) 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. // Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(&task.msg) txContext := NewEVMTxContext(&task.msg)
@ -303,7 +303,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
blockContext := NewEVMBlockContext(header, p.bc, nil) blockContext := NewEVMBlockContext(header, p.bc, nil)
context := NewEVMBlockContext(header, p.bc.hc, 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) var tracingStateDB = vm.StateDB(statedb)
if hooks := cfg.Tracer; hooks != nil { if hooks := cfg.Tracer; hooks != nil {
tracingStateDB = state.NewHookedState(statedb, hooks) tracingStateDB = state.NewHookedState(statedb, hooks)

View file

@ -294,7 +294,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) {
} }
evm.SetTxContext(NewEVMTxContext(msg)) evm.SetTxContext(NewEVMTxContext(msg))
evm.StateDB.AddAddressToAccessList(params.BeaconRootsAddress) 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) evm.StateDB.Finalise(true)
} }
@ -357,7 +357,7 @@ func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte
} }
evm.SetTxContext(NewEVMTxContext(msg)) evm.SetTxContext(NewEVMTxContext(msg))
evm.StateDB.AddAddressToAccessList(addr) 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) evm.StateDB.Finalise(true)
if len(ret) == 0 { if len(ret) == 0 {
return // skip empty output return // skip empty output

View file

@ -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 { traceTxn := func(indx int, tx *types.Transaction, borTx bool, stateSyncHash common.Hash) *TxTraceResult {
message, _ := core.TransactionToMessage(tx, signer, block.BaseFee()) message, _ := core.TransactionToMessage(tx, signer, block.BaseFee())
txContext := core.NewEVMTxContext(message)
txHash := tx.Hash() txHash := tx.Hash()
if borTx { if borTx {
txHash = stateSyncHash txHash = stateSyncHash
@ -86,7 +85,7 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T
tracer := logger.NewStructLogger(config.Config) tracer := logger.NewStructLogger(config.Config)
// Run the transaction with tracing enabled. // 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 // Call Prepare to clear out the statedb access list
// Not sure if we need to do this // Not sure if we need to do this

View file

@ -187,11 +187,10 @@ func (b *testBackend) StateAtTransaction(ctx context.Context, block *types.Block
} }
// Recompute transactions up to the target index. // Recompute transactions up to the target index.
signer := types.MakeSigner(b.chainConfig, block.Number(), block.Time()) signer := types.MakeSigner(b.chainConfig, block.Number(), block.Time())
context := core.NewEVMBlockContext(block.Header(), b.chain, nil) blockContext := core.NewEVMBlockContext(block.Header(), b.chain, nil)
evm := vm.NewEVM(context, statedb, b.chainConfig, vm.Config{}) evm := vm.NewEVM(blockContext, statedb, b.chainConfig, vm.Config{})
for idx, tx := range block.Transactions() { for idx, tx := range block.Transactions() {
msg, _ := core.TransactionToMessage(tx, signer, block.BaseFee()) msg, _ := core.TransactionToMessage(tx, signer, block.BaseFee())
txContext := core.NewEVMTxContext(msg)
blockContext := core.NewEVMBlockContext(block.Header(), b.chain, nil) blockContext := core.NewEVMBlockContext(block.Header(), b.chain, nil)
if idx == txIndex { if idx == txIndex {

View file

@ -1306,12 +1306,12 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
} }
if header.ParentBeaconRoot != nil { if header.ParentBeaconRoot != nil {
context := core.NewEVMBlockContext(header, w.chain, 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) core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
} }
if w.chainConfig.IsPrague(header.Number) { if w.chainConfig.IsPrague(header.Number) {
context := core.NewEVMBlockContext(header, w.chain, 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.ProcessParentBlockHash(header.ParentHash, vmenv, env.state) core.ProcessParentBlockHash(header.ParentHash, vmenv, env.state)
} }
return env, nil return env, nil
@ -1437,7 +1437,7 @@ func (w *worker) generateWork(params *generateParams, witness bool) *newPayloadR
requests = append(requests, depositRequests) requests = append(requests, depositRequests)
// create EVM for system calls // create EVM for system calls
blockContext := core.NewEVMBlockContext(work.header, w.chain, &work.header.Coinbase) 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 // EIP-7002 withdrawals
withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, work.state) withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, work.state)
requests = append(requests, withdrawalRequests) requests = append(requests, withdrawalRequests)