Skip to content

Commit 05f0d63

Browse files
committed
all: remove noop vm config flags (ethereum#23111)
1 parent 338fb86 commit 05f0d63

File tree

4 files changed

+17
-74
lines changed

4 files changed

+17
-74
lines changed

core/vm/evm.go

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package vm
1818

1919
import (
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.
8965
type 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 {

core/vm/instructions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func testTwoOperandOp(t *testing.T, tests []TwoOperandTestcase, opFn executionFu
9696
env = NewEVM(BlockContext{}, TxContext{}, nil, nil, params.TestChainConfig, Config{})
9797
stack = newstack()
9898
pc = uint64(0)
99-
evmInterpreter = env.interpreter.(*EVMInterpreter)
99+
evmInterpreter = env.interpreter
100100
)
101101

102102
for i, test := range tests {
@@ -239,7 +239,7 @@ func TestWriteExpectedValues(t *testing.T) {
239239
env = NewEVM(BlockContext{}, TxContext{}, nil, nil, params.TestChainConfig, Config{})
240240
stack = newstack()
241241
pc = uint64(0)
242-
interpreter = env.interpreter.(*EVMInterpreter)
242+
interpreter = env.interpreter
243243
)
244244
result := make([]TwoOperandTestcase, len(args))
245245
for i, param := range args {

core/vm/interpreter.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,9 @@ type Config struct {
3232

3333
JumpTable *JumpTable // EVM instruction table, automatically populated if unset
3434

35-
EWASMInterpreter string // External EWASM interpreter options
36-
EVMInterpreter string // External EVM interpreter options
37-
3835
ExtraEips []int // Additional EIPS that are to be enabled
3936
}
4037

41-
// Interpreter is used to run Ethereum based contracts and will utilise the
42-
// passed environment to query external sources for state information.
43-
// The Interpreter will run the byte code VM based on the passed
44-
// configuration.
45-
type Interpreter interface {
46-
// Run loops and evaluates the contract's code with the given input data and returns
47-
// the return byte-slice and an error if one occurred.
48-
Run(contract *Contract, input []byte, static bool) ([]byte, error)
49-
// CanRun tells if the contract, passed as an argument, can be
50-
// run by the current interpreter. This is meant so that the
51-
// caller can do something like:
52-
//
53-
// ```golang
54-
// for _, interpreter := range interpreters {
55-
// if interpreter.CanRun(contract.code) {
56-
// interpreter.Run(contract.code, input)
57-
// }
58-
// }
59-
// ```
60-
CanRun([]byte) bool
61-
}
62-
6338
// ScopeContext contains the things that are per-call, such as stack and memory,
6439
// but not transients like pc and gas
6540
type ScopeContext struct {
@@ -274,9 +249,3 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
274249

275250
return res, err
276251
}
277-
278-
// CanRun tells if the contract, passed as an argument, can be
279-
// run by the current interpreter.
280-
func (in *EVMInterpreter) CanRun(code []byte) bool {
281-
return true
282-
}

tests/state_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,21 @@ func TestState(t *testing.T) {
7474
const traceErrorLimit = 400000
7575

7676
func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
77-
err := test(vm.Config{})
77+
// Use config from command line arguments.
78+
config := vm.Config{}
79+
err := test(config)
7880
if err == nil {
7981
return
8082
}
81-
t.Error(err)
83+
84+
// Test failed, re-run with tracing enabled.
8285
if gasLimit > traceErrorLimit {
8386
t.Log("gas limit too high for EVM trace")
8487
return
8588
}
8689
tracer := vm.NewStructLogger(nil)
87-
err2 := test(vm.Config{Debug: true, Tracer: tracer})
90+
config.Debug, config.Tracer = true, tracer
91+
err2 := test(config)
8892
if !reflect.DeepEqual(err, err2) {
8993
t.Errorf("different error for second run: %v", err2)
9094
}

0 commit comments

Comments
 (0)