Skip to content

Commit 9331fe2

Browse files
authored
core/vm: fill gaps in jump table with opUndefined (#24031)
1 parent a0f7771 commit 9331fe2

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

core/vm/instructions.go

+4
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ func opRevert(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
801801
return ret, ErrExecutionReverted
802802
}
803803

804+
func opUndefined(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
805+
return nil, &ErrInvalidOpCode{opcode: OpCode(scope.Contract.Code[*pc])}
806+
}
807+
804808
func opStop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
805809
return nil, errStopToken
806810
}

core/vm/interpreter.go

-3
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
193193
// enough stack items available to perform the operation.
194194
op = contract.GetOp(pc)
195195
operation := in.cfg.JumpTable[op]
196-
if operation == nil {
197-
return nil, &ErrInvalidOpCode{opcode: op}
198-
}
199196
// Validate stack
200197
if sLen := stack.len(); sLen < operation.minStack {
201198
return nil, &ErrStackUnderflow{stackLen: sLen, required: operation.minStack}

core/vm/jump_table.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func newHomesteadInstructionSet() JumpTable {
200200
// newFrontierInstructionSet returns the frontier instructions
201201
// that can be executed during the frontier phase.
202202
func newFrontierInstructionSet() JumpTable {
203-
return JumpTable{
203+
tbl := JumpTable{
204204
STOP: {
205205
execute: opStop,
206206
constantGas: 0,
@@ -1002,4 +1002,13 @@ func newFrontierInstructionSet() JumpTable {
10021002
maxStack: maxStack(1, 0),
10031003
},
10041004
}
1005+
1006+
// Fill all unassigned slots with opUndefined.
1007+
for i, entry := range tbl {
1008+
if entry == nil {
1009+
tbl[i] = &operation{execute: opUndefined, maxStack: maxStack(0, 0)}
1010+
}
1011+
}
1012+
1013+
return tbl
10051014
}

0 commit comments

Comments
 (0)