From f3d83c90b11a4604b59bb98bea26dcd3cb582c49 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 22 Aug 2022 14:52:04 +0300 Subject: [PATCH] rpcsrv: allow invalid contract signatures in calculatenetworkfee See #2805, it allows to cover more cases like Notary contract that can use CalculateNetworkFee now instead of AddNetworkFee RPC client API. --- pkg/rpcclient/rpc.go | 14 +++++++++----- pkg/services/rpcsrv/server.go | 5 +---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/rpcclient/rpc.go b/pkg/rpcclient/rpc.go index c8b1e7073..3d37a0d54 100644 --- a/pkg/rpcclient/rpc.go +++ b/pkg/rpcclient/rpc.go @@ -918,17 +918,21 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa } fallbackNetFee += extraNetFee - dummyAccount := &wallet.Account{Contract: &wallet.Contract{Deployed: false}} // don't call `verify` for Notary contract witness, because it will fail - err = c.AddNetworkFee(fallbackTx, fallbackNetFee, dummyAccount, acc) - if err != nil { - return nil, fmt.Errorf("failed to add network fee: %w", err) - } fallbackTx.Scripts = []transaction.Witness{ { InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...), VerificationScript: []byte{}, }, + { + InvocationScript: []byte{}, + VerificationScript: acc.GetVerificationScript(), + }, } + fallbackTx.NetworkFee, err = c.CalculateNetworkFee(fallbackTx) + if err != nil { + return nil, fmt.Errorf("failed to add network fee: %w", err) + } + fallbackTx.NetworkFee += fallbackNetFee m, err := c.GetNetwork() if err != nil { return nil, fmt.Errorf("failed to sign fallback tx: %w", err) diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index cda8b0576..5ebfe1e7d 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -765,10 +765,7 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo for i, signer := range tx.Signers { w := tx.Scripts[i] if len(w.VerificationScript) == 0 { // then it still might be a contract-based verification - gasConsumed, err := s.chain.VerifyWitness(signer.Account, tx, &tx.Scripts[i], int64(s.config.MaxGasInvoke)) - if err != nil { - return 0, neorpc.NewRPCError("Invalid signature", fmt.Sprintf("contract verification for signer #%d failed: %s", i, err)) - } + gasConsumed, _ := s.chain.VerifyWitness(signer.Account, tx, &tx.Scripts[i], int64(s.config.MaxGasInvoke)) netFee += gasConsumed size += io.GetVarSize([]byte{}) + // verification script is empty (contract-based witness) io.GetVarSize(tx.Scripts[i].InvocationScript) // invocation script might not be empty (args for `verify`)