diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 4c57ea3bc..1d36341b2 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -677,8 +677,9 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro // Bit operations. case opcode.INVERT: // inplace - a := v.estack.Peek(0).BigInt() - a.Not(a) + e := v.estack.Peek(0) + i := e.BigInt() + e.value = makeStackItem(i.Not(i)) case opcode.AND: b := v.estack.Pop().BigInt() diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 838b1faf4..1bf8d1887 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1759,6 +1759,20 @@ func TestINVERTgood3(t *testing.T) { assert.Equal(t, int64(-0x6A), vm.estack.Peek(0).BigInt().Int64()) } +func TestINVERTWithConversion1(t *testing.T) { + prog := makeProgram(opcode.PUSHDATA2, 0, 0, opcode.INVERT) + vm := load(prog) + runVM(t, vm) + assert.Equal(t, int64(-1), vm.estack.Peek(0).BigInt().Int64()) +} + +func TestINVERTWithConversion2(t *testing.T) { + prog := makeProgram(opcode.PUSH0, opcode.PUSH1, opcode.NUMEQUAL, opcode.INVERT) + vm := load(prog) + runVM(t, vm) + assert.Equal(t, int64(-1), vm.estack.Peek(0).BigInt().Int64()) +} + func TestCATBadNoArgs(t *testing.T) { prog := makeProgram(opcode.CAT) vm := load(prog)