From 83bbf801ce4e8547837ec92bce5927eb1e3ea48a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 6 Mar 2024 20:45:26 +0800 Subject: [PATCH] refactor(x/auth): allow empty public keys for GetSignBytesAdapter (#19651) (cherry picked from commit 06a398931e0e4e0e1d0bac6832381e458e45ad24) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 46 ++++++++++++++++++++++++++++++++++ x/auth/signing/adapter.go | 20 +++++++++------ x/auth/signing/adapter_test.go | 34 +++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 x/auth/signing/adapter_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b94e459ec92..2070bf2983d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,53 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +<<<<<<< HEAD ## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-XX-XX +======= +Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. + +### Features + +* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` it in runtime. This service is present in all modules (when using depinject). +* (types) [#19164](https://github.com/cosmos/cosmos-sdk/pull/19164) Add a ValueCodec for the math.Uint type that can be used in collections maps. +* (types) [#19281](https://github.com/cosmos/cosmos-sdk/pull/19281) Added a new method, `IsGT`, for `types.Coin`. This method is used to check if a `types.Coin` is greater than another `types.Coin`. +* (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code. +* (client) [#18101](https://github.com/cosmos/cosmos-sdk/pull/18101) Add a `keyring-default-keyname` in `client.toml` for specifying a default key name, and skip the need to use the `--from` flag when signing transactions. +* (tests) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) Added helper method `SubmitTestTx` in testutil to broadcast test txns to test e2e tests. +* (client) [#17513](https://github.com/cosmos/cosmos-sdk/pull/17513) Allow overwriting `client.toml`. Use `client.CreateClientConfig` in place of `client.ReadFromClientConfig` and provide a custom template and a custom config. +* (runtime) [#18475](https://github.com/cosmos/cosmos-sdk/pull/18475) Adds an implementation for core.branch.Service. +* (baseapp) [#18499](https://github.com/cosmos/cosmos-sdk/pull/18499) Add `MsgRouter` response type from message name function. +* (types) [#18768](https://github.com/cosmos/cosmos-sdk/pull/18768) Add MustValAddressFromBech32 function. +* (gRPC) [#19049](https://github.com/cosmos/cosmos-sdk/pull/19049) Add debug log prints for each gRPC request. +* (x/consensus) [#19483](https://github.com/cosmos/cosmos-sdk/pull/19483) Add consensus messages registration to consensus module. + +### Improvements + +* (server) [#19455](https://github.com/cosmos/cosmos-sdk/pull/19455) Allow calling back into the application struct in PostSetup. +* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) The notion of basic manager does not exist anymore. + * The module manager now can do everything that the basic manager was doing. + * `AppModuleBasic` has been deprecated for extension interfaces. Modules can now implement `HasRegisterInterfaces`, `HasGRPCGateway` and `HasAminoCodec` when relevant. + * SDK modules now directly implement those extension interfaces on `AppModule` instead of `AppModuleBasic`. +* (client/keys) [#18950](https://github.com/cosmos/cosmos-sdk/pull/18950) Improve ` keys add`, ` keys import` and ` keys rename` by checking name validation. +* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. +* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. +* (client/keys) [#18703](https://github.com/cosmos/cosmos-sdk/pull/18703) Improve ` keys add` and ` keys show` by checking whether there are duplicate keys in the multisig case. + * Usage of `Must...` kind of functions are avoided in keeper methods. +* (client/keys) [#18687](https://github.com/cosmos/cosmos-sdk/pull/18687) Improve ` keys mnemonic` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (client/keys) [#18684](https://github.com/cosmos/cosmos-sdk/pull/18684) Improve ` keys export` by displaying unarmored hex private key discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (client/keys) [#18663](https://github.com/cosmos/cosmos-sdk/pull/18663) Improve ` keys add` by displaying mnemonic discreetly on an alternate screen and adding `--indiscreet` option to disable it. +* (types) [#18440](https://github.com/cosmos/cosmos-sdk/pull/18440) Add `AmountOfNoValidation` to `sdk.DecCoins`. +* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details. +* (crypto/keyring) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Simplify keyring interfaces to use `[]byte` instead of `sdk.Address` for addresses. +* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated `fmt.Errorf` errors and using `errors.New` where appropriate. +* (rpc) [#17470](https://github.com/cosmos/cosmos-sdk/pull/17470) Avoid open 0.0.0.0 to public by default and add `listen-ip-address` argument for `testnet init-files` cmd. +* (types) [#17670](https://github.com/cosmos/cosmos-sdk/pull/17670) Use `ctx.CometInfo` in place of `ctx.VoteInfos` +* [#17733](https://github.com/cosmos/cosmos-sdk/pull/17733) Ensure `buf export` exports all proto dependencies +* (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1` +* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle. +* (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding +* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. +>>>>>>> 06a398931 (refactor(x/auth): allow empty public keys for GetSignBytesAdapter (#19651)) ### Bug Fixes diff --git a/x/auth/signing/adapter.go b/x/auth/signing/adapter.go index bb0def2f230f..42b1b82fdc48 100644 --- a/x/auth/signing/adapter.go +++ b/x/auth/signing/adapter.go @@ -41,20 +41,24 @@ func GetSignBytesAdapter( return nil, err } - anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey) - if err != nil { - return nil, err - } + var pubKey *anypb.Any + if signerData.PubKey != nil { + anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey) + if err != nil { + return nil, err + } + pubKey = &anypb.Any{ + TypeUrl: anyPk.TypeUrl, + Value: anyPk.Value, + } + } txSignerData := txsigning.SignerData{ ChainID: signerData.ChainID, AccountNumber: signerData.AccountNumber, Sequence: signerData.Sequence, Address: signerData.Address, - PubKey: &anypb.Any{ - TypeUrl: anyPk.TypeUrl, - Value: anyPk.Value, - }, + PubKey: pubKey, } // Generate the bytes to be signed. return handlerMap.GetSignBytes(ctx, txSignMode, txSignerData, txData) diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go new file mode 100644 index 000000000000..2a90b7030a36 --- /dev/null +++ b/x/auth/signing/adapter_test.go @@ -0,0 +1,34 @@ +package signing_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + authsign "cosmossdk.io/x/auth/signing" + + "github.com/cosmos/cosmos-sdk/testutil/testdata" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/types/tx/signing" +) + +func TestGetSignBytesAdapterNoPublicKey(t *testing.T) { + encodingConfig := moduletestutil.MakeTestEncodingConfig() + txConfig := encodingConfig.TxConfig + _, _, addr := testdata.KeyTestPubAddr() + signerData := authsign.SignerData{ + Address: addr.String(), + ChainID: "test-chain", + AccountNumber: 11, + Sequence: 15, + } + w := txConfig.NewTxBuilder() + _, err := authsign.GetSignBytesAdapter( + context.Background(), + txConfig.SignModeHandler(), + signing.SignMode_SIGN_MODE_DIRECT, + signerData, + w.GetTx()) + require.NoError(t, err) +}