From 8f08065a8e6756f39066e7fb4492c646ae778f2b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 13 Apr 2020 13:43:36 +0300 Subject: [PATCH] interop/crypto: allow ECDsaVerify to accept interop items When invokes with interop item on stack, it should check for the signature of Verifiable item it contains. --- pkg/core/interop/crypto/ecdsa.go | 13 ++++++++++--- pkg/core/interop_neo_test.go | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/core/interop/crypto/ecdsa.go b/pkg/core/interop/crypto/ecdsa.go index ae8bf014c..74d4f3988 100644 --- a/pkg/core/interop/crypto/ecdsa.go +++ b/pkg/core/interop/crypto/ecdsa.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/nspcc-dev/neo-go/pkg/core/interop" + "github.com/nspcc-dev/neo-go/pkg/crypto" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -49,9 +50,15 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error { } func getMessage(_ *interop.Context, item vm.StackItem) []byte { - msg, err := item.TryBytes() - if err != nil { - panic(err) + var msg []byte + switch val := item.(type) { + case *vm.InteropItem: + msg = val.Value().(crypto.Verifiable).GetSignedPart() + default: + var err error + if msg, err = val.TryBytes(); err != nil { + return nil + } } return msg } diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index 782c491b0..e13a3faaf 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -273,6 +273,13 @@ func TestECDSAVerify(t *testing.T) { runCase(t, false, true, sign, priv.PublicKey().Bytes(), msg) }) + t.Run("signed interop item", func(t *testing.T) { + tx := transaction.NewInvocationTX([]byte{0, 1, 2}, 1) + msg := tx.GetSignedPart() + sign := priv.Sign(msg) + runCase(t, false, true, sign, priv.PublicKey().Bytes(), vm.NewInteropItem(tx)) + }) + t.Run("missing arguments", func(t *testing.T) { runCase(t, true, false) sign := priv.Sign(msg)