Skip to content

Commit

Permalink
core/vm: update subroutines acc to eip: disallow walk-into
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed May 25, 2020
1 parent 485a357 commit 291f812
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/vm/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (

// List evm execution errors
var (
// ErrInvalidSubroutineEntry means that a BEGINSUB was reached via iteration,
// as opposed to from a JUMPSUB instruction
ErrInvalidSubroutineEntry = errors.New("invalid subroutine entry")
ErrOutOfGas = errors.New("out of gas")
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")
ErrDepth = errors.New("max call depth exceeded")
Expand Down
4 changes: 2 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ func opJumpdest(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) (
}

func opBeginSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
return nil, nil
return nil, ErrInvalidSubroutineEntry
}

func opJumpSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
Expand All @@ -681,7 +681,7 @@ func opJumpSub(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([
return nil, ErrInvalidJump
}
callContext.rstack.push(*pc)
*pc = posU64
*pc = posU64+1
interpreter.intPool.put(pos)
return nil, nil
}
Expand Down
11 changes: 10 additions & 1 deletion core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func TestEipExampleCases(t *testing.T) {
prettyPrint("This should fail at first opcode, due to shallow `return_stack`", code)

}
{ // First eip testcase
{
code := []byte{
byte(vm.PUSH1), 5, // Jump past the subroutine
byte(vm.JUMP),
Expand All @@ -553,4 +553,13 @@ func TestEipExampleCases(t *testing.T) {
"and not exit with error", code)
}

{
code := []byte{
byte(vm.BEGINSUB),
byte(vm.RETURNSUB),
byte(vm.STOP),
}
prettyPrint("In this example, the code 'walks' into a subroutine, which is not "+
"allowed, and causes an error", code)
}
}

0 comments on commit 291f812

Please sign in to comment.