From e7f77e052f20f1b5c7fa393630fa51494dc16b37 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 20 Jul 2023 11:25:00 +0300 Subject: [PATCH 1/6] vm: add ABORTMSG and ASSERTMSG opcodes Signed-off-by: Anna Shaleva --- pkg/core/fee/opcode.go | 2 ++ pkg/vm/opcode/opcode.go | 4 ++++ pkg/vm/opcode/opcode_string.go | 6 +++++- pkg/vm/vm.go | 10 ++++++++++ pkg/vm/vm_test.go | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/core/fee/opcode.go b/pkg/core/fee/opcode.go index ba9e9a558..0a668a0df 100644 --- a/pkg/core/fee/opcode.go +++ b/pkg/core/fee/opcode.go @@ -70,6 +70,8 @@ var coefficients = [256]uint16{ opcode.CALLT: 1 << 15, opcode.ABORT: 0, opcode.ASSERT: 1 << 0, + opcode.ABORTMSG: 0, // TODO + opcode.ASSERTMSG: 1 << 0, // TODO opcode.THROW: 1 << 9, opcode.TRY: 1 << 2, opcode.TRYL: 1 << 2, diff --git a/pkg/vm/opcode/opcode.go b/pkg/vm/opcode/opcode.go index 847e5c400..3cb5c4664 100644 --- a/pkg/vm/opcode/opcode.go +++ b/pkg/vm/opcode/opcode.go @@ -225,6 +225,10 @@ const ( ISNULL Opcode = 0xD8 ISTYPE Opcode = 0xD9 CONVERT Opcode = 0xDB + + // Extensions. + ABORTMSG Opcode = 0xE0 + ASSERTMSG Opcode = 0xE1 ) var validCodes [256]bool diff --git a/pkg/vm/opcode/opcode_string.go b/pkg/vm/opcode/opcode_string.go index ee4e7e2e5..1c9456b93 100644 --- a/pkg/vm/opcode/opcode_string.go +++ b/pkg/vm/opcode/opcode_string.go @@ -202,9 +202,11 @@ func _() { _ = x[ISNULL-216] _ = x[ISTYPE-217] _ = x[CONVERT-219] + _ = x[ABORTMSG-224] + _ = x[ASSERTMSG-225] } -const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHTPUSHFPUSHAPUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMP_LJMPIFJMPIF_LJMPIFNOTJMPIFNOT_LJMPEQJMPEQ_LJMPNEJMPNE_LJMPGTJMPGT_LJMPGEJMPGE_LJMPLTJMPLT_LJMPLEJMPLE_LCALLCALL_LCALLACALLTABORTASSERTTHROWTRYTRY_LENDTRYENDTRY_LENDFINALLYRETSYSCALLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPROTROLLREVERSE3REVERSE4REVERSENINITSSLOTINITSLOTLDSFLD0LDSFLD1LDSFLD2LDSFLD3LDSFLD4LDSFLD5LDSFLD6LDSFLDSTSFLD0STSFLD1STSFLD2STSFLD3STSFLD4STSFLD5STSFLD6STSFLDLDLOC0LDLOC1LDLOC2LDLOC3LDLOC4LDLOC5LDLOC6LDLOCSTLOC0STLOC1STLOC2STLOC3STLOC4STLOC5STLOC6STLOCLDARG0LDARG1LDARG2LDARG3LDARG4LDARG5LDARG6LDARGSTARG0STARG1STARG2STARG3STARG4STARG5STARG6STARGNEWBUFFERMEMCPYCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODPOWSQRTMODMULMODPOWSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLEGTGEMINMAXWITHINPACKMAPPACKSTRUCTPACKUNPACKNEWARRAY0NEWARRAYNEWARRAY_TNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSPOPITEMISNULLISTYPECONVERT" +const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHTPUSHFPUSHAPUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMP_LJMPIFJMPIF_LJMPIFNOTJMPIFNOT_LJMPEQJMPEQ_LJMPNEJMPNE_LJMPGTJMPGT_LJMPGEJMPGE_LJMPLTJMPLT_LJMPLEJMPLE_LCALLCALL_LCALLACALLTABORTASSERTTHROWTRYTRY_LENDTRYENDTRY_LENDFINALLYRETSYSCALLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPROTROLLREVERSE3REVERSE4REVERSENINITSSLOTINITSLOTLDSFLD0LDSFLD1LDSFLD2LDSFLD3LDSFLD4LDSFLD5LDSFLD6LDSFLDSTSFLD0STSFLD1STSFLD2STSFLD3STSFLD4STSFLD5STSFLD6STSFLDLDLOC0LDLOC1LDLOC2LDLOC3LDLOC4LDLOC5LDLOC6LDLOCSTLOC0STLOC1STLOC2STLOC3STLOC4STLOC5STLOC6STLOCLDARG0LDARG1LDARG2LDARG3LDARG4LDARG5LDARG6LDARGSTARG0STARG1STARG2STARG3STARG4STARG5STARG6STARGNEWBUFFERMEMCPYCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODPOWSQRTMODMULMODPOWSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLEGTGEMINMAXWITHINPACKMAPPACKSTRUCTPACKUNPACKNEWARRAY0NEWARRAYNEWARRAY_TNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSPOPITEMISNULLISTYPECONVERTABORTMSGASSERTMSG" var _Opcode_map = map[Opcode]string{ 0: _Opcode_name[0:8], @@ -401,6 +403,8 @@ var _Opcode_map = map[Opcode]string{ 216: _Opcode_name[1112:1118], 217: _Opcode_name[1118:1124], 219: _Opcode_name[1124:1131], + 224: _Opcode_name[1131:1139], + 225: _Opcode_name[1139:1148], } func (i Opcode) String() string { diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 8c1af0df8..32f8c8210 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1587,11 +1587,21 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro case opcode.ABORT: panic("ABORT") + case opcode.ABORTMSG: + msg := v.estack.Pop().Bytes() + panic(fmt.Sprintf("%s is executed. Reason: %s", op, string(msg))) + case opcode.ASSERT: if !v.estack.Pop().Bool() { panic("ASSERT failed") } + case opcode.ASSERTMSG: + msg := v.estack.Pop().Bytes() + if !v.estack.Pop().Bool() { + panic(fmt.Sprintf("%s is executed with false result. Reason: %s", op, msg)) + } + case opcode.TRY, opcode.TRYL: catchP, finallyP := getTryParams(op, parameter) if ctx.tryStack.Len() >= MaxTryNestingDepth { diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index d19b42e6e..2107f749b 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1097,6 +1097,7 @@ func TestTRY(t *testing.T) { t.Run("Simple", getTRYTestFunc(1, push1, add5, nil)) t.Run("Throw", getTRYTestFunc(18, throw, add5, nil)) t.Run("Abort", getTRYTestFunc(nil, []byte{byte(opcode.ABORT)}, push1, nil)) + t.Run("AbortMSG", getTRYTestFunc(nil, []byte{byte(opcode.PUSH1), byte(opcode.ABORTMSG)}, push1, nil)) t.Run("ThrowInCatch", getTRYTestFunc(nil, throw, throw, nil)) }) t.Run("WithFinally", func(t *testing.T) { From 11bb733f1a2c56857891fd38f8b4b2da8c461220 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 20 Jul 2023 11:42:48 +0300 Subject: [PATCH 2/6] interop: support ABORTMSG, ASSERT, ASSERTMSG opcodes Signed-off-by: Anna Shaleva --- pkg/interop/neogointernal/opcode.go | 6 +++++- pkg/interop/util/util.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/interop/neogointernal/opcode.go b/pkg/interop/neogointernal/opcode.go index a64e85733..0b39138ed 100644 --- a/pkg/interop/neogointernal/opcode.go +++ b/pkg/interop/neogointernal/opcode.go @@ -9,12 +9,16 @@ func Opcode1(op string, arg any) any { return nil } +// Opcode1NoReturn emits opcode with 1 argument and no return value. +func Opcode1NoReturn(op string, arg any) { +} + // Opcode2 emits opcode with 2 arguments. func Opcode2(op string, arg1, arg2 any) any { return nil } -// Opcode2NoReturn emits opcode with 2 arguments. +// Opcode2NoReturn emits opcode with 2 arguments and no return value. func Opcode2NoReturn(op string, arg1, arg2 any) { } diff --git a/pkg/interop/util/util.go b/pkg/interop/util/util.go index 9e93ed6c3..b17eb0124 100644 --- a/pkg/interop/util/util.go +++ b/pkg/interop/util/util.go @@ -13,6 +13,25 @@ func Abort() { neogointernal.Opcode0NoReturn("ABORT") } +// AbortMsg terminates current execution with the specified message. Unlike +// exception throwing with panic() it can't be recovered from. +func AbortMsg(msg string) { + neogointernal.Opcode1NoReturn("ABORTMSG", msg) +} + +// Assert terminates current execution if the condition specified is false. Unlike +// exception throwing with panic() it can't be recovered from. +func Assert(ok bool) { + neogointernal.Opcode1NoReturn("ASSERT", ok) +} + +// AssertMsg terminates current execution with the specified message if the +// condition specified is false. Unlike exception throwing with panic() it can't +// be recovered from. +func AssertMsg(ok bool, msg string) { + neogointernal.Opcode2NoReturn("ASSERTMSG", ok, msg) +} + // Equals compares a with b and will return true when a and b are equal. It's // implemented as an EQUAL VM opcode, so the rules of comparison are those // of EQUAL. From de43b39c2aee36aacbed424daa087532ef763eb0 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 20 Jul 2023 11:44:26 +0300 Subject: [PATCH 3/6] *: update interop deps Signed-off-by: Anna Shaleva --- examples/engine/go.mod | 2 +- examples/engine/go.sum | 4 ++-- examples/events/go.mod | 2 +- examples/events/go.sum | 4 ++-- examples/iterator/go.mod | 2 +- examples/iterator/go.sum | 4 ++-- examples/nft-d/go.mod | 2 +- examples/nft-d/go.sum | 4 ++-- examples/nft-nd-nns/go.mod | 2 +- examples/nft-nd-nns/go.sum | 4 ++-- examples/nft-nd/go.mod | 2 +- examples/nft-nd/go.sum | 4 ++-- examples/oracle/go.mod | 2 +- examples/oracle/go.sum | 4 ++-- examples/runtime/go.mod | 2 +- examples/runtime/go.sum | 4 ++-- examples/storage/go.mod | 2 +- examples/storage/go.sum | 4 ++-- examples/timer/go.mod | 2 +- examples/timer/go.sum | 4 ++-- examples/token/go.mod | 2 +- examples/token/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- internal/contracts/oracle_contract/go.mod | 2 +- internal/contracts/oracle_contract/go.sum | 4 ++-- 26 files changed, 39 insertions(+), 39 deletions(-) diff --git a/examples/engine/go.mod b/examples/engine/go.mod index 94d41135f..60277ab1c 100644 --- a/examples/engine/go.mod +++ b/examples/engine/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/engine go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/engine/go.sum b/examples/engine/go.sum index f665b036a..ed1db4575 100644 --- a/examples/engine/go.sum +++ b/examples/engine/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/events/go.mod b/examples/events/go.mod index b4175ed11..7374bd165 100644 --- a/examples/events/go.mod +++ b/examples/events/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/events go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/events/go.sum b/examples/events/go.sum index f665b036a..ed1db4575 100644 --- a/examples/events/go.sum +++ b/examples/events/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/iterator/go.mod b/examples/iterator/go.mod index f9a528ba1..ce086bb59 100644 --- a/examples/iterator/go.mod +++ b/examples/iterator/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/iterator go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/iterator/go.sum b/examples/iterator/go.sum index f665b036a..ed1db4575 100644 --- a/examples/iterator/go.sum +++ b/examples/iterator/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/nft-d/go.mod b/examples/nft-d/go.mod index 5afeb6f09..af5ae7245 100644 --- a/examples/nft-d/go.mod +++ b/examples/nft-d/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/nft-d/go.sum b/examples/nft-d/go.sum index f665b036a..ed1db4575 100644 --- a/examples/nft-d/go.sum +++ b/examples/nft-d/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/nft-nd-nns/go.mod b/examples/nft-nd-nns/go.mod index 589482cd7..b91989772 100644 --- a/examples/nft-nd-nns/go.mod +++ b/examples/nft-nd-nns/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5 - github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c github.com/stretchr/testify v1.8.0 ) diff --git a/examples/nft-nd-nns/go.sum b/examples/nft-nd-nns/go.sum index 619660152..b8eaeff70 100644 --- a/examples/nft-nd-nns/go.sum +++ b/examples/nft-nd-nns/go.sum @@ -187,8 +187,8 @@ github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y= github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5 h1:NCIUxkLRB3ovLzM1lvQA6wBNn8fuY7dQx4cMJKLuaAs= github.com/nspcc-dev/neo-go v0.99.5-0.20221108145959-8746d9877eb5/go.mod h1:aWrWJZBYO+9kYC4+qJXvEjySW1WIyPnrHpmdrzd5mJY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ= github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU= diff --git a/examples/nft-nd/go.mod b/examples/nft-nd/go.mod index c6b8048c1..3ac3e18d5 100644 --- a/examples/nft-nd/go.mod +++ b/examples/nft-nd/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/nft-nd/go.sum b/examples/nft-nd/go.sum index f665b036a..ed1db4575 100644 --- a/examples/nft-nd/go.sum +++ b/examples/nft-nd/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/oracle/go.mod b/examples/oracle/go.mod index 224b6c5b7..369234276 100644 --- a/examples/oracle/go.mod +++ b/examples/oracle/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/oracle go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/oracle/go.sum b/examples/oracle/go.sum index f665b036a..ed1db4575 100644 --- a/examples/oracle/go.sum +++ b/examples/oracle/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/runtime/go.mod b/examples/runtime/go.mod index 8dc6ae388..97c02706b 100644 --- a/examples/runtime/go.mod +++ b/examples/runtime/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/runtime go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/runtime/go.sum b/examples/runtime/go.sum index f665b036a..ed1db4575 100644 --- a/examples/runtime/go.sum +++ b/examples/runtime/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/storage/go.mod b/examples/storage/go.mod index df0640441..9e0679179 100644 --- a/examples/storage/go.mod +++ b/examples/storage/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/storage go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/storage/go.sum b/examples/storage/go.sum index f665b036a..ed1db4575 100644 --- a/examples/storage/go.sum +++ b/examples/storage/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/timer/go.mod b/examples/timer/go.mod index 7f8d9efcc..dc24ccd1c 100644 --- a/examples/timer/go.mod +++ b/examples/timer/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/timer go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/timer/go.sum b/examples/timer/go.sum index f665b036a..ed1db4575 100644 --- a/examples/timer/go.sum +++ b/examples/timer/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/examples/token/go.mod b/examples/token/go.mod index 936db6f72..b51148efa 100644 --- a/examples/token/go.mod +++ b/examples/token/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/token go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/examples/token/go.sum b/examples/token/go.sum index f665b036a..ed1db4575 100644 --- a/examples/token/go.sum +++ b/examples/token/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= diff --git a/go.mod b/go.mod index e23b8dcdc..188124089 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/mr-tron/base58 v1.2.0 github.com/nspcc-dev/dbft v0.0.0-20230515113611-25db6ba61d5c github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 - github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.9 github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pierrec/lz4 v2.6.1+incompatible diff --git a/go.sum b/go.sum index 2c53ee921..c916365e7 100644 --- a/go.sum +++ b/go.sum @@ -206,8 +206,8 @@ github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 h1:n4ZaF github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U= github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y= github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= github.com/nspcc-dev/neofs-api-go/v2 v2.14.0 h1:jhuN8Ldqz7WApvUJRFY0bjRXE1R3iCkboMX5QVZhHVk= github.com/nspcc-dev/neofs-api-go/v2 v2.14.0/go.mod h1:DRIr0Ic1s+6QgdqmNFNLIqMqd7lNMJfYwkczlm1hDtM= github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4= diff --git a/internal/contracts/oracle_contract/go.mod b/internal/contracts/oracle_contract/go.mod index 1d36a6782..795e0663b 100644 --- a/internal/contracts/oracle_contract/go.mod +++ b/internal/contracts/oracle_contract/go.mod @@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/internal/examples/oracle go 1.18 -require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c diff --git a/internal/contracts/oracle_contract/go.sum b/internal/contracts/oracle_contract/go.sum index f665b036a..ed1db4575 100644 --- a/internal/contracts/oracle_contract/go.sum +++ b/internal/contracts/oracle_contract/go.sum @@ -1,2 +1,2 @@ -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a h1:63sh46kfKF/g2IE1z/EV8CBEKCVmGJXSSH0ZHqTDGCY= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230420112658-c50ab951645a/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c h1:upj+XyoI0dS7CYnZOTAeyuznhvDIJurQXL4FvHNKyl4= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230810094130-11bb733f1a2c/go.mod h1:ZUuXOkdtHZgaC13za/zMgXfQFncZ0jLzfQTe+OsDOtg= From 5b12be2ac77bf72fa18fa22c9e12776da9dbe33e Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 20 Jul 2023 11:51:18 +0300 Subject: [PATCH 4/6] compiler: add test for util.AbortMsg and util.AssertMsg Signed-off-by: Anna Shaleva --- pkg/compiler/interop_test.go | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pkg/compiler/interop_test.go b/pkg/compiler/interop_test.go index c8f77ce24..b43e4824b 100644 --- a/pkg/compiler/interop_test.go +++ b/pkg/compiler/interop_test.go @@ -192,6 +192,60 @@ func TestAbort(t *testing.T) { require.True(t, v.HasFailed()) } +func TestAbortMsg(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/util" + func Main() int { + util.AbortMsg("some message") + return 1 + }` + v := vmAndCompile(t, src) + err := v.Run() + require.Error(t, err) + require.True(t, v.HasFailed()) + require.True(t, strings.Contains(err.Error(), "ABORTMSG is executed. Reason: some message"), err) +} + +func TestAssert(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/util" + func Main(ok bool) int { + util.Assert(ok) + return 1 + }` + + // assert OK + evalWithArgs(t, src, nil, []stackitem.Item{stackitem.Make(true)}, big.NewInt(1)) + + // assert FALSE + v := vmAndCompile(t, src) + v.Estack().PushVal(false) + err := v.Run() + require.Error(t, err) + require.True(t, v.HasFailed()) + require.True(t, strings.Contains(err.Error(), "ASSERT"), err) +} + +func TestAssertMsg(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/util" + func Main(ok bool) int { + util.AssertMsg(ok, "some message") + return 1 + }` + + // assert OK + evalWithArgs(t, src, nil, []stackitem.Item{stackitem.Make(true)}, big.NewInt(1)) + + // assert FALSE + v := vmAndCompile(t, src) + v.Estack().PushVal(false) + err := v.Run() + require.Error(t, err) + require.True(t, v.HasFailed()) + require.True(t, strings.Contains(err.Error(), "ASSERTMSG is executed with false result. Reason: some message"), err) +} + func spawnVM(t *testing.T, ic *interop.Context, src string) *vm.VM { b, di, err := compiler.CompileWithOptions("foo.go", strings.NewReader(src), nil) require.NoError(t, err) From 158d8e69a441ba94a0cf4d87ffabd16a39814c94 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 10 Aug 2023 11:08:06 +0300 Subject: [PATCH 5/6] vm: update VM json tests path It was changed way back in https://github.com/neo-project/neo-vm/commit/5a11f4b4cad43a78410f070216a000779f838355. Signed-off-by: Anna Shaleva --- pkg/vm/json_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/vm/json_test.go b/pkg/vm/json_test.go index 8df690145..1f80451f7 100644 --- a/pkg/vm/json_test.go +++ b/pkg/vm/json_test.go @@ -91,7 +91,7 @@ const ( typeString vmUTStackItemType = "string" typeStruct vmUTStackItemType = "struct" - testsDir = "testdata/neo-vm/tests/neo-vm.Tests/Tests/" + testsDir = "testdata/neo-vm/tests/Neo.VM.Tests/Tests/" ) func TestUT(t *testing.T) { From 3608314c15a2d2b604fbe1d645bc07758ac3c57a Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 10 Aug 2023 12:33:03 +0300 Subject: [PATCH 6/6] .github: enable submodules sync for actions/checkout@v3 Signed-off-by: Anna Shaleva --- .github/workflows/run_tests.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 0613c7e09..dbcba1d09 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -94,11 +94,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - - name: Sync VM submodule - run: | - git submodule sync - git submodule update --init + submodules: 'true' - name: Set up Go uses: actions/setup-go@v4 @@ -144,6 +140,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 + submodules: 'true' - name: Set up Go uses: actions/setup-go@v4 @@ -154,10 +151,5 @@ jobs: - name: Update Go modules run: go mod download -json - - name: Sync VM submodule - run: | - git submodule sync - git submodule update --init - - name: Run tests run: go test -v -race ./...