From 0cdad0fe106c03d9473a973d5ea45e026cefe9f0 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 19 Jan 2024 08:54:12 +1300 Subject: [PATCH 1/2] fix: allow empty public keys when setting signatures --- x/auth/tx/builder.go | 14 ++++++++++---- x/auth/tx/builder_test.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index ba7955b0ec5..fd03334f7be 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -352,11 +352,17 @@ func (w *wrapper) SetSignatures(signatures ...signing.SignatureV2) error { rawSigs := make([][]byte, n) for i, sig := range signatures { - var modeInfo *tx.ModeInfo + var ( + modeInfo *tx.ModeInfo + pubKey *codectypes.Any + err error + ) modeInfo, rawSigs[i] = SignatureDataToModeInfoAndSig(sig.Data) - pubKey, err := codectypes.NewAnyWithValue(sig.PubKey) - if err != nil { - return err + if sig.PubKey != nil { + pubKey, err = codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return err + } } signerInfos[i] = &tx.SignerInfo{ PublicKey: pubKey, diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 3ea3ae0c3b4..2fb88905beb 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -127,6 +127,20 @@ func TestTxBuilder(t *testing.T) { }) } +func TestSetSignaturesNoPublicKey(t *testing.T) { + _, pubkey, _ := testdata.KeyTestPubAddr() + txBuilder := newBuilder(nil) + sig2 := signing.SignatureV2{ + Data: &signing.SingleSignatureData{ + SignMode: signing.SignMode_SIGN_MODE_DIRECT, + Signature: legacy.Cdc.MustMarshal(pubkey), + }, + Sequence: 1, + } + err := txBuilder.SetSignatures(sig2) + require.NoError(t, err) +} + func TestBuilderValidateBasic(t *testing.T) { // keys and addresses _, pubKey1, addr1 := testdata.KeyTestPubAddr() From b01ea11312f47fbe308e26af2e1bfa990ce002db Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Fri, 19 Jan 2024 09:05:22 +1300 Subject: [PATCH 2/2] add changelog --- x/auth/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 226d7e357e7..2409c10e3b4 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -49,3 +49,5 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18817](https://github.com/cosmos/cosmos-sdk/pull/18817) SigVerification, GasConsumption, IncreaseSequence ante decorators have all been joined into one SigVerification decorator. Gas consumption during TX validation flow has reduced. ### Bug Fixes + +* [#19106](https://github.com/cosmos/cosmos-sdk/pull/19106) Allow empty public keys when setting signatures. Public keys aren't needed for every transaction.