From b9573767d2f857cb827a694d7851c96d1c4d358f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:07:02 +0100 Subject: [PATCH] fix(x/auth/tx): avoid panic from intoAnyV2 when v1.PublicKey is optional (backport #23148) (#23187) Co-authored-by: mmsqe Co-authored-by: Julien Robert --- CHANGELOG.md | 4 ++++ x/auth/tx/builder.go | 8 +++++--- x/auth/tx/builder_test.go | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 x/auth/tx/builder_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb9b7c151..42ca411e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ Every module contains its own CHANGELOG.md. Please refer to the module you are interested in. +### Bug Fixes + +* (x/auth/tx) [#23148](https://github.com/cosmos/cosmos-sdk/pull/23148) Avoid panic from intoAnyV2 when v1.PublicKey is optional. + ### Deprecated * (modules) [#22994](https://github.com/cosmos/cosmos-sdk/pull/22994) Deprecate `Invariants` and associated methods. diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 2b1c866e8e..17b23f8b64 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -293,9 +293,11 @@ func intoV2SignerInfo(v1s []*tx.SignerInfo) []*txv1beta1.SignerInfo { modeInfoV2 := new(txv1beta1.ModeInfo) intoV2ModeInfo(v1.ModeInfo, modeInfoV2) v2 := &txv1beta1.SignerInfo{ - PublicKey: intoAnyV2([]*codectypes.Any{v1.PublicKey})[0], - ModeInfo: modeInfoV2, - Sequence: v1.Sequence, + ModeInfo: modeInfoV2, + Sequence: v1.Sequence, + } + if v1.PublicKey != nil { + v2.PublicKey = intoAnyV2([]*codectypes.Any{v1.PublicKey})[0] } v2s[i] = v2 } diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go new file mode 100644 index 0000000000..9667f42d7b --- /dev/null +++ b/x/auth/tx/builder_test.go @@ -0,0 +1,15 @@ +package tx + +import ( + "testing" + + any "github.com/cosmos/gogoproto/types/any" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/types/tx" +) + +func TestIntoV2SignerInfo(t *testing.T) { + require.NotNil(t, intoV2SignerInfo([]*tx.SignerInfo{{}})) + require.NotNil(t, intoV2SignerInfo([]*tx.SignerInfo{{PublicKey: &any.Any{}}})) +}