Skip to content

Commit

Permalink
Problem: gas consumed differs after enabled cache (#570)
Browse files Browse the repository at this point in the history
* Problem: gas consumed differs after enabled cache

* fix test

* Revert "Problem: gas consumed differs after enabled cache"

This reverts commit f33944e.

* Revert "Problem: signature verification result not cache between incarnations of same tx (#565)"

This reverts commit 5a1594f.

* keep interface
  • Loading branch information
mmsqe authored Jul 16, 2024
1 parent f7d64a2 commit c47504d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
5 changes: 5 additions & 0 deletions core/coins/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 10 additions & 27 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ var (
key = make([]byte, secp256k1.PubKeySize)
simSecp256k1Pubkey = &secp256k1.PubKey{Key: key}
simSecp256k1Sig [64]byte

SigVerificationResultCacheKey = "ante:SigVerificationResult"
)

func init() {
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down

0 comments on commit c47504d

Please sign in to comment.