From 63f8d10434c310ea77eb9630eaa66fda6e1b1e45 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Fri, 20 Oct 2023 09:27:20 -0700 Subject: [PATCH] OpCode select plugin hook and injection --- core/vm/interpreter.go | 3 +++ core/vm/plugin_hooks.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 873337850..8d6270b77 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -95,6 +95,9 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { } } evm.Config.ExtraEips = extraEips + // begin PluGeth injection + table = pluginOpCodeSelect(table) + // end PluGeth injection return &EVMInterpreter{evm: evm, table: table} } diff --git a/core/vm/plugin_hooks.go b/core/vm/plugin_hooks.go index 728e3c75f..7592dc2cd 100644 --- a/core/vm/plugin_hooks.go +++ b/core/vm/plugin_hooks.go @@ -1,5 +1,39 @@ package vm +import ( + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" +) + func (st *Stack) Len() int { return len(st.data) } + +func PluginOpCodeSelect(pl *plugins.PluginLoader, jt *JumpTable) *JumpTable { + var opCodes []int + fnList := pl.Lookup("OpCodeSelect", func(item interface{}) bool { + _, ok := item.(func() []int) + return ok + }) + for _, fni := range fnList { + if fn, ok := fni.(func() []int); ok { + opCodes = append(opCodes, fn()...) + } + } + if len(opCodes) > 0 { + jt = copyJumpTable(jt) + } + for _, idx := range opCodes { + (*jt)[idx] = nil + } + return jt +} + +func pluginOpCodeSelect(jt *JumpTable) *JumpTable { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting PluginOpCodeSelect, but default PluginLoader has not been initialized") + return nil + } + return PluginOpCodeSelect(plugins.DefaultPluginLoader, jt) +} +