diff --git a/modules/core/02-client/legacy/v100/solomachine.go b/modules/core/02-client/legacy/v100/solomachine.go index 8fa99104316..c953fc419b6 100644 --- a/modules/core/02-client/legacy/v100/solomachine.go +++ b/modules/core/02-client/legacy/v100/solomachine.go @@ -227,7 +227,7 @@ func (cs *ClientState) VerifyMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, value []byte, ) error { panic("legacy solo machine is deprecated!") @@ -242,7 +242,7 @@ func (cs *ClientState) VerifyNonMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, ) error { panic("legacy solo machine is deprecated") } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 64c6cdb43cf..ad9cfac718f 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -41,11 +41,6 @@ func (k Keeper) VerifyClientState( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - bz, err := k.cdc.MarshalInterface(clientState) if err != nil { return err @@ -54,7 +49,7 @@ func (k Keeper) VerifyClientState( if err := targetClient.VerifyMembership( ctx, clientStore, k.cdc, height, 0, 0, // skip delay period checks for non-packet processing verification - proof, path, bz, + proof, merklePath, bz, ); err != nil { return sdkerrors.Wrapf(err, "failed client state verification for target client: %s", clientID) } @@ -90,11 +85,6 @@ func (k Keeper) VerifyClientConsensusState( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - bz, err := k.cdc.MarshalInterface(consensusState) if err != nil { return err @@ -103,7 +93,7 @@ func (k Keeper) VerifyClientConsensusState( if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, 0, 0, // skip delay period checks for non-packet processing verification - proof, path, bz, + proof, merklePath, bz, ); err != nil { return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", clientID) } @@ -139,11 +129,6 @@ func (k Keeper) VerifyConnectionState( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection) @@ -157,7 +142,7 @@ func (k Keeper) VerifyConnectionState( if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, 0, 0, // skip delay period checks for non-packet processing verification - proof, path, bz, + proof, merklePath, bz, ); err != nil { return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", clientID) } @@ -194,11 +179,6 @@ func (k Keeper) VerifyChannelState( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - channelEnd, ok := channel.(channeltypes.Channel) if !ok { return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid channel type %T", channel) @@ -212,7 +192,7 @@ func (k Keeper) VerifyChannelState( if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, 0, 0, // skip delay period checks for non-packet processing verification - proof, path, bz, + proof, merklePath, bz, ); err != nil { return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", clientID) } @@ -254,15 +234,10 @@ func (k Keeper) VerifyPacketCommitment( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, timeDelay, blockDelay, - proof, path, commitmentBytes, + proof, merklePath, commitmentBytes, ); err != nil { return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", clientID) } @@ -304,15 +279,10 @@ func (k Keeper) VerifyPacketAcknowledgement( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, timeDelay, blockDelay, - proof, path, channeltypes.CommitAcknowledgement(acknowledgement), + proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement), ); err != nil { return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID) } @@ -354,15 +324,10 @@ func (k Keeper) VerifyPacketReceiptAbsence( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - if err := clientState.VerifyNonMembership( ctx, clientStore, k.cdc, height, timeDelay, blockDelay, - proof, path, + proof, merklePath, ); err != nil { return sdkerrors.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID) } @@ -403,15 +368,10 @@ func (k Keeper) VerifyNextSequenceRecv( return err } - path, err := k.cdc.Marshal(&merklePath) - if err != nil { - return err - } - if err := clientState.VerifyMembership( ctx, clientStore, k.cdc, height, timeDelay, blockDelay, - proof, path, sdk.Uint64ToBigEndian(nextSequenceRecv), + proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv), ); err != nil { return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID) } diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index ac76a647dc5..81dea3373c5 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -74,7 +74,7 @@ type ClientState interface { delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path Path, value []byte, ) error @@ -88,7 +88,7 @@ type ClientState interface { delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path Path, ) error // VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update. diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 17b07364927..36cb1135540 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -112,7 +112,7 @@ func (cs *ClientState) VerifyMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, value []byte, ) error { publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof) @@ -120,9 +120,9 @@ func (cs *ClientState) VerifyMembership( return err } - var merklePath commitmenttypes.MerklePath - if err := cdc.Unmarshal(path, &merklePath); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path") + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } signBytes := &SignBytes{ @@ -159,16 +159,16 @@ func (cs *ClientState) VerifyNonMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, ) error { publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof) if err != nil { return err } - var merklePath commitmenttypes.MerklePath - if err := cdc.Unmarshal(path, &merklePath); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path") + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } signBytes := &SignBytes{ diff --git a/modules/light-clients/06-solomachine/client_state_test.go b/modules/light-clients/06-solomachine/client_state_test.go index 71a2a898e07..3fabbb21783 100644 --- a/modules/light-clients/06-solomachine/client_state_test.go +++ b/modules/light-clients/06-solomachine/client_state_test.go @@ -12,6 +12,7 @@ import ( solomachine "github.com/cosmos/ibc-go/v6/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v6/testing" + ibcmock "github.com/cosmos/ibc-go/v6/testing/mock" ) const ( @@ -147,7 +148,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { clientState *solomachine.ClientState err error height clienttypes.Height - path []byte + path exported.Path proof []byte testingPath *ibctesting.Path signBytes solomachine.SignBytes @@ -170,12 +171,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { clientStateBz, err := suite.chainA.Codec.Marshal(clientState) suite.Require().NoError(err) - merklePath := suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) + path = suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) signBytes = solomachine.SignBytes{ Sequence: sm.GetHeight().GetRevisionHeight(), Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: clientStateBz, } @@ -189,9 +190,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -205,12 +203,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { consensusStateBz, err := suite.chainA.Codec.Marshal(consensusState) suite.Require().NoError(err) - merklePath := sm.GetConsensusStatePath(counterpartyClientIdentifier, height) + path = sm.GetConsensusStatePath(counterpartyClientIdentifier, height) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: consensusStateBz, } @@ -224,9 +222,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -243,12 +238,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { connectionEndBz, err := suite.chainA.Codec.Marshal(&connectionEnd) suite.Require().NoError(err) - merklePath := sm.GetConnectionStatePath(ibctesting.FirstConnectionID) + path = sm.GetConnectionStatePath(ibctesting.FirstConnectionID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: connectionEndBz, } @@ -262,9 +257,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -282,12 +274,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { channelEndBz, err := suite.chainA.Codec.Marshal(&channelEnd) suite.Require().NoError(err) - merklePath := sm.GetChannelStatePath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = sm.GetChannelStatePath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: channelEndBz, } @@ -301,9 +293,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -318,12 +307,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { nextSeqRecv, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetNextSequenceRecv(suite.chainA.GetContext(), ibctesting.MockPort, ibctesting.FirstChannelID) suite.Require().True(found) - merklePath := sm.GetNextSequenceRecvPath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = sm.GetNextSequenceRecvPath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: sdk.Uint64ToBigEndian(nextSeqRecv), } @@ -337,9 +326,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -360,12 +346,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { ) commitmentBz := channeltypes.CommitPacket(suite.chainA.Codec, packet) - merklePath := sm.GetPacketCommitmentPath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = sm.GetPacketCommitmentPath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: commitmentBz, } @@ -379,9 +365,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -390,12 +373,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { { "success: packet acknowledgement verification", func() { - merklePath := sm.GetPacketAcknowledgementPath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = sm.GetPacketAcknowledgementPath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: ibctesting.MockAcknowledgement, } @@ -409,9 +392,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -420,12 +400,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { { "success: packet receipt verification", func() { - merklePath := sm.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = sm.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.Sequence, Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: []byte{byte(1)}, // packet receipt is stored as a single byte } @@ -439,9 +419,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -467,19 +444,16 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { false, }, { - "malformed merkle path fails to unmarshal", + "invalid path type", func() { - path = []byte("invalid path") + path = ibcmock.KeyPath{} }, false, }, { "malformed proof fails to unmarshal", func() { - merklePath := suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - + path = suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) proof = []byte("invalid proof") }, false, @@ -555,12 +529,12 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { clientState = sm.ClientState() height = clienttypes.NewHeight(sm.GetHeight().GetRevisionNumber(), sm.GetHeight().GetRevisionHeight()) - merklePath := commitmenttypes.NewMerklePath("ibc", "solomachine") + path = commitmenttypes.NewMerklePath("ibc", "solomachine") signBytes = solomachine.SignBytes{ Sequence: sm.GetHeight().GetRevisionHeight(), Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: []byte("solomachine"), } @@ -574,9 +548,6 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) @@ -641,7 +612,7 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { clientState *solomachine.ClientState err error height clienttypes.Height - path []byte + path exported.Path proof []byte signBytes solomachine.SignBytes ) @@ -659,12 +630,12 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { { "success: packet receipt absence verification", func() { - merklePath := suite.solomachine.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID) + path = suite.solomachine.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID) signBytes = solomachine.SignBytes{ Sequence: sm.GetHeight().GetRevisionHeight(), Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: nil, } @@ -678,9 +649,6 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) }, @@ -706,19 +674,16 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { false, }, { - "malformed merkle path fails to unmarshal", + "invalid path type", func() { - path = []byte("invalid path") + path = ibcmock.KeyPath{} }, false, }, { "malformed proof fails to unmarshal", func() { - merklePath := suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - + path = suite.solomachine.GetClientStatePath(counterpartyClientIdentifier) proof = []byte("invalid proof") }, false, @@ -804,12 +769,12 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { clientState = sm.ClientState() height = clienttypes.NewHeight(sm.GetHeight().GetRevisionNumber(), sm.GetHeight().GetRevisionHeight()) - merklePath := commitmenttypes.NewMerklePath("ibc", "solomachine") + path = commitmenttypes.NewMerklePath("ibc", "solomachine") signBytes = solomachine.SignBytes{ Sequence: sm.GetHeight().GetRevisionHeight(), Timestamp: sm.Time, Diversifier: sm.Diversifier, - Path: []byte(merklePath.String()), + Path: []byte(path.String()), Data: nil, } @@ -823,9 +788,6 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { Timestamp: sm.Time, } - path, err = suite.chainA.Codec.Marshal(&merklePath) - suite.Require().NoError(err) - proof, err = suite.chainA.Codec.Marshal(signatureDoc) suite.Require().NoError(err) diff --git a/modules/light-clients/07-tendermint/client_state.go b/modules/light-clients/07-tendermint/client_state.go index dc434912505..b1de29b44b7 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -210,7 +210,7 @@ func (cs ClientState) VerifyMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, value []byte, ) error { if cs.GetLatestHeight().LT(height) { @@ -229,9 +229,9 @@ func (cs ClientState) VerifyMembership( return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } - var merklePath commitmenttypes.MerklePath - if err := cdc.Unmarshal(path, &merklePath); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path") + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) @@ -256,7 +256,7 @@ func (cs ClientState) VerifyNonMembership( delayTimePeriod uint64, delayBlockPeriod uint64, proof []byte, - path []byte, + path exported.Path, ) error { if cs.GetLatestHeight().LT(height) { return sdkerrors.Wrapf( @@ -274,9 +274,9 @@ func (cs ClientState) VerifyNonMembership( return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } - var merklePath commitmenttypes.MerklePath - if err := cdc.Unmarshal(path, &merklePath); err != nil { - return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path") + merklePath, ok := path.(commitmenttypes.MerklePath) + if !ok { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) diff --git a/modules/light-clients/07-tendermint/client_state_test.go b/modules/light-clients/07-tendermint/client_state_test.go index ba3d04f337e..64ffff0fd50 100644 --- a/modules/light-clients/07-tendermint/client_state_test.go +++ b/modules/light-clients/07-tendermint/client_state_test.go @@ -214,9 +214,10 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { testingpath *ibctesting.Path delayTimePeriod uint64 delayBlockPeriod uint64 + err error proofHeight exported.Height proof []byte - path []byte + path exported.Path value []byte ) @@ -236,10 +237,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { "successful ConsensusState verification", func() { key := host.FullConsensusStateKey(testingpath.EndpointB.ClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -254,10 +252,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { "successful Connection verification", func() { key := host.ConnectionKey(testingpath.EndpointB.ConnectionID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -272,10 +267,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { "successful Channel verification", func() { key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -296,10 +288,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, clienttypes.NewHeight(1, 100), 0) key := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -320,10 +309,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { key := host.PacketAcknowledgementKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -347,10 +333,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { key := host.NextSequenceRecvKey(packet.GetSourcePort(), packet.GetSourceChannel()) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -363,10 +346,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { "successful verification outside IBC store", func() { key := transfertypes.PortKey merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) suite.Require().NoError(err) clientState := testingpath.EndpointA.GetClientState() @@ -407,9 +387,11 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { }, false, }, { - "failed to unmarshal merkle path", func() { - path = []byte("invalid merkle path") - }, false, + "invalid path type", + func() { + path = ibcmock.KeyPath{} + }, + false, }, { "failed to unmarshal merkle proof", func() { @@ -446,10 +428,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { // may be overwritten by malleate() key := host.FullClientStateKey(testingpath.EndpointB.ClientID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainA.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -484,9 +463,10 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { testingpath *ibctesting.Path delayTimePeriod uint64 delayBlockPeriod uint64 + err error proofHeight exported.Height + path exported.Path proof []byte - path []byte invalidClientID = "09-tendermint" invalidConnectionID = "connection-100" invalidChannelID = "channel-800" @@ -509,10 +489,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful ConsensusState verification of non membership", func() { key := host.FullConsensusStateKey(invalidClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -523,10 +500,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful Connection verification of non membership", func() { key := host.ConnectionKey(invalidConnectionID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -537,10 +511,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful Channel verification of non membership", func() { key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, invalidChannelID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -552,10 +523,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { // make packet commitment proof key := host.PacketCommitmentKey(invalidPortID, invalidChannelID, 1) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -565,10 +533,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful Acknowledgement verification of non membership", func() { key := host.PacketAcknowledgementKey(invalidPortID, invalidChannelID, 1) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -579,10 +544,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful NextSequenceRecv verification of non membership", func() { key := host.NextSequenceRecvKey(invalidPortID, invalidChannelID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = testingpath.EndpointB.QueryProof(key) @@ -593,10 +555,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful verification of non membership outside IBC store", func() { key := []byte{0x08} merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainB.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) suite.Require().NoError(err) clientState := testingpath.EndpointA.GetClientState() @@ -634,9 +593,11 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { }, false, }, { - "failed to unmarshal merkle path", func() { - path = []byte("invalid merkle path") - }, false, + "invalid path type", + func() { + path = ibcmock.KeyPath{} + }, + false, }, { "failed to unmarshal merkle proof", func() { @@ -653,10 +614,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { // change the value being proved key := host.FullClientStateKey(testingpath.EndpointB.ClientID) merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainA.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) @@ -682,10 +640,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { key := host.FullClientStateKey("invalid-client-id") merklePath := commitmenttypes.NewMerklePath(string(key)) - merklePath, err := commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - path, err = suite.chainA.Codec.Marshal(&merklePath) + path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) proof, proofHeight = suite.chainB.QueryProof(key) diff --git a/testing/mock/mock.go b/testing/mock/mock.go index d8fa60806a9..f99fac85830 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -17,6 +17,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" + "github.com/cosmos/ibc-go/v6/modules/core/exported" ) const ( @@ -150,3 +151,18 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } + +var _ exported.Path = KeyPath{} + +// KeyPath defines a placeholder struct which implements the exported.Path interface +type KeyPath struct{} + +// String implements the exported.Path interface +func (KeyPath) String() string { + return "" +} + +// Empty implements the exported.Path interface +func (KeyPath) Empty() bool { + return false +}