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.
This commit is contained in:
Evgenii Stratonikov 2020-04-13 13:43:36 +03:00
parent 2879f89337
commit 8f08065a8e
2 changed files with 17 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/interop" "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/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm" "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 { func getMessage(_ *interop.Context, item vm.StackItem) []byte {
msg, err := item.TryBytes() var msg []byte
if err != nil { switch val := item.(type) {
panic(err) case *vm.InteropItem:
msg = val.Value().(crypto.Verifiable).GetSignedPart()
default:
var err error
if msg, err = val.TryBytes(); err != nil {
return nil
}
} }
return msg return msg
} }

View file

@ -273,6 +273,13 @@ func TestECDSAVerify(t *testing.T) {
runCase(t, false, true, sign, priv.PublicKey().Bytes(), msg) 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) { t.Run("missing arguments", func(t *testing.T) {
runCase(t, true, false) runCase(t, true, false)
sign := priv.Sign(msg) sign := priv.Sign(msg)