From b4059f652e32a2485f17452df510c23651553f00 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 9 Sep 2021 11:47:30 +0300 Subject: [PATCH] [#814] morph/event: Fix `NotaryPreparator` parsing Add checking for call flag in TX's script and do not pass it to parsers. Signed-off-by: Pavel Karpy --- pkg/morph/event/notary_preparator.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/morph/event/notary_preparator.go b/pkg/morph/event/notary_preparator.go index f1df8019d..6424ddf15 100644 --- a/pkg/morph/event/notary_preparator.go +++ b/pkg/morph/event/notary_preparator.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" @@ -28,7 +29,8 @@ var ( errIncorrectNotaryPlaceholder = errors.New("received main tx has incorrect Notary contract placeholder") errIncorrectAttributesAmount = errors.New("received main tx has incorrect attributes amount") errIncorrectAttribute = errors.New("received main tx has incorrect attribute") - errUnexpectedOpcode = errors.New("received main tx has unexpected(not PUSHDATA) NeoVM opcodes") + errUnexpectedOpcode = errors.New("received main tx has unexpected(not PUSH) NeoVM opcodes") + errIncorrectCallFlag = errors.New("received main tx has unexpected call flag") errIncorrectFBAttributesAmount = errors.New("received fallback tx has incorrect attributes amount") errIncorrectFBAttributes = errors.New("received fallback tx has incorrect attributes") @@ -183,7 +185,13 @@ func (p Preparator) Prepare(nr *payload.P2PNotaryRequest) (NotaryEvent, error) { // retrieve contract's method contractMethod := string(ops[opsLen-3].param) - err = p.validateParameterOpcodes(ops[:opsLen-3]) + // check if there is a call flag(must be in range [0:15)) + callFlag := callflag.CallFlag(ops[opsLen-4].code - opcode.PUSH0) + if callFlag > callflag.All { + return nil, errIncorrectCallFlag + } + + err = p.validateParameterOpcodes(ops[:opsLen-4]) if err != nil { return nil, err } @@ -191,7 +199,7 @@ func (p Preparator) Prepare(nr *payload.P2PNotaryRequest) (NotaryEvent, error) { return parsedNotaryEvent{ hash: contractHash, notaryType: NotaryTypeFromString(contractMethod), - params: ops[:opsLen-3], + params: ops[:opsLen-4], raw: nr, }, nil }