From 9ebb7930091647e8f331b15c26cf1535a991d160 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 6 Nov 2019 12:15:55 +0300 Subject: [PATCH] vm: revert SUBSTR offset behavior to NEO 2.x --- pkg/vm/vm.go | 5 ++++- pkg/vm/vm_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 8f7db244b..cd9716a53 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -519,7 +519,10 @@ func (v *VM) execute(ctx *Context, op Instruction, parameter []byte) (err error) } s := v.estack.Pop().Bytes() if o > len(s) { - panic("invalid offset") + // panic("invalid offset") + // FIXME revert when NEO 3.0 https://github.com/nspcc-dev/neo-go/issues/477 + v.estack.PushVal("") + break } last := l + o if last > len(s) { diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 059bc0afd..2819d37df 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1674,7 +1674,12 @@ func TestSUBSTRBadOffset(t *testing.T) { vm.estack.PushVal([]byte("abcdef")) vm.estack.PushVal(7) vm.estack.PushVal(1) - checkVMFailed(t, vm) + + // checkVMFailed(t, vm) + // FIXME revert when NEO 3.0 https://github.com/nspcc-dev/neo-go/issues/477 + runVM(t, vm) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, []byte{}, vm.estack.Peek(0).Bytes()) } func TestSUBSTRBigLen(t *testing.T) {