From c47504d189d460735666dc9321d876881ebf222c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 16 Jul 2024 14:33:09 +0800 Subject: [PATCH] Problem: gas consumed differs after enabled cache (#570) * Problem: gas consumed differs after enabled cache * fix test * Revert "Problem: gas consumed differs after enabled cache" This reverts commit f33944ee849c66f1b51d5d29e6e4f3b6ce41797a. * Revert "Problem: signature verification result not cache between incarnations of same tx (#565)" This reverts commit 5a1594f17924388dc2530bd8143ca2b04655fad4. * keep interface --- core/coins/format.go | 5 +++++ x/auth/ante/sigverify.go | 37 ++++++++++--------------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/core/coins/format.go b/core/coins/format.go index 315c96d78f46..7b1e49f2b7e2 100644 --- a/core/coins/format.go +++ b/core/coins/format.go @@ -84,6 +84,11 @@ func FormatCoins(coins []*basev1beta1.Coin, metadata []*bankv1beta1.Metadata) (s if err != nil { return "", err } + // If a coin contains a comma, return an error given that the output + // could be misinterpreted by the user as 2 different coins. + if strings.Contains(formatted[i], ",") { + return "", fmt.Errorf("coin %s contains a comma", formatted[i]) + } } if len(coins) == 0 { diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 341ccf65cf85..9f7c18d57cb2 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -31,8 +31,6 @@ var ( key = make([]byte, secp256k1.PubKeySize) simSecp256k1Pubkey = &secp256k1.PubKey{Key: key} simSecp256k1Sig [64]byte - - SigVerificationResultCacheKey = "ante:SigVerificationResult" ) func init() { @@ -252,44 +250,44 @@ func OnlyLegacyAminoSigners(sigData signing.SignatureData) bool { } } -func (svd SigVerificationDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool) error { +func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { sigTx, ok := tx.(authsigning.Tx) if !ok { - return errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") + return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") } // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. sigs, err := sigTx.GetSignaturesV2() if err != nil { - return err + return ctx, err } signers, err := sigTx.GetSigners() if err != nil { - return err + return ctx, err } // check that signer length and signature length are the same if len(sigs) != len(signers) { - return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signers), len(sigs)) + return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signers), len(sigs)) } for i, sig := range sigs { acc, err := GetSignerAcc(ctx, svd.ak, signers[i]) if err != nil { - return err + return ctx, err } // retrieve pubkey pubKey := acc.GetPubKey() if !simulate && pubKey == nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") + return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set") } // Check account sequence number. if sig.Sequence != acc.GetSequence() { - return errorsmod.Wrapf( + return ctx, errorsmod.Wrapf( sdkerrors.ErrWrongSequence, "account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, ) @@ -319,7 +317,7 @@ func (svd SigVerificationDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simul } adaptableTx, ok := tx.(authsigning.V2AdaptableTx) if !ok { - return fmt.Errorf("expected tx to implement V2AdaptableTx, got %T", tx) + return ctx, fmt.Errorf("expected tx to implement V2AdaptableTx, got %T", tx) } txData := adaptableTx.GetSigningTxData() err = authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) @@ -332,27 +330,12 @@ func (svd SigVerificationDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simul } else { errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d) and chain-id (%s): (%s)", accNum, chainID, err.Error()) } - return errorsmod.Wrap(sdkerrors.ErrUnauthorized, errMsg) + return ctx, errorsmod.Wrap(sdkerrors.ErrUnauthorized, errMsg) } } } - return nil -} -func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - if v, ok := ctx.GetIncarnationCache(SigVerificationResultCacheKey); ok { - // can't convert `nil` to interface - if v != nil { - err = v.(error) - } - } else { - err = svd.anteHandle(ctx, tx, simulate) - ctx.SetIncarnationCache(SigVerificationResultCacheKey, err) - } - if err != nil { - return ctx, err - } return next(ctx, tx, simulate) }