1717package vm
1818
1919import (
20- "errors"
2120 "math/big"
2221 "sync/atomic"
2322 "time"
@@ -61,29 +60,6 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
6160 return p , ok
6261}
6362
64- // run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
65- func run (evm * EVM , contract * Contract , input []byte , readOnly bool ) ([]byte , error ) {
66- if evm .ChainConfig ().IsTIPXDCXCancellationFee (evm .Context .BlockNumber ) {
67- for _ , interpreter := range evm .interpreters {
68- if interpreter .CanRun (contract .Code ) {
69- if evm .interpreter != interpreter {
70- // Ensure that the interpreter pointer is set back
71- // to its current value upon return.
72- defer func (i Interpreter ) {
73- evm .interpreter = i
74- }(evm .interpreter )
75- evm .interpreter = interpreter
76- }
77- return interpreter .Run (contract , input , readOnly )
78- }
79- }
80- } else {
81- return evm .interpreter .Run (contract , input , false )
82- }
83-
84- return nil , errors .New ("no compatible interpreter" )
85- }
86-
8763// BlockContext provides the EVM with auxiliary information. Once provided
8864// it shouldn't be modified.
8965type BlockContext struct {
@@ -143,8 +119,7 @@ type EVM struct {
143119 Config Config
144120 // global (to this context) ethereum virtual machine
145121 // used throughout the execution of the tx.
146- interpreters []Interpreter
147- interpreter Interpreter
122+ interpreter * EVMInterpreter
148123 // abort is used to abort the EVM calling operations
149124 // NOTE: must be set atomically
150125 abort int32
@@ -165,14 +140,9 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStat
165140 Config : config ,
166141 chainConfig : chainConfig ,
167142 chainRules : chainConfig .Rules (blockCtx .BlockNumber ),
168- interpreters : make ([]Interpreter , 0 , 1 ),
169143 }
170144
171- // vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here
172- // as we always want to have the built-in EVM as the failover option.
173- evm .interpreters = append (evm .interpreters , NewEVMInterpreter (evm , config ))
174- evm .interpreter = evm .interpreters [0 ]
175-
145+ evm .interpreter = NewEVMInterpreter (evm , config )
176146 return evm
177147}
178148
@@ -195,7 +165,7 @@ func (evm *EVM) Cancelled() bool {
195165}
196166
197167// Interpreter returns the current interpreter
198- func (evm * EVM ) Interpreter () Interpreter {
168+ func (evm * EVM ) Interpreter () * EVMInterpreter {
199169 return evm .interpreter
200170}
201171
@@ -264,7 +234,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
264234 // The depth-check is already done, and precompiles handled above
265235 contract := NewContract (caller , AccountRef (addrCopy ), value , gas )
266236 contract .SetCallCode (& addrCopy , evm .StateDB .GetCodeHash (addrCopy ), code )
267- ret , err = run ( evm , contract , input , false )
237+ ret , err = evm . interpreter . Run ( contract , input , false )
268238 gas = contract .Gas
269239 }
270240 }
@@ -321,7 +291,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
321291 // The contract is a scoped environment for this execution context only.
322292 contract := NewContract (caller , AccountRef (caller .Address ()), value , gas )
323293 contract .SetCallCode (& addrCopy , evm .StateDB .GetCodeHash (addrCopy ), evm .StateDB .GetCode (addrCopy ))
324- ret , err = run ( evm , contract , input , false )
294+ ret , err = evm . interpreter . Run ( contract , input , false )
325295 gas = contract .Gas
326296 }
327297 if err != nil {
@@ -361,7 +331,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
361331 // Initialise a new contract and make initialise the delegate values
362332 contract := NewContract (caller , AccountRef (caller .Address ()), nil , gas ).AsDelegate ()
363333 contract .SetCallCode (& addrCopy , evm .StateDB .GetCodeHash (addrCopy ), evm .StateDB .GetCode (addrCopy ))
364- ret , err = run ( evm , contract , input , false )
334+ ret , err = evm . interpreter . Run ( contract , input , false )
365335 gas = contract .Gas
366336 }
367337 if err != nil {
@@ -418,7 +388,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
418388 // above we revert to the snapshot and consume any gas remaining. Additionally
419389 // when we're in Homestead this also counts for code storage gas errors.
420390 readOnly := evm .ChainConfig ().IsTIPXDCXCancellationFee (evm .Context .BlockNumber )
421- ret , err = run ( evm , contract , input , readOnly )
391+ ret , err = evm . interpreter . Run ( contract , input , readOnly )
422392 gas = contract .Gas
423393 }
424394 if err != nil {
@@ -489,7 +459,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
489459 }
490460 start := time .Now ()
491461
492- ret , err := run ( evm , contract , nil , false )
462+ ret , err := evm . interpreter . Run ( contract , nil , false )
493463
494464 // Check whether the max code size has been exceeded, assign err if the case.
495465 if err == nil && evm .chainRules .IsEIP158 && len (ret ) > params .MaxCodeSize {
0 commit comments