Skip to content

Commit 8f7cdaf

Browse files
update SigVerifiableTx.GetPubKeys to return an error (#8828)
closes: #8129
1 parent 24ed401 commit 8f7cdaf

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ Ref: https://keepachangelog.com/en/1.0.0/
4141
* [\#8559](https://github.com/cosmos/cosmos-sdk/pull/8559) Added Protobuf compatible secp256r1 ECDSA signatures.
4242
* [\#8786](https://github.com/cosmos/cosmos-sdk/pull/8786) Enabled secp256r1 in x/auth.
4343

44+
4445
### Client Breaking Changes
4546

4647
* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
4748
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
4849
* (crypto/ed25519) [\#8690] Adopt zip1215 ed2559 verification rules.
4950

51+
5052
### API Breaking Changes
5153

5254
* (keyring) [#\8662](https://github.com/cosmos/cosmos-sdk/pull/8662) `NewMnemonic` now receives an additional `passphrase` argument to secure the key generated by the bip39 mnemonic.
@@ -58,6 +60,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
5860
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
5961
* (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added.
6062
* (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking
63+
* (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error.
64+
6165

6266
### State Machine Breaking
6367

x/auth/ante/sigverify.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
5959
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type")
6060
}
6161

62-
pubkeys := sigTx.GetPubKeys()
62+
pubkeys, err := sigTx.GetPubKeys()
63+
if err != nil {
64+
return ctx, err
65+
}
6366
signers := sigTx.GetSigners()
6467

6568
for i, pk := range pubkeys {
@@ -339,7 +342,10 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
339342
}
340343

341344
params := vscd.ak.GetParams(ctx)
342-
pubKeys := sigTx.GetPubKeys()
345+
pubKeys, err := sigTx.GetPubKeys()
346+
if err != nil {
347+
return ctx, err
348+
}
343349

344350
sigCount := 0
345351
for _, pk := range pubKeys {

x/auth/legacy/legacytx/stdtx.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ func (tx StdTx) GetSignaturesV2() ([]signing.SignatureV2, error) {
246246

247247
// GetPubkeys returns the pubkeys of signers if the pubkey is included in the signature
248248
// If pubkey is not included in the signature, then nil is in the slice instead
249-
func (tx StdTx) GetPubKeys() []cryptotypes.PubKey {
249+
func (tx StdTx) GetPubKeys() ([]cryptotypes.PubKey, error) {
250250
pks := make([]cryptotypes.PubKey, len(tx.Signatures))
251251

252252
for i, stdSig := range tx.Signatures {
253253
pks[i] = stdSig.GetPubKey()
254254
}
255255

256-
return pks
256+
return pks, nil
257257
}
258258

259259
// GetGas returns the Gas in StdFee

x/auth/signing/sig_verifiable_tx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
type SigVerifiableTx interface {
1212
types.Tx
1313
GetSigners() []types.AccAddress
14-
GetPubKeys() []cryptotypes.PubKey // If signer already has pubkey in context, this list will have nil in its place
14+
GetPubKeys() ([]cryptotypes.PubKey, error) // If signer already has pubkey in context, this list will have nil in its place
1515
GetSignaturesV2() ([]signing.SignatureV2, error)
1616
}
1717

x/auth/testutil/suite.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() {
258258
tx3Sigs, err := tx3.GetSignaturesV2()
259259
s.Require().NoError(err)
260260
s.Require().Equal([]signingtypes.SignatureV2{sig}, tx3Sigs)
261-
s.Require().Equal([]cryptotypes.PubKey{pubkey}, tx3.GetPubKeys())
261+
pks, err := tx3.GetPubKeys()
262+
s.Require().NoError(err)
263+
s.Require().Equal([]cryptotypes.PubKey{pubkey}, pks)
262264

263265
log("JSON encode transaction")
264266
jsonTxBytes, err := s.TxConfig.TxJSONEncoder()(tx)
@@ -277,7 +279,9 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() {
277279
tx3Sigs, err = tx3.GetSignaturesV2()
278280
s.Require().NoError(err)
279281
s.Require().Equal([]signingtypes.SignatureV2{sig}, tx3Sigs)
280-
s.Require().Equal([]cryptotypes.PubKey{pubkey}, tx3.GetPubKeys())
282+
pks, err = tx3.GetPubKeys()
283+
s.Require().NoError(err)
284+
s.Require().Equal([]cryptotypes.PubKey{pubkey}, pks)
281285
}
282286

283287
func (s *TxConfigTestSuite) TestWrapTxBuilder() {

x/auth/tx/builder.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
88
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
99
sdk "github.com/cosmos/cosmos-sdk/types"
10+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1011
"github.com/cosmos/cosmos-sdk/types/tx"
1112
"github.com/cosmos/cosmos-sdk/types/tx/signing"
1213
"github.com/cosmos/cosmos-sdk/x/auth/ante"
@@ -100,7 +101,7 @@ func (w *wrapper) GetSigners() []sdk.AccAddress {
100101
return w.tx.GetSigners()
101102
}
102103

103-
func (w *wrapper) GetPubKeys() []cryptotypes.PubKey {
104+
func (w *wrapper) GetPubKeys() ([]cryptotypes.PubKey, error) {
104105
signerInfos := w.tx.AuthInfo.SignerInfos
105106
pks := make([]cryptotypes.PubKey, len(signerInfos))
106107

@@ -111,13 +112,16 @@ func (w *wrapper) GetPubKeys() []cryptotypes.PubKey {
111112
continue
112113
}
113114

114-
pk, ok := si.PublicKey.GetCachedValue().(cryptotypes.PubKey)
115+
pkAny := si.PublicKey.GetCachedValue()
116+
pk, ok := pkAny.(cryptotypes.PubKey)
115117
if ok {
116118
pks[i] = pk
119+
} else {
120+
return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "Expecting PubKey, got: %T", pkAny)
117121
}
118122
}
119123

120-
return pks
124+
return pks, nil
121125
}
122126

123127
func (w *wrapper) GetGas() uint64 {
@@ -165,7 +169,10 @@ func (w *wrapper) GetTimeoutHeight() uint64 {
165169
func (w *wrapper) GetSignaturesV2() ([]signing.SignatureV2, error) {
166170
signerInfos := w.tx.AuthInfo.SignerInfos
167171
sigs := w.tx.Signatures
168-
pubKeys := w.GetPubKeys()
172+
pubKeys, err := w.GetPubKeys()
173+
if err != nil {
174+
return nil, err
175+
}
169176
n := len(signerInfos)
170177
res := make([]signing.SignatureV2, n)
171178

x/auth/tx/builder_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func TestTxBuilder(t *testing.T) {
8989
txBuilder.SetMemo(memo)
9090
require.Equal(t, bodyBytes, txBuilder.getBodyBytes())
9191
require.Equal(t, len(msgs), len(txBuilder.GetMsgs()))
92-
require.Equal(t, 0, len(txBuilder.GetPubKeys()))
92+
pks, err := txBuilder.GetPubKeys()
93+
require.NoError(t, err)
94+
require.Empty(t, pks)
9395

9496
t.Log("verify that updated AuthInfo results in the correct getAuthInfoBytes and GetPubKeys")
9597
require.NotEqual(t, authInfoBytes, txBuilder.getAuthInfoBytes())
@@ -104,8 +106,10 @@ func TestTxBuilder(t *testing.T) {
104106
require.Equal(t, authInfoBytes, txBuilder.getAuthInfoBytes())
105107

106108
require.Equal(t, len(msgs), len(txBuilder.GetMsgs()))
107-
require.Equal(t, 1, len(txBuilder.GetPubKeys()))
108-
require.Equal(t, legacy.Cdc.MustMarshalBinaryBare(pubkey), legacy.Cdc.MustMarshalBinaryBare(txBuilder.GetPubKeys()[0]))
109+
pks, err = txBuilder.GetPubKeys()
110+
require.NoError(t, err)
111+
require.Equal(t, 1, len(pks))
112+
require.True(t, pubkey.Equals(pks[0]))
109113

110114
any, err = codectypes.NewAnyWithValue(testdata.NewTestMsg())
111115
require.NoError(t, err)

0 commit comments

Comments
 (0)