Skip to content

Commit 508891e

Browse files
committed
core/vm: use pointers to operations vs. copy by value
1 parent 9e88224 commit 508891e

File tree

3 files changed

+19
-165
lines changed

3 files changed

+19
-165
lines changed

core/vm/eips.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ func enable1884(jt *JumpTable) {
6868
jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884
6969

7070
// New opcode
71-
jt[SELFBALANCE] = operation{
71+
jt[SELFBALANCE] = &operation{
7272
execute: opSelfBalance,
7373
constantGas: GasFastStep,
7474
minStack: minStack(0, 1),
7575
maxStack: maxStack(0, 1),
76-
valid: true,
7776
}
7877
}
7978

@@ -87,12 +86,11 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx
8786
// - Adds an opcode that returns the current chain’s EIP-155 unique identifier
8887
func enable1344(jt *JumpTable) {
8988
// New opcode
90-
jt[CHAINID] = operation{
89+
jt[CHAINID] = &operation{
9190
execute: opChainID,
9291
constantGas: GasQuickStep,
9392
minStack: minStack(0, 1),
9493
maxStack: maxStack(0, 1),
95-
valid: true,
9694
}
9795
}
9896

@@ -113,29 +111,26 @@ func enable2200(jt *JumpTable) {
113111
// - Adds opcodes that jump to and return from subroutines
114112
func enable2315(jt *JumpTable) {
115113
// New opcode
116-
jt[BEGINSUB] = operation{
114+
jt[BEGINSUB] = &operation{
117115
execute: opBeginSub,
118116
constantGas: GasQuickStep,
119117
minStack: minStack(0, 0),
120118
maxStack: maxStack(0, 0),
121-
valid: true,
122119
}
123120
// New opcode
124-
jt[JUMPSUB] = operation{
121+
jt[JUMPSUB] = &operation{
125122
execute: opJumpSub,
126123
constantGas: GasSlowStep,
127124
minStack: minStack(1, 0),
128125
maxStack: maxStack(1, 0),
129126
jumps: true,
130-
valid: true,
131127
}
132128
// New opcode
133-
jt[RETURNSUB] = operation{
129+
jt[RETURNSUB] = &operation{
134130
execute: opReturnSub,
135131
constantGas: GasFastStep,
136132
minStack: minStack(0, 0),
137133
maxStack: maxStack(0, 0),
138-
valid: true,
139134
jumps: true,
140135
}
141136
}

core/vm/interpreter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Config struct {
3232
NoRecursion bool // Disables call, callcode, delegate call and create
3333
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
3434

35-
JumpTable [256]operation // EVM instruction table, automatically populated if unset
35+
JumpTable [256]*operation // EVM instruction table, automatically populated if unset
3636

3737
EWASMInterpreter string // External EWASM interpreter options
3838
EVMInterpreter string // External EVM interpreter options
@@ -96,7 +96,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
9696
// We use the STOP instruction whether to see
9797
// the jump table was initialised. If it was not
9898
// we'll set the default jump table.
99-
if !cfg.JumpTable[STOP].valid {
99+
if cfg.JumpTable[STOP] == nil {
100100
var jt JumpTable
101101
switch {
102102
case evm.chainRules.IsYoloV1:
@@ -221,7 +221,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
221221
// enough stack items available to perform the operation.
222222
op = contract.GetOp(pc)
223223
operation := in.cfg.JumpTable[op]
224-
if !operation.valid {
224+
if operation == nil {
225225
return nil, &ErrInvalidOpCode{opcode: op}
226226
}
227227
// Validate stack

0 commit comments

Comments
 (0)