Skip to content

Commit

Permalink
EVMC support
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed May 20, 2020
1 parent 6d74d1e commit a391ec8
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 24 deletions.
4 changes: 4 additions & 0 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func runCmd(ctx *cli.Context) error {
},
}

if runtimeConfig.EVMConfig.EVMInterpreter != "" {
vm.InitEVMCEVM(runtimeConfig.EVMConfig.EVMInterpreter)
}

if cpuProfilePath := ctx.GlobalString(CPUProfileFlag.Name); cpuProfilePath != "" {
f, err := os.Create(cpuProfilePath)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,10 +1539,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {

if ctx.GlobalIsSet(EWASMInterpreterFlag.Name) {
cfg.EWASMInterpreter = ctx.GlobalString(EWASMInterpreterFlag.Name)
vm.InitEVMCEwasm(cfg.EWASMInterpreter)
}

if ctx.GlobalIsSet(EVMInterpreterFlag.Name) {
cfg.EVMInterpreter = ctx.GlobalString(EVMInterpreterFlag.Name)
vm.InitEVMCEVM(cfg.EVMInterpreter)
}
if ctx.GlobalIsSet(RPCGlobalGasCap.Name) {
cfg.RPCGasCap = new(big.Int).SetUint64(ctx.GlobalUint64(RPCGlobalGasCap.Name))
Expand Down
46 changes: 22 additions & 24 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"sync/atomic"
"time"

"github.com/ethereum/evmc/v7/bindings/go/evmc"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -135,33 +137,29 @@ type EVM struct {
// only ever be used *once*.
func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *EVM {
evm := &EVM{
Context: ctx,
StateDB: statedb,
vmConfig: vmConfig,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(ctx.BlockNumber),
interpreters: make([]Interpreter, 0, 1),
Context: ctx,
StateDB: statedb,
vmConfig: vmConfig,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(ctx.BlockNumber),
// The list of interpreters, space reserved for both EVM and EWASM ones.
interpreters: make([]Interpreter, 0, 2),
}

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.")
}

// vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here
// as we always want to have the built-in EVM as the failover option.
evm.interpreters = append(evm.interpreters, NewEVMInterpreter(evm, vmConfig))
if vmConfig.EWASMInterpreter != "" {
evm.interpreters = append(evm.interpreters, &EVMC{ewasmModule, evm, evmc.CapabilityEWASM, false})
} else {
panic("The default ewasm interpreter not supported yet.")
}
}

if vmConfig.EVMInterpreter != "" {
evm.interpreters = append(evm.interpreters, &EVMC{evmModule, evm, evmc.CapabilityEVM1, false})
} else {
evm.interpreters = append(evm.interpreters, NewEVMInterpreter(evm, vmConfig))
}

evm.interpreter = evm.interpreters[0]

return evm
Expand Down
Loading

0 comments on commit a391ec8

Please sign in to comment.