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)
This commit is contained in:
parent
07453203cd
commit
78c3c4e92d
@ -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)
|
||||
}
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user