Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/auth): allow empty public keys for GetSignBytesAdapter #19651

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down
20 changes: 12 additions & 8 deletions x/auth/signing/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions x/auth/signing/adapter_test.go
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines +16 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test TestGetSignBytesAdapterNoPublicKey effectively checks for errors in the scenario with no public key. However, it could be enhanced by adding more detailed assertions to verify the behavior of GetSignBytesAdapter more thoroughly, such as ensuring the output is as expected when PubKey is nil.

}
Loading