diff --git a/core/vm/evm.go b/core/vm/evm.go index f5fff54111..6982605f66 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -19,6 +19,7 @@ package vm import ( "math/big" "os" + "strings" "sync/atomic" "time" @@ -141,23 +142,21 @@ func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmCon } if chainConfig.IsEWASM(ctx.BlockNumber) { - // to be implemented by EVM-C and Wagon PRs. - // if vmConfig.EWASMInterpreter != "" { - // extIntOpts := strings.Split(vmConfig.EWASMInterpreter, ":") - // path := extIntOpts[0] - // options := []string{} - // if len(extIntOpts) > 1 { - // options = extIntOpts[1..] - // } - // evm.interpreters = append(evm.interpreters, NewEVMVCInterpreter(evm, vmConfig, options)) - // } else { - // evm.interpreters = append(evm.interpreters, NewEWASMInterpreter(evm, vmConfig)) - // } - panic("No supported ewasm interpreter yet.") + if vmConfig.EWASMInterpreter != "" { + extIntOpts := strings.Split(vmConfig.EWASMInterpreter, ":") + path := extIntOpts[0] + options := []string{} + if len(extIntOpts) > 1 { + options = extIntOpts[1:] + } + evm.interpreters = append(evm.interpreters, NewEVMC(path, options, evm)) + } else { + panic("No supported ewasm interpreter yet.") + } } if len(vmConfig.EVMInterpreter) != 0 || len(os.Getenv("EVMC_PATH")) != 0 { - evm.interpreters = append(evm.interpreters, NewEVMC(vmConfig.EVMInterpreter, evm)) + evm.interpreters = append(evm.interpreters, NewEVMC(vmConfig.EVMInterpreter, nil, evm)) } // vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here diff --git a/core/vm/evmc.go b/core/vm/evmc.go index c8706ced48..8418134cd5 100644 --- a/core/vm/evmc.go +++ b/core/vm/evmc.go @@ -42,7 +42,7 @@ var ( evmcInstance *evmc.Instance ) -func createVM(path string) *evmc.Instance { +func createVM(path string, options []string) *evmc.Instance { createMu.Lock() defer createMu.Unlock() @@ -62,7 +62,10 @@ func createVM(path string) *evmc.Instance { } log.Info("EVMC VM loaded", "name", evmcInstance.Name(), "version", evmcInstance.Version(), "path", vmPath) - for _, option := range strings.Split(os.Getenv("EVMC_OPTIONS"), " ") { + opts := strings.Split(os.Getenv("EVMC_OPTIONS"), " ") + opts = append(opts, options...) + + for _, option := range opts { if idx := strings.Index(option, "="); idx >= 0 { name := option[:idx] value := option[idx+1:] @@ -78,8 +81,8 @@ func createVM(path string) *evmc.Instance { return evmcInstance } -func NewEVMC(path string, env *EVM) *EVMC { - return &EVMC{createVM(path), env, false} +func NewEVMC(path string, options []string, env *EVM) *EVMC { + return &EVMC{createVM(path, options), env, false} } // Implements evmc.HostContext interface. @@ -309,7 +312,8 @@ func (evm *EVMC) Run(contract *Contract, input []byte, readOnly bool) (ret []byt func (evm *EVMC) CanRun(code []byte) bool { cap := evmc.CapabilityEVM1 - if (bytes.Equal(code[0:4], []byte("\x00asm"))) { + wasmPreamble := []byte("\x00asm\x01\x00\x00\x00") + if (bytes.HasPrefix(code, wasmPreamble)) { cap = evmc.CapabilityEWASM } // FIXME: Optimize. Access capabilities once.