interop/crypto: allow ECDsaVerify to verify ScriptContainer

When verifying transaction or block, verification script can be
a simple PUSHNULL + SYSCALL, which means that script-encontaining
entity should be verified.
This commit is contained in:
Evgenii Stratonikov 2020-04-13 16:18:28 +03:00
parent 8f08065a8e
commit a92872931c
3 changed files with 13 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/dao" "github.com/nspcc-dev/neo-go/pkg/core/dao"
"github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
"github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm"
"go.uber.org/zap" "go.uber.org/zap"
@ -14,6 +15,7 @@ import (
// Context represents context in which interops are executed. // Context represents context in which interops are executed.
type Context struct { type Context struct {
Chain blockchainer.Blockchainer Chain blockchainer.Blockchainer
Container crypto.Verifiable
Trigger trigger.Type Trigger trigger.Type
Block *block.Block Block *block.Block
Tx *transaction.Transaction Tx *transaction.Transaction

View file

@ -49,11 +49,13 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error {
return nil return nil
} }
func getMessage(_ *interop.Context, item vm.StackItem) []byte { func getMessage(ic *interop.Context, item vm.StackItem) []byte {
var msg []byte var msg []byte
switch val := item.(type) { switch val := item.(type) {
case *vm.InteropItem: case *vm.InteropItem:
msg = val.Value().(crypto.Verifiable).GetSignedPart() msg = val.Value().(crypto.Verifiable).GetSignedPart()
case vm.NullItem:
msg = ic.Container.GetSignedPart()
default: default:
var err error var err error
if msg, err = val.TryBytes(); err != nil { if msg, err = val.TryBytes(); err != nil {

View file

@ -280,6 +280,14 @@ func TestECDSAVerify(t *testing.T) {
runCase(t, false, true, sign, priv.PublicKey().Bytes(), vm.NewInteropItem(tx)) runCase(t, false, true, sign, priv.PublicKey().Bytes(), vm.NewInteropItem(tx))
}) })
t.Run("signed script container", func(t *testing.T) {
tx := transaction.NewInvocationTX([]byte{0, 1, 2}, 1)
msg := tx.GetSignedPart()
sign := priv.Sign(msg)
ic.Container = tx
runCase(t, false, true, sign, priv.PublicKey().Bytes(), vm.NullItem{})
})
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)