From 78c3c4e92d38c00b07fd888e231a91372189fa67 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 31 Aug 2021 00:15:21 +0200 Subject: [PATCH] fix!: Remove onlyAminoSigners in sequence check (#10029) ## Description Amino multisig update. It breaks the state machine and it's needed for the next SDK upgrade. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- client/tx/legacy.go | 22 ---------------------- client/tx/legacy_test.go | 22 ---------------------- x/auth/ante/sigverify.go | 19 ++++++------------- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/client/tx/legacy.go b/client/tx/legacy.go index 80626bd896..7a46e194aa 100644 --- a/client/tx/legacy.go +++ b/client/tx/legacy.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/auth/signing" ) @@ -65,24 +64,3 @@ func CopyTx(tx signing.Tx, builder client.TxBuilder, ignoreSignatureError bool) return nil } - -// ConvertAndEncodeStdTx encodes the stdTx as a transaction in the format specified by txConfig -func ConvertAndEncodeStdTx(txConfig client.TxConfig, stdTx legacytx.StdTx) ([]byte, error) { - builder := txConfig.NewTxBuilder() - - var theTx sdk.Tx - - // check if we need a StdTx anyway, in that case don't copy - if _, ok := builder.GetTx().(legacytx.StdTx); ok { - theTx = stdTx - } else { - err := CopyTx(stdTx, builder, false) - if err != nil { - return nil, err - } - - theTx = builder.GetTx() - } - - return txConfig.TxEncoder()(theTx) -} diff --git a/client/tx/legacy_test.go b/client/tx/legacy_test.go index 7172bfe26c..65949a038f 100644 --- a/client/tx/legacy_test.go +++ b/client/tx/legacy_test.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/types" signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -149,27 +148,6 @@ func (s *TestSuite) TestConvertTxToStdTx() { s.Require().Equal(stdTx, stdTx2) } -func (s *TestSuite) TestConvertAndEncodeStdTx() { - // convert amino -> proto -> amino - aminoBuilder := s.aminoCfg.NewTxBuilder() - buildTestTx(s.T(), aminoBuilder) - stdTx := aminoBuilder.GetTx().(legacytx.StdTx) - txBz, err := tx2.ConvertAndEncodeStdTx(s.protoCfg, stdTx) - s.Require().NoError(err) - decodedTx, err := s.protoCfg.TxDecoder()(txBz) - s.Require().NoError(err) - aminoBuilder2 := s.aminoCfg.NewTxBuilder() - s.Require().NoError(tx2.CopyTx(decodedTx.(signing.Tx), aminoBuilder2, false)) - s.Require().Equal(stdTx, aminoBuilder2.GetTx()) - - // just use amino everywhere - txBz, err = tx2.ConvertAndEncodeStdTx(s.aminoCfg, stdTx) - s.Require().NoError(err) - decodedTx, err = s.aminoCfg.TxDecoder()(txBz) - s.Require().NoError(err) - s.Require().Equal(stdTx, decodedTx) -} - func TestTestSuite(t *testing.T) { suite.Run(t, new(TestSuite)) } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 638e837aa3..5097478da2 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -265,18 +265,11 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } // Check account sequence number. - // When using Amino StdSignatures, we actually don't have the Sequence in - // the SignatureV2 struct (it's only in the SignDoc). In this case, we - // cannot check sequence directly, and must do it via signature - // verification (in the VerifySignature call below). - onlyAminoSigners := OnlyLegacyAminoSigners(sig.Data) - if !onlyAminoSigners { - if sig.Sequence != acc.GetSequence() { - return ctx, sdkerrors.Wrapf( - sdkerrors.ErrWrongSequence, - "account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, - ) - } + if sig.Sequence != acc.GetSequence() { + return ctx, sdkerrors.Wrapf( + sdkerrors.ErrWrongSequence, + "account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, + ) } // retrieve signer data @@ -296,7 +289,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, tx) if err != nil { var errMsg string - if onlyAminoSigners { + if OnlyLegacyAminoSigners(sig.Data) { // If all signers are using SIGN_MODE_LEGACY_AMINO, we rely on VerifySignature to check account sequence number, // and therefore communicate sequence number as a potential cause of error. errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d), sequence (%d) and chain-id (%s)", accNum, acc.GetSequence(), chainID)