From 3db030bbb6bd6e17c5986c726b908695ea7b0898 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 23 Mar 2020 11:58:41 +0300 Subject: [PATCH] vm: implement PUSHNULL opcode --- pkg/vm/opcode/opcode.go | 1 + pkg/vm/vm.go | 3 +++ pkg/vm/vm_test.go | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/pkg/vm/opcode/opcode.go b/pkg/vm/opcode/opcode.go index f3e09a5a8..269d24587 100644 --- a/pkg/vm/opcode/opcode.go +++ b/pkg/vm/opcode/opcode.go @@ -89,6 +89,7 @@ const ( PUSHDATA2 Opcode = 0x4D PUSHDATA4 Opcode = 0x4E PUSHM1 Opcode = 0x4F + PUSHNULL Opcode = 0x50 PUSH1 Opcode = 0x51 PUSHT Opcode = PUSH1 PUSH2 Opcode = 0x52 diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 13ac42441..56a9ec452 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -560,6 +560,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro case opcode.PUSHDATA1, opcode.PUSHDATA2, opcode.PUSHDATA4: v.estack.PushVal(parameter) + case opcode.PUSHNULL: + v.estack.PushVal(NullItem{}) + // Stack operations. case opcode.TOALTSTACK: v.astack.Push(v.estack.Pop()) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index e0b13920b..44c4d8ee8 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -197,6 +197,15 @@ func TestStackLimitPUSH1Bad(t *testing.T) { checkVMFailed(t, v) } +func TestPUSHNULL(t *testing.T) { + prog := makeProgram(opcode.PUSHNULL, opcode.PUSHNULL, opcode.EQUAL) + v := load(prog) + require.NoError(t, v.Step()) + require.Equal(t, 1, v.estack.Len()) + runVM(t, v) + require.True(t, v.estack.Pop().Bool()) +} + // appendBigStruct returns a program which: // 1. pushes size Structs on stack // 2. packs them into a new struct