From cf7d5b0fb09933ac0f0fb26cde15769f068ad923 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 5 Mar 2024 23:41:14 +0800 Subject: [PATCH 1/3] fix: allow empty public keys for auth --- CHANGELOG.md | 1 + x/auth/signing/adapter.go | 20 ++++++++++++-------- x/auth/signing/adapter_test.go | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 x/auth/signing/adapter_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c5d15e6869f4..b986618e189b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (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) [#](https://github.com/cosmos/cosmos-sdk/pull/) Allow empty public keys in `GetSignBytesAdapter`. ### 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..85fe375c3817 --- /dev/null +++ b/x/auth/signing/adapter_test.go @@ -0,0 +1,32 @@ +package signing_test + +import ( + "context" + "testing" + + 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" + "github.com/stretchr/testify/require" +) + +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) +} From 8a829557ba6369052a026bacd8830dbffc6c819f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 5 Mar 2024 23:50:16 +0800 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b986618e189b..ddb50a0f026f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,7 +80,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (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) [#](https://github.com/cosmos/cosmos-sdk/pull/) Allow empty public keys in `GetSignBytesAdapter`. +* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. ### Bug Fixes From 93bae50d6b33f4a8a407a8f95c5aefb96cc25d8d Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 6 Mar 2024 00:00:16 +0800 Subject: [PATCH 3/3] fix lint --- x/auth/signing/adapter_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go index 85fe375c3817..2a90b7030a36 100644 --- a/x/auth/signing/adapter_test.go +++ b/x/auth/signing/adapter_test.go @@ -4,11 +4,13 @@ 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" - "github.com/stretchr/testify/require" ) func TestGetSignBytesAdapterNoPublicKey(t *testing.T) {