@@ -74,18 +74,18 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
7474 )
7575
7676 // Apply pre-execution system calls.
77- context = NewEVMBlockContext (header , p .chain , nil )
78-
79- vmenv := vm .NewEVM (context , vm.TxContext {}, statedb , p .config , cfg )
8077 var tracingStateDB = vm .StateDB (statedb )
8178 if hooks := cfg .Tracer ; hooks != nil {
8279 tracingStateDB = state .NewHookedState (statedb , hooks )
8380 }
81+ context = NewEVMBlockContext (header , p .chain , nil )
82+ evm := vm .NewEVM (context , tracingStateDB , p .config , cfg )
83+
8484 if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
85- ProcessBeaconBlockRoot (* beaconRoot , vmenv , tracingStateDB )
85+ ProcessBeaconBlockRoot (* beaconRoot , evm , tracingStateDB )
8686 }
8787 if p .config .IsPrague (block .Number (), block .Time ()) {
88- ProcessParentBlockHash (block .ParentHash (), vmenv , tracingStateDB )
88+ ProcessParentBlockHash (block .ParentHash (), evm , tracingStateDB )
8989 }
9090
9191 // Iterate over and process the individual transactions
@@ -96,7 +96,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
9696 }
9797 statedb .SetTxContext (tx .Hash (), i )
9898
99- receipt , err := ApplyTransactionWithEVM (msg , p .config , gp , statedb , blockNumber , blockHash , tx , usedGas , vmenv )
99+ receipt , err := ApplyTransactionWithEVM (msg , p .config , gp , statedb , blockNumber , blockHash , tx , usedGas , evm )
100100 if err != nil {
101101 return nil , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
102102 }
@@ -113,10 +113,10 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
113113 }
114114 requests = append (requests , depositRequests )
115115 // EIP-7002 withdrawals
116- withdrawalRequests := ProcessWithdrawalQueue (vmenv , tracingStateDB )
116+ withdrawalRequests := ProcessWithdrawalQueue (evm , tracingStateDB )
117117 requests = append (requests , withdrawalRequests )
118118 // EIP-7251 consolidations
119- consolidationRequests := ProcessConsolidationQueue (vmenv , tracingStateDB )
119+ consolidationRequests := ProcessConsolidationQueue (evm , tracingStateDB )
120120 requests = append (requests , consolidationRequests )
121121 }
122122
@@ -135,9 +135,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
135135// and uses the input parameters for its environment similar to ApplyTransaction. However,
136136// this method takes an already created EVM instance as input.
137137func ApplyTransactionWithEVM (msg * Message , config * params.ChainConfig , gp * GasPool , statedb * state.StateDB , blockNumber * big.Int , blockHash common.Hash , tx * types.Transaction , usedGas * uint64 , evm * vm.EVM ) (receipt * types.Receipt , err error ) {
138- var tracingStateDB = vm .StateDB (statedb )
139138 if hooks := evm .Config .Tracer ; hooks != nil {
140- tracingStateDB = state .NewHookedState (statedb , hooks )
141139 if hooks .OnTxStart != nil {
142140 hooks .OnTxStart (evm .GetVMContext (), tx , msg .From )
143141 }
@@ -148,7 +146,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
148146
149147 // Create a new context to be used in the EVM environment.
150148 txContext := NewEVMTxContext (msg )
151- evm .Reset (txContext , tracingStateDB )
149+ evm .SetTxContext (txContext )
152150
153151 // Apply the transaction to the current state (included in the env).
154152 result , err := ApplyMessage (evm , msg , gp )
@@ -159,7 +157,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
159157 // Update the state with pending changes.
160158 var root []byte
161159 if config .IsByzantium (blockNumber ) {
162- tracingStateDB .Finalise (true )
160+ evm . StateDB .Finalise (true )
163161 } else {
164162 root = statedb .IntermediateRoot (config .IsEIP158 (blockNumber )).Bytes ()
165163 }
@@ -210,16 +208,13 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
210208// and uses the input parameters for its environment. It returns the receipt
211209// for the transaction, gas used and an error if the transaction failed,
212210// indicating the block was invalid.
213- func ApplyTransaction (config * params.ChainConfig , bc ChainContext , author * common. Address , gp * GasPool , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * uint64 , cfg vm. Config ) (* types.Receipt , error ) {
211+ func ApplyTransaction (config * params.ChainConfig , evm * vm. EVM , gp * GasPool , statedb * state.StateDB , header * types.Header , tx * types.Transaction , usedGas * uint64 ) (* types.Receipt , error ) {
214212 msg , err := TransactionToMessage (tx , types .MakeSigner (config , header .Number , header .Time ), header .BaseFee )
215213 if err != nil {
216214 return nil , err
217215 }
218216 // Create a new context to be used in the EVM environment
219- blockContext := NewEVMBlockContext (header , bc , author )
220- txContext := NewEVMTxContext (msg )
221- vmenv := vm .NewEVM (blockContext , txContext , statedb , config , cfg )
222- return ApplyTransactionWithEVM (msg , config , gp , statedb , header .Number , header .Hash (), tx , usedGas , vmenv )
217+ return ApplyTransactionWithEVM (msg , config , gp , statedb , header .Number , header .Hash (), tx , usedGas , evm )
223218}
224219
225220// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root
@@ -242,7 +237,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb vm.St
242237 To : & params .BeaconRootsAddress ,
243238 Data : beaconRoot [:],
244239 }
245- vmenv .Reset (NewEVMTxContext (msg ), statedb )
240+ vmenv .SetTxContext (NewEVMTxContext (msg ))
246241 statedb .AddAddressToAccessList (params .BeaconRootsAddress )
247242 _ , _ , _ = vmenv .Call (vm .AccountRef (msg .From ), * msg .To , msg .Data , 30_000_000 , common .U2560 )
248243 statedb .Finalise (true )
@@ -268,7 +263,7 @@ func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb vm.Stat
268263 To : & params .HistoryStorageAddress ,
269264 Data : prevHash .Bytes (),
270265 }
271- vmenv .Reset (NewEVMTxContext (msg ), statedb )
266+ vmenv .SetTxContext (NewEVMTxContext (msg ))
272267 statedb .AddAddressToAccessList (params .HistoryStorageAddress )
273268 _ , _ , _ = vmenv .Call (vm .AccountRef (msg .From ), * msg .To , msg .Data , 30_000_000 , common .U2560 )
274269 statedb .Finalise (true )
@@ -304,7 +299,7 @@ func processRequestsSystemCall(vmenv *vm.EVM, statedb vm.StateDB, requestType by
304299 GasTipCap : common .Big0 ,
305300 To : & addr ,
306301 }
307- vmenv .Reset (NewEVMTxContext (msg ), statedb )
302+ vmenv .SetTxContext (NewEVMTxContext (msg ))
308303 statedb .AddAddressToAccessList (addr )
309304 ret , _ , _ := vmenv .Call (vm .AccountRef (msg .From ), * msg .To , msg .Data , 30_000_000 , common .U2560 )
310305 statedb .Finalise (true )
0 commit comments