diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 1a62206a5..218824e1f 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -439,6 +439,9 @@ func (v *VM) execute(ctx *Context, op Instruction) { } case DROP: + if v.estack.Len() < 1 { + panic("stack is too small") + } v.estack.Pop() case EQUAL: diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index e402887eb..4f2b1b231 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -803,6 +803,22 @@ func TestOVERgood(t *testing.T) { assert.Equal(t, 3, vm.estack.Len()) } +func TestDROPBadNoItem(t *testing.T) { + prog := makeProgram(DROP) + vm := load(prog) + vm.Run() + assert.Equal(t, true, vm.state.HasFlag(faultState)) +} + +func TestDROPGood(t *testing.T) { + prog := makeProgram(DROP) + vm := load(prog) + vm.estack.PushVal(1) + vm.Run() + assert.Equal(t, false, vm.state.HasFlag(faultState)) + assert.Equal(t, 0, vm.estack.Len()) +} + func TestXDROPbadNoitem(t *testing.T) { prog := makeProgram(XDROP) vm := load(prog)