Skip to content

Commit 163f166

Browse files
authored
core/vm: don't copy JumpTable when no EIP mods are needed (ethereum#23977)
1 parent a69d4b2 commit 163f166

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

core/vm/interpreter.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Config struct {
3333
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
3434
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
3535

36-
JumpTable JumpTable // EVM instruction table, automatically populated if unset
36+
JumpTable *JumpTable // EVM instruction table, automatically populated if unset
3737

3838
ExtraEips []int // Additional EIPS that are to be enabled
3939
}
@@ -68,39 +68,37 @@ type EVMInterpreter struct {
6868

6969
// NewEVMInterpreter returns a new instance of the Interpreter.
7070
func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
71-
// We use the STOP instruction whether to see
72-
// the jump table was initialised. If it was not
73-
// we'll set the default jump table.
74-
if cfg.JumpTable[STOP] == nil {
75-
var jt JumpTable
71+
// If jump table was not initialised we set the default one.
72+
if cfg.JumpTable == nil {
7673
switch {
7774
case evm.chainRules.IsLondon:
78-
jt = londonInstructionSet
75+
cfg.JumpTable = &londonInstructionSet
7976
case evm.chainRules.IsBerlin:
80-
jt = berlinInstructionSet
77+
cfg.JumpTable = &berlinInstructionSet
8178
case evm.chainRules.IsIstanbul:
82-
jt = istanbulInstructionSet
79+
cfg.JumpTable = &istanbulInstructionSet
8380
case evm.chainRules.IsConstantinople:
84-
jt = constantinopleInstructionSet
81+
cfg.JumpTable = &constantinopleInstructionSet
8582
case evm.chainRules.IsByzantium:
86-
jt = byzantiumInstructionSet
83+
cfg.JumpTable = &byzantiumInstructionSet
8784
case evm.chainRules.IsEIP158:
88-
jt = spuriousDragonInstructionSet
85+
cfg.JumpTable = &spuriousDragonInstructionSet
8986
case evm.chainRules.IsEIP150:
90-
jt = tangerineWhistleInstructionSet
87+
cfg.JumpTable = &tangerineWhistleInstructionSet
9188
case evm.chainRules.IsHomestead:
92-
jt = homesteadInstructionSet
89+
cfg.JumpTable = &homesteadInstructionSet
9390
default:
94-
jt = frontierInstructionSet
91+
cfg.JumpTable = &frontierInstructionSet
9592
}
9693
for i, eip := range cfg.ExtraEips {
97-
if err := EnableEIP(eip, &jt); err != nil {
94+
copy := *cfg.JumpTable
95+
if err := EnableEIP(eip, &copy); err != nil {
9896
// Disable it, so caller can check if it's activated or not
9997
cfg.ExtraEips = append(cfg.ExtraEips[:i], cfg.ExtraEips[i+1:]...)
10098
log.Error("EIP activation failed", "eip", eip, "error", err)
10199
}
100+
cfg.JumpTable = &copy
102101
}
103-
cfg.JumpTable = jt
104102
}
105103

106104
return &EVMInterpreter{

0 commit comments

Comments
 (0)