Skip to content

Commit 3a52c0f

Browse files
committed
core/vm: remove pointers from JumpTable
1 parent 93e4625 commit 3a52c0f

File tree

3 files changed

+61
-80
lines changed

3 files changed

+61
-80
lines changed

core/vm/eips.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func enable1884(jt *JumpTable) {
8181
jt[EXTCODEHASH].constantGas = params.ExtcodeHashGasEIP1884
8282

8383
// New opcode
84-
jt[SELFBALANCE] = &operation{
84+
jt[SELFBALANCE] = operation{
8585
execute: opSelfBalance,
8686
constantGas: GasFastStep,
8787
}
@@ -96,7 +96,7 @@ func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
9696
// - Adds an opcode that returns the current chain’s EIP-155 unique identifier
9797
func enable1344(jt *JumpTable) {
9898
// New opcode
99-
jt[CHAINID] = &operation{
99+
jt[CHAINID] = operation{
100100
execute: opChainID,
101101
constantGas: GasQuickStep,
102102
}
@@ -165,7 +165,7 @@ func enable3529(jt *JumpTable) {
165165
// - Adds an opcode that returns the current block's base fee.
166166
func enable3198(jt *JumpTable) {
167167
// New opcode
168-
jt[BASEFEE] = &operation{
168+
jt[BASEFEE] = operation{
169169
execute: opBaseFee,
170170
constantGas: GasQuickStep,
171171
}
@@ -175,12 +175,12 @@ func enable3198(jt *JumpTable) {
175175
// - Adds TLOAD that reads from transient storage
176176
// - Adds TSTORE that writes to transient storage
177177
func enable1153(jt *JumpTable) {
178-
jt[TLOAD] = &operation{
178+
jt[TLOAD] = operation{
179179
execute: opTload,
180180
constantGas: params.WarmStorageReadCostEIP2929,
181181
}
182182

183-
jt[TSTORE] = &operation{
183+
jt[TSTORE] = operation{
184184
execute: opTstore,
185185
constantGas: params.WarmStorageReadCostEIP2929,
186186
}
@@ -222,7 +222,7 @@ func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
222222
// enable3855 applies EIP-3855 (PUSH0 opcode)
223223
func enable3855(jt *JumpTable) {
224224
// New opcode
225-
jt[PUSH0] = &operation{
225+
jt[PUSH0] = operation{
226226
execute: opPush0,
227227
constantGas: GasQuickStep,
228228
}
@@ -243,7 +243,7 @@ func enable3860(jt *JumpTable) {
243243
// enable5656 enables EIP-5656 (MCOPY opcode)
244244
// https://eips.ethereum.org/EIPS/eip-5656
245245
func enable5656(jt *JumpTable) {
246-
jt[MCOPY] = &operation{
246+
jt[MCOPY] = operation{
247247
execute: opMcopy,
248248
constantGas: GasFastestStep,
249249
}
@@ -314,31 +314,31 @@ func opCLZ(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte
314314

315315
// enable4844 applies EIP-4844 (BLOBHASH opcode)
316316
func enable4844(jt *JumpTable) {
317-
jt[BLOBHASH] = &operation{
317+
jt[BLOBHASH] = operation{
318318
execute: opBlobHash,
319319
constantGas: GasFastestStep,
320320
}
321321
}
322322

323323
// enable7939 enables EIP-7939 (CLZ opcode)
324324
func enable7939(jt *JumpTable) {
325-
jt[CLZ] = &operation{
325+
jt[CLZ] = operation{
326326
execute: opCLZ,
327327
constantGas: GasFastStep,
328328
}
329329
}
330330

331331
// enable7516 applies EIP-7516 (BLOBBASEFEE opcode)
332332
func enable7516(jt *JumpTable) {
333-
jt[BLOBBASEFEE] = &operation{
333+
jt[BLOBBASEFEE] = operation{
334334
execute: opBlobBaseFee,
335335
constantGas: GasQuickStep,
336336
}
337337
}
338338

339339
// enable6780 applies EIP-6780 (deactivate SELFDESTRUCT)
340340
func enable6780(jt *JumpTable) {
341-
jt[SELFDESTRUCT] = &operation{
341+
jt[SELFDESTRUCT] = operation{
342342
execute: opSelfdestructEIP6780,
343343
constantGas: params.SelfdestructGasEIP150,
344344
}
@@ -440,71 +440,71 @@ func makePushEIP4762(size uint64, pushByteSize int) executionFunc {
440440
}
441441

442442
func enable4762(jt *JumpTable) {
443-
jt[SSTORE] = &operation{
443+
jt[SSTORE] = operation{
444444
execute: opSstoreEIP4762,
445445
}
446-
jt[SLOAD] = &operation{
446+
jt[SLOAD] = operation{
447447
execute: opSLoadEIP4762,
448448
}
449449

450-
jt[BALANCE] = &operation{
450+
jt[BALANCE] = operation{
451451
execute: opBalanceEIP4762,
452452
}
453453

454-
jt[EXTCODESIZE] = &operation{
454+
jt[EXTCODESIZE] = operation{
455455
execute: opExtCodeSizeEIP4762,
456456
}
457457

458-
jt[EXTCODEHASH] = &operation{
458+
jt[EXTCODEHASH] = operation{
459459
execute: opExtCodeHashEIP4762,
460460
}
461461

462-
jt[EXTCODECOPY] = &operation{
462+
jt[EXTCODECOPY] = operation{
463463
execute: opExtCodeCopyEIP4762,
464464
}
465465

466-
jt[CODECOPY] = &operation{
466+
jt[CODECOPY] = operation{
467467
execute: opCodeCopyEIP4762,
468468
constantGas: GasFastestStep,
469469
}
470470

471-
jt[SELFDESTRUCT] = &operation{
471+
jt[SELFDESTRUCT] = operation{
472472
execute: opSelfdestructEIP4762,
473473
constantGas: params.SelfdestructGasEIP150,
474474
}
475475

476-
jt[CREATE] = &operation{
476+
jt[CREATE] = operation{
477477
execute: opCreateEIP3860,
478478
constantGas: params.CreateNGasEip4762,
479479
}
480480

481-
jt[CREATE2] = &operation{
481+
jt[CREATE2] = operation{
482482
execute: opCreate2EIP3860,
483483
constantGas: params.CreateNGasEip4762,
484484
}
485485

486-
jt[CALL] = &operation{
486+
jt[CALL] = operation{
487487
execute: opCallEIP4762,
488488
}
489489

490-
jt[CALLCODE] = &operation{
490+
jt[CALLCODE] = operation{
491491
execute: opCallCodeEIP4762,
492492
}
493493

494-
jt[STATICCALL] = &operation{
494+
jt[STATICCALL] = operation{
495495
execute: opStaticCallEIP4762,
496496
}
497497

498-
jt[DELEGATECALL] = &operation{
498+
jt[DELEGATECALL] = operation{
499499
execute: opDelegateCallEIP4762,
500500
}
501501

502-
jt[PUSH1] = &operation{
502+
jt[PUSH1] = operation{
503503
execute: opPush1EIP4762,
504504
constantGas: GasFastestStep,
505505
}
506506
for i := 1; i < 32; i++ {
507-
jt[PUSH1+OpCode(i)] = &operation{
507+
jt[PUSH1+OpCode(i)] = operation{
508508
execute: makePushEIP4762(uint64(i+1), i+1),
509509
constantGas: GasFastestStep,
510510
}

core/vm/interpreter.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
149149
}
150150
}
151151
if evm.Config.Tracer != nil {
152-
for _, op := range table {
153-
op.execute = executeWithTracer(evm.Config.Tracer, op.execute)
152+
for i := range table {
153+
table[i].execute = executeWithTracer(evm.Config.Tracer, table[i].execute)
154154
}
155155
}
156156

@@ -163,7 +163,7 @@ func executeWithTracer(tracer *tracing.Hooks, execF executionFunc) executionFunc
163163
return func(pc *uint64, interpreter *EVMInterpreter, callContext *ScopeContext) ([]byte, error) {
164164
pcCopy := *pc
165165
op := callContext.Contract.GetOp(pcCopy)
166-
operation := interpreter.table[op]
166+
operation := &interpreter.table[op]
167167
cost := operation.constantGas
168168
gasCopy := callContext.Contract.Gas + cost
169169

@@ -263,7 +263,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
263263

264264
// Get the operation from the jump table
265265
op = contract.GetOp(pc)
266-
operation := jumpTable[op]
266+
operation := &jumpTable[op]
267267
cost = operation.constantGas // For tracing
268268
// for tracing: this gas consumption event is emitted in the executeWithTracer wrapper.
269269
if contract.Gas < cost {

0 commit comments

Comments
 (0)