From 434f94800ad6745b223cad4ff27c55f02b79f163 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 11 Jul 2024 12:03:34 +0300 Subject: [PATCH] rpcsrv: improve witness verification error It's needed to give user a hint about what's wrong with the witness during `calculatenetworkfee` RPC request processing. Signed-off-by: Anna Shaleva --- pkg/core/blockchain.go | 2 +- pkg/services/rpcsrv/server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 3e7984aa7..93c98577e 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -2902,7 +2902,7 @@ var ( func (bc *Blockchain) InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error { if len(witness.VerificationScript) != 0 { if witness.ScriptHash() != hash { - return ErrWitnessHashMismatch + return fmt.Errorf("%w: expected %s, got %s", ErrWitnessHashMismatch, hash.StringLE(), witness.ScriptHash().StringLE()) } if bc.contracts.ByHash(hash) != nil { return ErrNativeContractWitness diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index d58d68f2e..755140a36 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -991,7 +991,7 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (any, *neorpc.Erro } gasConsumed, err := s.chain.VerifyWitness(signer.Account, tx, &w, gasLimit) if err != nil && !errors.Is(err, core.ErrInvalidSignature) { - return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidSignature, err.Error()) + return nil, neorpc.WrapErrorWithData(neorpc.ErrInvalidSignature, fmt.Sprintf("witness %d: %s", i, err)) } gasLimit -= gasConsumed netFee += gasConsumed