Skip to content

Commit

Permalink
fix!: Remove onlyAminoSigners in sequence check (#10029)
Browse files Browse the repository at this point in the history
## 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)

(cherry picked from commit 78c3c4e)

# Conflicts:
#	client/tx/legacy.go
#	client/tx/legacy_test.go
  • Loading branch information
robert-zaremba authored and mergify-bot committed Aug 30, 2021
1 parent 370134c commit 28024b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 55 deletions.
25 changes: 4 additions & 21 deletions client/tx/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
<<<<<<< HEAD
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
=======
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
>>>>>>> 78c3c4e92 (fix!: Remove onlyAminoSigners in sequence check (#10029))
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

Expand Down Expand Up @@ -65,24 +69,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)
}
25 changes: 4 additions & 21 deletions client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
<<<<<<< HEAD
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
=======
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
>>>>>>> 78c3c4e92 (fix!: Remove onlyAminoSigners in sequence check (#10029))
"github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
Expand Down Expand Up @@ -149,27 +153,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))
}
19 changes: 6 additions & 13 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 28024b8

Please sign in to comment.