Merge pull request #92 from openrelayxyz/feature/etc-plugin

Feature/etc plugin
This commit is contained in:
AusIV
2023-10-30 12:53:00 -05:00
committed by GitHub
23 changed files with 1568 additions and 301 deletions
+8 -1
View File
@@ -72,7 +72,9 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
table = &constantinopleInstructionSet
case evm.chainRules.IsByzantium:
table = &byzantiumInstructionSet
case evm.chainRules.IsEIP158:
// begin PluGeth injection
case evm.chainRules.IsEIP160:
// end PluGeth injection
table = &spuriousDragonInstructionSet
case evm.chainRules.IsEIP150:
table = &tangerineWhistleInstructionSet
@@ -95,6 +97,11 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
}
}
evm.Config.ExtraEips = extraEips
// begin PluGeth injection
if pluginTable := pluginOpCodeSelect(table); pluginTable != nil {
table = pluginTable
}
// end PluGeth injection
return &EVMInterpreter{evm: evm, table: table}
}
+3 -1
View File
@@ -46,7 +46,9 @@ func LookupInstructionSet(rules params.Rules) (JumpTable, error) {
return newConstantinopleInstructionSet(), nil
case rules.IsByzantium:
return newByzantiumInstructionSet(), nil
case rules.IsEIP158:
// Begin plugeth injection
case rules.IsEIP160:
// End plugeth injection
return newSpuriousDragonInstructionSet(), nil
case rules.IsEIP150:
return newTangerineWhistleInstructionSet(), nil
+34
View File
@@ -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] = &operation{execute: opUndefined, maxStack: maxStack(0, 0)}
}
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)
}