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:
parent
2879f89337
commit
8f08065a8e
2 changed files with 17 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue