17
17
package vm
18
18
19
19
import (
20
- "errors"
21
20
"math/big"
22
21
"sync/atomic"
23
22
"time"
@@ -61,29 +60,6 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
61
60
return p , ok
62
61
}
63
62
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
-
87
63
// BlockContext provides the EVM with auxiliary information. Once provided
88
64
// it shouldn't be modified.
89
65
type BlockContext struct {
@@ -143,8 +119,7 @@ type EVM struct {
143
119
Config Config
144
120
// global (to this context) ethereum virtual machine
145
121
// used throughout the execution of the tx.
146
- interpreters []Interpreter
147
- interpreter Interpreter
122
+ interpreter * EVMInterpreter
148
123
// abort is used to abort the EVM calling operations
149
124
// NOTE: must be set atomically
150
125
abort int32
@@ -165,14 +140,9 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStat
165
140
Config : config ,
166
141
chainConfig : chainConfig ,
167
142
chainRules : chainConfig .Rules (blockCtx .BlockNumber ),
168
- interpreters : make ([]Interpreter , 0 , 1 ),
169
143
}
170
144
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 )
176
146
return evm
177
147
}
178
148
@@ -195,7 +165,7 @@ func (evm *EVM) Cancelled() bool {
195
165
}
196
166
197
167
// Interpreter returns the current interpreter
198
- func (evm * EVM ) Interpreter () Interpreter {
168
+ func (evm * EVM ) Interpreter () * EVMInterpreter {
199
169
return evm .interpreter
200
170
}
201
171
@@ -264,7 +234,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
264
234
// The depth-check is already done, and precompiles handled above
265
235
contract := NewContract (caller , AccountRef (addrCopy ), value , gas )
266
236
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 )
268
238
gas = contract .Gas
269
239
}
270
240
}
@@ -321,7 +291,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
321
291
// The contract is a scoped environment for this execution context only.
322
292
contract := NewContract (caller , AccountRef (caller .Address ()), value , gas )
323
293
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 )
325
295
gas = contract .Gas
326
296
}
327
297
if err != nil {
@@ -361,7 +331,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
361
331
// Initialise a new contract and make initialise the delegate values
362
332
contract := NewContract (caller , AccountRef (caller .Address ()), nil , gas ).AsDelegate ()
363
333
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 )
365
335
gas = contract .Gas
366
336
}
367
337
if err != nil {
@@ -418,7 +388,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
418
388
// above we revert to the snapshot and consume any gas remaining. Additionally
419
389
// when we're in Homestead this also counts for code storage gas errors.
420
390
readOnly := evm .ChainConfig ().IsTIPXDCXCancellationFee (evm .Context .BlockNumber )
421
- ret , err = run ( evm , contract , input , readOnly )
391
+ ret , err = evm . interpreter . Run ( contract , input , readOnly )
422
392
gas = contract .Gas
423
393
}
424
394
if err != nil {
@@ -489,7 +459,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
489
459
}
490
460
start := time .Now ()
491
461
492
- ret , err := run ( evm , contract , nil , false )
462
+ ret , err := evm . interpreter . Run ( contract , nil , false )
493
463
494
464
// Check whether the max code size has been exceeded, assign err if the case.
495
465
if err == nil && evm .chainRules .IsEIP158 && len (ret ) > params .MaxCodeSize {
0 commit comments