From 5a95a057ed30d1315e087eac8fbcfbaeffa9ac9d Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 14 Nov 2022 15:30:32 +0100 Subject: [PATCH 1/2] added check for empty path --- modules/light-clients/06-solomachine/client_state.go | 4 ++++ modules/light-clients/06-solomachine/client_state_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 17b07364927..5c17392e919 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -125,6 +125,10 @@ func (cs *ClientState) VerifyMembership( return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path") } + if len(merklePath.String()) == 0 { + return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") + } + signBytes := &SignBytes{ Sequence: sequence, Timestamp: timestamp, diff --git a/modules/light-clients/06-solomachine/client_state_test.go b/modules/light-clients/06-solomachine/client_state_test.go index d28374d54bb..1c6cfa8b151 100644 --- a/modules/light-clients/06-solomachine/client_state_test.go +++ b/modules/light-clients/06-solomachine/client_state_test.go @@ -541,6 +541,13 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { }, false, }, + { + "empty path", + func() { + path = []byte("") + }, + false, + }, } for _, tc := range testCases { From e182349d30bf291e59da79967f7746077cbeda6d Mon Sep 17 00:00:00 2001 From: Charly Date: Tue, 15 Nov 2022 16:23:31 +0100 Subject: [PATCH 2/2] update test, pr comments --- modules/light-clients/06-solomachine/client_state.go | 2 +- modules/light-clients/06-solomachine/client_state_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 94911929549..0d515356eee 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -125,7 +125,7 @@ func (cs *ClientState) VerifyMembership( return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } - if len(merklePath.String()) == 0 { + if merklePath.Empty() { return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "path is empty") } diff --git a/modules/light-clients/06-solomachine/client_state_test.go b/modules/light-clients/06-solomachine/client_state_test.go index 58511619939..11507a5eda9 100644 --- a/modules/light-clients/06-solomachine/client_state_test.go +++ b/modules/light-clients/06-solomachine/client_state_test.go @@ -520,7 +520,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { { "empty path", func() { - path = []byte("") + path = commitmenttypes.MerklePath{} }, false, },