From c146540ce8d2ddf1864002236599e20c07a70f34 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 22 Jan 2021 12:54:17 +0300 Subject: [PATCH] core: fix native contract verification --- pkg/core/blockchain.go | 24 ++++++++++++++---------- pkg/core/blockchain_test.go | 1 - 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 0e4983d4b..b65cae7d4 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -34,7 +34,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" - "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "go.uber.org/zap" ) @@ -1654,6 +1653,7 @@ var ( // initVerificationVM initializes VM for witness check. func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error { + isNative := false v := ic.VM if len(witness.VerificationScript) != 0 { if witness.ScriptHash() != hash { @@ -1677,18 +1677,22 @@ func (bc *Blockchain) initVerificationVM(ic *interop.Context, hash util.Uint160, v.Context().NEF = &cs.NEF v.Jump(v.Context(), md.Offset) - if cs.ID <= 0 { - w := io.NewBufBinWriter() - emit.String(w.BinWriter, manifest.MethodVerify) - if w.Err != nil { - return w.Err - } - v.LoadScript(w.Bytes()) - } else if initMD != nil { + isNative = cs.ID <= 0 + if !isNative && initMD != nil { v.Call(v.Context(), initMD.Offset) } } - v.LoadScript(witness.InvocationScript) + if len(witness.InvocationScript) != 0 { + v.LoadScript(witness.InvocationScript) + if isNative { + if err := v.StepOut(); err != nil { + return err + } + } + } + if isNative { + v.Estack().PushVal(manifest.MethodVerify) + } return nil } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 83f83a971..4b4741b91 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -973,7 +973,6 @@ func TestVerifyTx(t *testing.T) { transaction.NotaryServiceFeePerKey + // fee for Notary attribute fee.Opcode(bc.GetBaseExecFee(), // Notary verification script opcode.PUSHDATA1, opcode.RET, // invocation script - opcode.PUSHDATA1, opcode.RET, // arguments for native verification call opcode.PUSHINT8, opcode.SYSCALL, opcode.RET) + // Neo.Native.Call native.NotaryVerificationPrice // Notary witness verification price tx.Scripts = []transaction.Witness{