mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
core/vm: customisable jump table
This commit is contained in:
parent
f02b4012c9
commit
007cae717f
2 changed files with 819 additions and 804 deletions
|
|
@ -48,7 +48,10 @@ type operation struct {
|
||||||
valid bool
|
valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var jumpTable = [256]operation{
|
var defaultJumpTable = NewJumpTable()
|
||||||
|
|
||||||
|
func NewJumpTable() [256]operation {
|
||||||
|
return [256]operation{
|
||||||
ADD: operation{
|
ADD: operation{
|
||||||
execute: opAdd,
|
execute: opAdd,
|
||||||
gasCost: constGasFunc(GasFastestStep),
|
gasCost: constGasFunc(GasFastestStep),
|
||||||
|
|
@ -852,4 +855,5 @@ var jumpTable = [256]operation{
|
||||||
validateStack: makeStackFunc(16, 1),
|
validateStack: makeStackFunc(16, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@ type Config struct {
|
||||||
NoRecursion bool
|
NoRecursion bool
|
||||||
// Disable gas metering
|
// Disable gas metering
|
||||||
DisableGasMetering bool
|
DisableGasMetering bool
|
||||||
|
// JumpTable contains the EVM instruction table. This
|
||||||
|
// may me left uninitialised and will be set the default
|
||||||
|
// table.
|
||||||
|
JumpTable [256]operation
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interpreter is used to run Ethereum based contracts and will utilise the
|
// Interpreter is used to run Ethereum based contracts and will utilise the
|
||||||
|
|
@ -58,6 +62,13 @@ type Interpreter struct {
|
||||||
|
|
||||||
// NewInterpreter returns a new instance of the Interpreter.
|
// NewInterpreter returns a new instance of the Interpreter.
|
||||||
func NewInterpreter(env *EVM, cfg Config) *Interpreter {
|
func NewInterpreter(env *EVM, cfg Config) *Interpreter {
|
||||||
|
// We use the STOP instruction whether to see
|
||||||
|
// the jump table was initialised. If it was not
|
||||||
|
// we'll set the default jump table.
|
||||||
|
if !cfg.JumpTable[STOP].valid {
|
||||||
|
cfg.JumpTable = defaultJumpTable
|
||||||
|
}
|
||||||
|
|
||||||
return &Interpreter{
|
return &Interpreter{
|
||||||
env: env,
|
env: env,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
|
|
@ -121,7 +132,7 @@ func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err e
|
||||||
op = contract.GetOp(pc)
|
op = contract.GetOp(pc)
|
||||||
|
|
||||||
// get the operation from the jump table matching the opcode
|
// get the operation from the jump table matching the opcode
|
||||||
operation := jumpTable[op]
|
operation := evm.cfg.JumpTable[op]
|
||||||
|
|
||||||
// if the op is invalid abort the process and return an error
|
// if the op is invalid abort the process and return an error
|
||||||
if !operation.valid {
|
if !operation.valid {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue