From 343c6ada4999128123e54150e259eeba948b403f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:24:20 +0100 Subject: [PATCH] fix: allow empty public keys when setting signatures (backport #19106) (#19108) Co-authored-by: Callum Waters Co-authored-by: Julien Robert --- CHANGELOG.md | 3 ++- x/auth/tx/builder.go | 16 +++++++++++----- x/auth/tx/builder_test.go | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dcb1765198..206ef92ade8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (server) [#18920](https://github.com/cosmos/cosmos-sdk/pull/18920) fixes consensus failure while restart node with wrong `chainId` in genesis. +* [#19106](https://github.com/cosmos/cosmos-sdk/pull/19106) Allow empty public keys when setting signatures. Public keys aren't needed for every transaction. +* (server) [#18920](https://github.com/cosmos/cosmos-sdk/pull/18920) Fixes consensus failure while restart node with wrong `chainId` in genesis. ## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20 diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index ed84b6a23ed..f1d85865808 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -288,14 +288,20 @@ 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) - any, 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: any, + PublicKey: pubKey, ModeInfo: modeInfo, Sequence: sig.Sequence, } diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index f7122dd3921..b4c1556e5c3 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -123,6 +123,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()