diff --git a/CHANGELOG.md b/CHANGELOG.md index 74834f51b28..92661f15033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (apps/transfer) [\#6440](https://github.com/cosmos/ibc-go/pull/6440) Remove `GetPrefixedDenom`. * (apps/transfer) [\#6508](https://github.com/cosmos/ibc-go/pull/6508) Remove the `DenomTrace` type. * (apps/27-interchain-accounts) [\#6598](https://github.com/cosmos/ibc-go/pull/6598) Mark the `requests` repeated field of `MsgModuleQuerySafe` non-nullable. +* (23-commmitment) [\#6644](https://github.com/cosmos/ibc-go/pull/6644) Introduce commitment/v2 `MerklePath` to include `repeated bytes` in favour of `repeated string`. This supports using merkle path keys which include non UTF-8 encoded runes. * (23-commmitment) [\#6633](https://github.com/cosmos/ibc-go/pull/6633) MerklePath has been changed to use `repeated bytes` in favour of `repeated strings`. ### State Machine Breaking diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index 2a916d89c8b..132332809f9 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -803,7 +803,7 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() { channelProof, proofHeight := path.EndpointB.QueryProof(host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) - merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) merklePath, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -890,7 +890,7 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() { ClientId: ibctesting.FirstClientID, Proof: []byte{0x01}, ProofHeight: types.NewHeight(1, 100), - MerklePath: commitmenttypes.NewMerklePath("/ibc", host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)), + MerklePath: commitmenttypes.NewMerklePath([]byte("/ibc"), host.ChannelKey(mock.PortID, ibctesting.FirstChannelID)), } }, errors.New("empty value"), @@ -902,7 +902,7 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() { ClientId: wasmClientID, // use a client type that is not registered Proof: []byte{0x01}, ProofHeight: types.NewHeight(1, 100), - MerklePath: commitmenttypes.NewMerklePath("/ibc", host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)), + MerklePath: commitmenttypes.NewMerklePath([]byte("/ibc"), host.ChannelKey(mock.PortID, ibctesting.FirstChannelID)), Value: []byte{0x01}, } }, @@ -918,7 +918,7 @@ func (suite *KeeperTestSuite) TestQueryVerifyMembershipProof() { ClientId: path.EndpointA.ClientID, Proof: []byte{0x01}, ProofHeight: types.NewHeight(1, 100), - MerklePath: commitmenttypes.NewMerklePath("/ibc", host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)), + MerklePath: commitmenttypes.NewMerklePath([]byte("/ibc"), host.ChannelKey(mock.PortID, ibctesting.FirstChannelID)), Value: []byte{0x01}, } }, diff --git a/modules/core/02-client/types/query.pb.go b/modules/core/02-client/types/query.pb.go index bad89fe1fdc..8130717af64 100644 --- a/modules/core/02-client/types/query.pb.go +++ b/modules/core/02-client/types/query.pb.go @@ -11,7 +11,7 @@ import ( _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" - types1 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + v2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -969,14 +969,14 @@ type QueryVerifyMembershipRequest struct { Proof []byte `protobuf:"bytes,2,opt,name=proof,proto3" json:"proof,omitempty"` // the height of the commitment root at which the proof is verified. ProofHeight Height `protobuf:"bytes,3,opt,name=proof_height,json=proofHeight,proto3" json:"proof_height"` - // the commitment key path. - MerklePath types1.MerklePath `protobuf:"bytes,4,opt,name=merkle_path,json=merklePath,proto3" json:"merkle_path"` // the value which is proven. Value []byte `protobuf:"bytes,5,opt,name=value,proto3" json:"value,omitempty"` // optional time delay TimeDelay uint64 `protobuf:"varint,6,opt,name=time_delay,json=timeDelay,proto3" json:"time_delay,omitempty"` // optional block delay BlockDelay uint64 `protobuf:"varint,7,opt,name=block_delay,json=blockDelay,proto3" json:"block_delay,omitempty"` + // the commitment key path. + MerklePath v2.MerklePath `protobuf:"bytes,8,opt,name=merkle_path,json=merklePath,proto3" json:"merkle_path"` } func (m *QueryVerifyMembershipRequest) Reset() { *m = QueryVerifyMembershipRequest{} } @@ -1033,13 +1033,6 @@ func (m *QueryVerifyMembershipRequest) GetProofHeight() Height { return Height{} } -func (m *QueryVerifyMembershipRequest) GetMerklePath() types1.MerklePath { - if m != nil { - return m.MerklePath - } - return types1.MerklePath{} -} - func (m *QueryVerifyMembershipRequest) GetValue() []byte { if m != nil { return m.Value @@ -1061,6 +1054,13 @@ func (m *QueryVerifyMembershipRequest) GetBlockDelay() uint64 { return 0 } +func (m *QueryVerifyMembershipRequest) GetMerklePath() v2.MerklePath { + if m != nil { + return m.MerklePath + } + return v2.MerklePath{} +} + // QueryVerifyMembershipResponse is the response type for the Query/VerifyMembership RPC method type QueryVerifyMembershipResponse struct { // boolean indicating success or failure of proof verification. @@ -1133,85 +1133,86 @@ func init() { func init() { proto.RegisterFile("ibc/core/client/v1/query.proto", fileDescriptor_dc42cdfd1d52d76e) } var fileDescriptor_dc42cdfd1d52d76e = []byte{ - // 1242 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0xcd, 0x4f, 0x1b, 0x47, - 0x1b, 0x67, 0x08, 0x10, 0x78, 0xec, 0x40, 0x34, 0x01, 0x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x42, 0xc4, 0x53, 0xfd, 0x0d, 0xc1, 0x35, 0x49, 0x12, 0xd1, 0x15, 0x07, - 0x2e, 0x45, 0xbb, 0x42, 0x33, 0x68, 0xf1, 0xc2, 0x6a, 0x2a, 0x7f, 0x43, 0x56, 0xc7, 0x7e, 0x99, - 0x38, 0x9e, 0x75, 0x68, 0x91, 0x72, 0x24, 0xd4, 0x5e, 0x36, 0x28, 0xeb, 0x87, 0x17, 0x0b, 0xb3, - 0x52, 0x35, 0x2d, 0xa4, 0x23, 0xbd, 0xa4, 0xf8, 0x83, 0x58, 0x55, 0xc3, 0xac, 0xaa, 0x95, 0xbe, - 0x55, 0x71, 0xb0, 0xb1, 0xb2, 0x9e, 0x22, 0x50, 0x78, 0x59, 0x81, 0xca, 0xa1, 0x3e, 0x4d, 0xbc, - 0x27, 0x78, 0x05, 0xa6, 0x1a, 0xa4, 0x69, 0x51, 0xcb, 0x75, 0x8a, 0x8e, 0x6f, 0x97, 0x48, 0x83, - 0x21, 0x19, 0x29, 0x4c, 0x86, 0xe2, 0xfb, 0x4c, 0x1a, 0x33, 0x8c, 0xcc, 0x39, 0x62, 0xc8, 0x07, - 0x89, 0x97, 0xe1, 0x52, 0x2d, 0xa8, 0xcf, 0x0b, 0xcd, 0x46, 0x16, 0xd1, 0xea, 0x78, 0x21, 0xcd, - 0x85, 0x62, 0xda, 0xcf, 0x10, 0xcc, 0x49, 0x21, 0x8b, 0x59, 0xbc, 0x03, 0x53, 0x66, 0xa8, 0x49, - 0xb0, 0xa4, 0x93, 0x66, 0x2c, 0xcc, 0xeb, 0xdc, 0xd3, 0x13, 0x39, 0x72, 0x9a, 0xa8, 0xdb, 0x77, - 0x24, 0x23, 0xff, 0x37, 0x8b, 0xfc, 0x33, 0x82, 0x79, 0x39, 0x08, 0xd1, 0xbf, 0x2f, 0xe1, 0x72, - 0x47, 0xff, 0xc2, 0x75, 0x5e, 0x97, 0x95, 0x1b, 0x0f, 0xf3, 0x99, 0xe5, 0x55, 0x63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0x9f, 0x06, 0x97, 0xc5, 0xe5, 0x4e, 0x2a, 0xc2, 0xbd, 0x0f, 0x7f, 0x0f, 0xba, 0x57, 0x72, - 0x03, 0x78, 0x84, 0x80, 0x1f, 0xff, 0xfd, 0x74, 0x0d, 0x31, 0xd4, 0x6b, 0xb7, 0xd0, 0x9a, 0xfa, - 0x7f, 0x19, 0xf0, 0x26, 0xf3, 0x2e, 0xda, 0x2d, 0xf7, 0xbd, 0xc2, 0xe9, 0x59, 0x16, 0x3d, 0x3f, - 0xcb, 0xa2, 0x3f, 0xcf, 0xb2, 0xe8, 0xeb, 0xf3, 0xec, 0xd0, 0xf3, 0xf3, 0xec, 0xd0, 0xef, 0xe7, - 0xd9, 0xa1, 0x2f, 0x76, 0x2b, 0x96, 0x57, 0xf5, 0x4b, 0x01, 0xc5, 0xeb, 0xe2, 0x1f, 0x19, 0xab, - 0x64, 0x6e, 0x54, 0x5c, 0xbd, 0xb9, 0xab, 0xdb, 0x6e, 0xd9, 0xaf, 0x11, 0xca, 0xe3, 0x6f, 0xe6, - 0x37, 0x44, 0x0a, 0xef, 0xa8, 0x4e, 0x68, 0x69, 0x8c, 0xbd, 0x79, 0xb6, 0xfe, 0x09, 0x00, 0x00, - 0xff, 0xff, 0x78, 0xef, 0x8a, 0x42, 0x29, 0x12, 0x00, 0x00, + // 1249 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0xcb, 0x6f, 0x1b, 0x45, + 0x18, 0xcf, 0xa4, 0x49, 0x9a, 0x7c, 0x76, 0x93, 0x68, 0x9a, 0xa4, 0xee, 0x26, 0x75, 0x92, 0x0d, + 0x90, 0x34, 0x24, 0xbb, 0x89, 0x43, 0x93, 0x50, 0x09, 0x09, 0x52, 0x54, 0x1a, 0xa4, 0x96, 0x60, + 0xc4, 0x43, 0x48, 0xc8, 0x5a, 0xaf, 0x27, 0xf6, 0xaa, 0xde, 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42, 0xc0, 0x8f, 0xfe, 0x79, 0xb2, 0x8a, + 0x18, 0xea, 0xd5, 0x9b, 0x68, 0x55, 0x7d, 0x55, 0x06, 0xbc, 0xc1, 0xbc, 0x0b, 0x76, 0xd3, 0x7d, + 0x2f, 0x7f, 0x7a, 0x96, 0x45, 0x4f, 0xcf, 0xb2, 0xe8, 0xaf, 0xb3, 0x2c, 0xfa, 0xea, 0x3c, 0x3b, + 0xf0, 0xf4, 0x3c, 0x3b, 0xf0, 0xc7, 0x79, 0x76, 0xe0, 0xf3, 0xdd, 0xb2, 0xe5, 0x55, 0xfc, 0x62, + 0x40, 0xc9, 0xba, 0xf8, 0x5f, 0xc6, 0x2a, 0x9a, 0xeb, 0x65, 0x57, 0x6f, 0xec, 0xea, 0xb6, 0x5b, + 0xf2, 0xab, 0x84, 0xf2, 0xf8, 0x1b, 0xb9, 0x75, 0x91, 0xc2, 0x3b, 0xaa, 0x11, 0x5a, 0x1c, 0x61, + 0x2f, 0x9f, 0xad, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x99, 0xfd, 0xd9, 0x60, 0x2f, 0x12, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -2346,6 +2347,16 @@ func (m *QueryVerifyMembershipRequest) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + { + size, err := m.MerklePath.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 if m.BlockDelay != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.BlockDelay)) i-- @@ -2363,16 +2374,6 @@ func (m *QueryVerifyMembershipRequest) MarshalToSizedBuffer(dAtA []byte) (int, e i-- dAtA[i] = 0x2a } - { - size, err := m.MerklePath.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 { size, err := m.ProofHeight.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -2729,8 +2730,6 @@ func (m *QueryVerifyMembershipRequest) Size() (n int) { } l = m.ProofHeight.Size() n += 1 + l + sovQuery(uint64(l)) - l = m.MerklePath.Size() - n += 1 + l + sovQuery(uint64(l)) l = len(m.Value) if l > 0 { n += 1 + l + sovQuery(uint64(l)) @@ -2741,6 +2740,8 @@ func (m *QueryVerifyMembershipRequest) Size() (n int) { if m.BlockDelay != 0 { n += 1 + sovQuery(uint64(m.BlockDelay)) } + l = m.MerklePath.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -4672,39 +4673,6 @@ func (m *QueryVerifyMembershipRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MerklePath", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MerklePath.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) @@ -4777,6 +4745,39 @@ func (m *QueryVerifyMembershipRequest) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MerklePath", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MerklePath.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index c1cf804f91e..31968c304c4 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -34,7 +34,7 @@ func (k *Keeper) VerifyClientState( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(connection.Counterparty.ClientId)) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStateKey(connection.Counterparty.ClientId)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -76,7 +76,7 @@ func (k *Keeper) VerifyClientConsensusState( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStatePath(connection.Counterparty.ClientId, consensusHeight)) + merklePath := commitmenttypes.NewMerklePath(host.FullConsensusStateKey(connection.Counterparty.ClientId, consensusHeight)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -118,7 +118,7 @@ func (k *Keeper) VerifyConnectionState( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(connectionID)) + merklePath := commitmenttypes.NewMerklePath(host.ConnectionKey(connectionID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -161,7 +161,7 @@ func (k *Keeper) VerifyChannelState( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -209,7 +209,7 @@ func (k *Keeper) VerifyPacketCommitment( timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) - merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence)) + merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentKey(portID, channelID, sequence)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -250,7 +250,7 @@ func (k *Keeper) VerifyPacketAcknowledgement( timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) - merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence)) + merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementKey(portID, channelID, sequence)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -297,7 +297,7 @@ func (k *Keeper) VerifyPacketReceiptAbsence( timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) - merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence)) + merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptKey(portID, channelID, sequence)) merklePath, err = commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -337,7 +337,7 @@ func (k *Keeper) VerifyNextSequenceRecv( timeDelay := connection.DelayPeriod blockDelay := k.getBlockDelay(ctx, connection) - merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID)) + merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -374,7 +374,7 @@ func (k *Keeper) VerifyChannelUpgradeError( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorPath(portID, channelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeErrorKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err @@ -416,7 +416,7 @@ func (k *Keeper) VerifyChannelUpgrade( return errorsmod.Wrap(clienttypes.ErrRouteNotFound, clientID) } - merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradePath(portID, channelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelUpgradeKey(portID, channelID)) merklePath, err := commitmenttypes.ApplyPrefix(connection.Counterparty.Prefix, merklePath) if err != nil { return err diff --git a/modules/core/23-commitment/types/commitment.pb.go b/modules/core/23-commitment/types/commitment.pb.go index b517747e01e..bf95874a8ac 100644 --- a/modules/core/23-commitment/types/commitment.pb.go +++ b/modules/core/23-commitment/types/commitment.pb.go @@ -114,7 +114,7 @@ func (m *MerklePrefix) GetKeyPrefix() []byte { // arbitrary structured object (defined by a commitment type). // MerklePath is represented from root-to-leaf type MerklePath struct { - KeyPath [][]byte `protobuf:"bytes,1,rep,name=key_path,json=keyPath,proto3" json:"key_path,omitempty"` + KeyPath []string `protobuf:"bytes,1,rep,name=key_path,json=keyPath,proto3" json:"key_path,omitempty"` } func (m *MerklePath) Reset() { *m = MerklePath{} } @@ -150,7 +150,7 @@ func (m *MerklePath) XXX_DiscardUnknown() { var xxx_messageInfo_MerklePath proto.InternalMessageInfo -func (m *MerklePath) GetKeyPath() [][]byte { +func (m *MerklePath) GetKeyPath() []string { if m != nil { return m.KeyPath } @@ -218,27 +218,27 @@ func init() { } var fileDescriptor_7921d88972a41469 = []byte{ - // 310 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x31, 0x4e, 0xc3, 0x30, - 0x14, 0x86, 0x13, 0x51, 0x15, 0x70, 0x3b, 0x59, 0x08, 0x41, 0x05, 0xa6, 0xca, 0x40, 0xbb, 0xd4, - 0x56, 0xdb, 0xa5, 0x42, 0x4c, 0x30, 0x30, 0x21, 0x55, 0x19, 0x18, 0x58, 0x50, 0x62, 0xdc, 0xc4, - 0x6a, 0xc3, 0x8b, 0x62, 0x37, 0xa2, 0x37, 0x60, 0xe4, 0x08, 0x1c, 0x87, 0xb1, 0x23, 0x23, 0x6a, - 0x2e, 0x82, 0x6c, 0x37, 0x28, 0xdb, 0x7b, 0x7a, 0x9f, 0x7f, 0xfd, 0xfe, 0xd0, 0x40, 0xc6, 0x9c, - 0x71, 0x28, 0x04, 0xe3, 0x90, 0x65, 0x52, 0x67, 0xe2, 0x4d, 0xb3, 0x72, 0xdc, 0xd8, 0x68, 0x5e, - 0x80, 0x06, 0x7c, 0x2a, 0x63, 0x4e, 0x0d, 0x48, 0x1b, 0xa7, 0x72, 0xdc, 0x3b, 0x49, 0x20, 0x01, - 0x8b, 0x30, 0x33, 0x39, 0xba, 0x77, 0xc1, 0x41, 0x65, 0xa0, 0x98, 0xe4, 0x6a, 0x32, 0x35, 0x79, - 0x79, 0x01, 0xb0, 0x50, 0xee, 0x1a, 0x5c, 0x23, 0xf4, 0x28, 0x8a, 0xe5, 0x4a, 0x84, 0x00, 0x1a, - 0x63, 0xd4, 0x4a, 0x23, 0x95, 0x9e, 0xf9, 0x7d, 0x7f, 0xd8, 0x0d, 0xed, 0x7c, 0xd3, 0xfa, 0xf8, - 0xba, 0xf2, 0x82, 0x11, 0xea, 0x3a, 0x6e, 0x5e, 0x88, 0x85, 0x7c, 0xc7, 0x97, 0x08, 0x2d, 0xc5, - 0xe6, 0x25, 0xb7, 0xdb, 0x9e, 0x3f, 0x5e, 0x8a, 0x8d, 0x3b, 0x07, 0x83, 0x3a, 0x76, 0x1e, 0xe9, - 0x14, 0x9f, 0xa3, 0x23, 0x0b, 0x47, 0xda, 0x44, 0x1f, 0x0c, 0xbb, 0xe1, 0xa1, 0x41, 0x23, 0x9d, - 0x06, 0x0f, 0xa8, 0x53, 0xe7, 0x02, 0x2c, 0xf0, 0x0c, 0xb5, 0x5d, 0x3d, 0xcb, 0x75, 0x26, 0x7d, - 0xea, 0xda, 0x53, 0xdb, 0x9e, 0x96, 0x63, 0x7a, 0xff, 0xff, 0x65, 0xfb, 0x22, 0xdc, 0xf3, 0x77, - 0x4f, 0xdf, 0x3b, 0xe2, 0x6f, 0x77, 0xc4, 0xff, 0xdd, 0x11, 0xff, 0xb3, 0x22, 0xde, 0xb6, 0x22, - 0xde, 0x4f, 0x45, 0xbc, 0xe7, 0xdb, 0x44, 0xea, 0x74, 0x1d, 0x1b, 0x59, 0xac, 0x76, 0x11, 0xf3, - 0x51, 0x02, 0xac, 0x9c, 0xb1, 0x0c, 0x5e, 0xd7, 0x2b, 0xa1, 0x9c, 0xf7, 0xc9, 0x74, 0xd4, 0x50, - 0xaf, 0x37, 0xb9, 0x50, 0x71, 0xdb, 0x7a, 0x9a, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x0c, 0xb3, - 0xc0, 0xc0, 0x9e, 0x01, 0x00, 0x00, + // 312 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4e, 0xeb, 0x30, + 0x14, 0x86, 0x13, 0xdd, 0xaa, 0x97, 0xba, 0x9d, 0x2c, 0x84, 0xa0, 0x02, 0x53, 0x65, 0xa0, 0x5d, + 0x6a, 0xab, 0xed, 0x52, 0x21, 0x26, 0x18, 0x98, 0x90, 0xaa, 0x0c, 0x0c, 0x2c, 0x28, 0x31, 0x6e, + 0x62, 0xb5, 0xe1, 0x44, 0xb1, 0x1b, 0xd1, 0x37, 0x60, 0xe4, 0x11, 0x78, 0x1c, 0xc6, 0x8e, 0x8c, + 0xa8, 0x79, 0x11, 0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0x9f, 0x3d, 0xf1, 0x3f, 0x2a, 0xe2, 0xed, + 0x2a, 0xe2, 0x7d, 0x57, 0xc4, 0x7b, 0xba, 0x49, 0xa4, 0x4e, 0x37, 0xb1, 0x91, 0xc5, 0x6a, 0x17, + 0x31, 0x1f, 0x27, 0xc0, 0xca, 0x39, 0xcb, 0xe0, 0x65, 0xb3, 0x16, 0xca, 0x79, 0x9f, 0xce, 0xc6, + 0x0d, 0xf5, 0x7a, 0x9b, 0x0b, 0x15, 0xb7, 0xad, 0xa7, 0xd9, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x55, 0x02, 0x17, 0xe1, 0x9e, 0x01, 0x00, 0x00, } func (m *MerkleRoot) Marshal() (dAtA []byte, err error) { @@ -414,8 +414,8 @@ func (m *MerklePath) Size() (n int) { var l int _ = l if len(m.KeyPath) > 0 { - for _, b := range m.KeyPath { - l = len(b) + for _, s := range m.KeyPath { + l = len(s) n += 1 + l + sovCommitment(uint64(l)) } } @@ -644,7 +644,7 @@ func (m *MerklePath) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field KeyPath", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowCommitment @@ -654,23 +654,23 @@ func (m *MerklePath) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthCommitment } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthCommitment } if postIndex > l { return io.ErrUnexpectedEOF } - m.KeyPath = append(m.KeyPath, make([]byte, postIndex-iNdEx)) - copy(m.KeyPath[len(m.KeyPath)-1], dAtA[iNdEx:postIndex]) + m.KeyPath = append(m.KeyPath, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex default: iNdEx = preIndex diff --git a/modules/core/23-commitment/types/merkle.go b/modules/core/23-commitment/types/merkle.go index 9e28936bbd9..52c6c1775e6 100644 --- a/modules/core/23-commitment/types/merkle.go +++ b/modules/core/23-commitment/types/merkle.go @@ -11,6 +11,7 @@ import ( cmtcrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -69,39 +70,33 @@ func (mp MerklePrefix) Empty() bool { var _ exported.Path = (*MerklePath)(nil) // NewMerklePath creates a new MerklePath instance -// The keys must be passed in from root-to-leaf order -func NewMerklePath(keyPath ...string) MerklePath { - var path [][]byte - for _, key := range keyPath { - path = append(path, []byte(key)) - } - - return MerklePath{ - KeyPath: path, - } -} +// The keys must be passed in from root-to-leaf order. +// NOTE: NewMerklePath returns a commitment/v2 MerklePath. +var NewMerklePath = v2.NewMerklePath // GetKey will return a byte representation of the key -func (mp MerklePath) GetKey(i uint64) ([]byte, error) { +// Deprecated: Please use commitment/v2 MerklePath instead. +func (mp MerklePath) GetKey(i uint64) (string, error) { if i >= uint64(len(mp.KeyPath)) { - return nil, fmt.Errorf("index out of range. %d (index) >= %d (len)", i, len(mp.KeyPath)) + return "", fmt.Errorf("index out of range. %d (index) >= %d (len)", i, len(mp.KeyPath)) } return mp.KeyPath[i], nil } // Empty returns true if the path is empty +// Deprecated: Please use commitment/v2 MerklePath instead. func (mp MerklePath) Empty() bool { return len(mp.KeyPath) == 0 } // ApplyPrefix constructs a new commitment path from the arguments. It prepends the prefix key // with the given path. -func ApplyPrefix(prefix exported.Prefix, path MerklePath) (MerklePath, error) { +func ApplyPrefix(prefix exported.Prefix, path v2.MerklePath) (v2.MerklePath, error) { if prefix == nil || prefix.Empty() { - return MerklePath{}, errorsmod.Wrap(ErrInvalidPrefix, "prefix can't be empty") + return v2.MerklePath{}, errorsmod.Wrap(ErrInvalidPrefix, "prefix can't be empty") } - return MerklePath{ + return v2.MerklePath{ KeyPath: append([][]byte{prefix.Bytes()}, path.KeyPath...), }, nil } @@ -114,7 +109,7 @@ func (proof MerkleProof) VerifyMembership(specs []*ics23.ProofSpec, root exporte } // VerifyMembership specific argument validation - mpath, ok := path.(MerklePath) + mpath, ok := path.(v2.MerklePath) if !ok { return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerklePath", path) } @@ -140,7 +135,7 @@ func (proof MerkleProof) VerifyNonMembership(specs []*ics23.ProofSpec, root expo } // VerifyNonMembership specific argument validation - mpath, ok := path.(MerklePath) + mpath, ok := path.(v2.MerklePath) if !ok { return errorsmod.Wrapf(ErrInvalidProof, "path %v is not of type MerkleProof", path) } @@ -196,7 +191,7 @@ func (MerkleProof) BatchVerifyNonMembership(specs []*ics23.ProofSpec, root expor // The proofs and specs are passed in from lowest subtree to the highest subtree, but the keys are passed in from highest subtree to lowest. // The index specifies what index to start chaining the membership proofs, this is useful since the lowest proof may not be a membership proof, thus we // will want to start the membership proof chaining from index 1 with value being the lowest subroot -func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs []*ics23.CommitmentProof, keys MerklePath, value []byte, index int) error { +func verifyChainedMembershipProof(root []byte, specs []*ics23.ProofSpec, proofs []*ics23.CommitmentProof, keys v2.MerklePath, value []byte, index int) error { var ( subroot []byte err error diff --git a/modules/core/23-commitment/types/merkle_test.go b/modules/core/23-commitment/types/merkle_test.go index b8aedb0e967..d0089799c67 100644 --- a/modules/core/23-commitment/types/merkle_test.go +++ b/modules/core/23-commitment/types/merkle_test.go @@ -9,6 +9,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ) func (suite *MerkleTestSuite) TestVerifyMembership() { @@ -32,22 +33,22 @@ func (suite *MerkleTestSuite) TestVerifyMembership() { cases := []struct { name string root []byte - pathArr []string + pathArr [][]byte value []byte malleate func() shouldPass bool }{ - {"valid proof", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, []byte("MYVALUE"), func() {}, true}, // valid proof - {"wrong value", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, []byte("WRONGVALUE"), func() {}, false}, // invalid proof with wrong value - {"nil value", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, []byte(nil), func() {}, false}, // invalid proof with nil value - {"wrong key", cid.Hash, []string{suite.storeKey.Name(), "NOTMYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong key - {"wrong path 1", cid.Hash, []string{suite.storeKey.Name(), "MYKEY", "MYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path - {"wrong path 2", cid.Hash, []string{suite.storeKey.Name()}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path - {"wrong path 3", cid.Hash, []string{"MYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path - {"wrong storekey", cid.Hash, []string{"otherStoreKey", "MYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong store prefix - {"wrong root", []byte("WRONGROOT"), []string{suite.storeKey.Name(), "MYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong root - {"nil root", []byte(nil), []string{suite.storeKey.Name(), "MYKEY"}, []byte("MYVALUE"), func() {}, false}, // invalid proof with nil root - {"proof is wrong length", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, []byte("MYVALUE"), func() { + {"valid proof", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte("MYVALUE"), func() {}, true}, // valid proof + {"wrong value", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte("WRONGVALUE"), func() {}, false}, // invalid proof with wrong value + {"nil value", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte(nil), func() {}, false}, // invalid proof with nil value + {"wrong key", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("NOTMYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong key + {"wrong path 1", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY"), []byte("MYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path + {"wrong path 2", cid.Hash, [][]byte{[]byte(suite.storeKey.Name())}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path + {"wrong path 3", cid.Hash, [][]byte{[]byte("MYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong path + {"wrong storekey", cid.Hash, [][]byte{[]byte("otherStoreKey"), []byte("MYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong store prefix + {"wrong root", []byte("WRONGROOT"), [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with wrong root + {"nil root", []byte(nil), [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte("MYVALUE"), func() {}, false}, // invalid proof with nil root + {"proof is wrong length", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, []byte("MYVALUE"), func() { proof = types.MerkleProof{ Proofs: proof.Proofs[1:], } @@ -97,20 +98,20 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() { cases := []struct { name string root []byte - pathArr []string + pathArr [][]byte malleate func() shouldPass bool }{ - {"valid proof", cid.Hash, []string{suite.storeKey.Name(), "MYABSENTKEY"}, func() {}, true}, // valid proof - {"wrong key", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, func() {}, false}, // invalid proof with existent key - {"wrong path 1", cid.Hash, []string{suite.storeKey.Name(), "MYKEY", "MYABSENTKEY"}, func() {}, false}, // invalid proof with wrong path - {"wrong path 2", cid.Hash, []string{suite.storeKey.Name(), "MYABSENTKEY", "MYKEY"}, func() {}, false}, // invalid proof with wrong path - {"wrong path 3", cid.Hash, []string{suite.storeKey.Name()}, func() {}, false}, // invalid proof with wrong path - {"wrong path 4", cid.Hash, []string{"MYABSENTKEY"}, func() {}, false}, // invalid proof with wrong path - {"wrong storeKey", cid.Hash, []string{"otherStoreKey", "MYABSENTKEY"}, func() {}, false}, // invalid proof with wrong store prefix - {"wrong root", []byte("WRONGROOT"), []string{suite.storeKey.Name(), "MYABSENTKEY"}, func() {}, false}, // invalid proof with wrong root - {"nil root", []byte(nil), []string{suite.storeKey.Name(), "MYABSENTKEY"}, func() {}, false}, // invalid proof with nil root - {"proof is wrong length", cid.Hash, []string{suite.storeKey.Name(), "MYKEY"}, func() { + {"valid proof", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYABSENTKEY")}, func() {}, true}, // valid proof + {"wrong key", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, func() {}, false}, // invalid proof with existent key + {"wrong path 1", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY"), []byte("MYABSENTKEY")}, func() {}, false}, // invalid proof with wrong path + {"wrong path 2", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYABSENTKEY"), []byte("MYKEY")}, func() {}, false}, // invalid proof with wrong path + {"wrong path 3", cid.Hash, [][]byte{[]byte(suite.storeKey.Name())}, func() {}, false}, // invalid proof with wrong path + {"wrong path 4", cid.Hash, [][]byte{[]byte("MYABSENTKEY")}, func() {}, false}, // invalid proof with wrong path + {"wrong storeKey", cid.Hash, [][]byte{[]byte("otherStoreKey"), []byte("MYABSENTKEY")}, func() {}, false}, // invalid proof with wrong store prefix + {"wrong root", []byte("WRONGROOT"), [][]byte{[]byte(suite.storeKey.Name()), []byte("MYABSENTKEY")}, func() {}, false}, // invalid proof with wrong root + {"nil root", []byte(nil), [][]byte{[]byte(suite.storeKey.Name()), []byte("MYABSENTKEY")}, func() {}, false}, // invalid proof with nil root + {"proof is wrong length", cid.Hash, [][]byte{[]byte(suite.storeKey.Name()), []byte("MYKEY")}, func() { proof = types.MerkleProof{ Proofs: proof.Proofs[1:], } @@ -143,9 +144,9 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() { func TestApplyPrefix(t *testing.T) { prefix := types.NewMerklePrefix([]byte("storePrefixKey")) - pathStr := "pathone/pathtwo/paththree/key" - path := types.MerklePath{ - KeyPath: [][]byte{[]byte(pathStr)}, + pathBz := []byte("pathone/pathtwo/paththree/key") + path := v2.MerklePath{ + KeyPath: [][]byte{pathBz}, } prefixedPath, err := types.ApplyPrefix(prefix, path) @@ -158,5 +159,5 @@ func TestApplyPrefix(t *testing.T) { key1, err := prefixedPath.GetKey(1) require.NoError(t, err, "get key 1 returns error") - require.Equal(t, []byte(pathStr), key1, "key 1 does not match expected value") + require.Equal(t, pathBz, key1, "key 1 does not match expected value") } diff --git a/modules/core/23-commitment/types/utils_test.go b/modules/core/23-commitment/types/utils_test.go index 22afcf60a52..cd7f9a8bf50 100644 --- a/modules/core/23-commitment/types/utils_test.go +++ b/modules/core/23-commitment/types/utils_test.go @@ -17,8 +17,8 @@ func (suite *MerkleTestSuite) TestConvertProofs() { cid := suite.store.Commit() root := types.NewMerkleRoot(cid.Hash) - existsPath := types.NewMerklePath(suite.storeKey.Name(), "MYKEY") - nonexistPath := types.NewMerklePath(suite.storeKey.Name(), "NOTMYKEY") + existsPath := types.NewMerklePath([]byte(suite.storeKey.Name()), []byte("MYKEY")) + nonexistPath := types.NewMerklePath([]byte(suite.storeKey.Name()), []byte("NOTMYKEY")) value := []byte("MYVALUE") var proofOps *crypto.ProofOps diff --git a/modules/core/23-commitment/types/v2/commitment.pb.go b/modules/core/23-commitment/types/v2/commitment.pb.go new file mode 100644 index 00000000000..fed8615f431 --- /dev/null +++ b/modules/core/23-commitment/types/v2/commitment.pb.go @@ -0,0 +1,325 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/core/commitment/v2/commitment.proto + +package v2 + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MerklePath is the path used to verify commitment proofs, which can be an +// arbitrary structured object (defined by a commitment type). +// MerklePath is represented from root-to-leaf +type MerklePath struct { + KeyPath [][]byte `protobuf:"bytes,1,rep,name=key_path,json=keyPath,proto3" json:"key_path,omitempty"` +} + +func (m *MerklePath) Reset() { *m = MerklePath{} } +func (m *MerklePath) String() string { return proto.CompactTextString(m) } +func (*MerklePath) ProtoMessage() {} +func (*MerklePath) Descriptor() ([]byte, []int) { + return fileDescriptor_8f65a9eb5e4ee5fc, []int{0} +} +func (m *MerklePath) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MerklePath) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MerklePath.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MerklePath) XXX_Merge(src proto.Message) { + xxx_messageInfo_MerklePath.Merge(m, src) +} +func (m *MerklePath) XXX_Size() int { + return m.Size() +} +func (m *MerklePath) XXX_DiscardUnknown() { + xxx_messageInfo_MerklePath.DiscardUnknown(m) +} + +var xxx_messageInfo_MerklePath proto.InternalMessageInfo + +func (m *MerklePath) GetKeyPath() [][]byte { + if m != nil { + return m.KeyPath + } + return nil +} + +func init() { + proto.RegisterType((*MerklePath)(nil), "ibc.core.commitment.v2.MerklePath") +} + +func init() { + proto.RegisterFile("ibc/core/commitment/v2/commitment.proto", fileDescriptor_8f65a9eb5e4ee5fc) +} + +var fileDescriptor_8f65a9eb5e4ee5fc = []byte{ + // 191 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00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, 0x00, 0x00, +} + +func (m *MerklePath) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MerklePath) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MerklePath) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.KeyPath) > 0 { + for iNdEx := len(m.KeyPath) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.KeyPath[iNdEx]) + copy(dAtA[i:], m.KeyPath[iNdEx]) + i = encodeVarintCommitment(dAtA, i, uint64(len(m.KeyPath[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintCommitment(dAtA []byte, offset int, v uint64) int { + offset -= sovCommitment(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MerklePath) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.KeyPath) > 0 { + for _, b := range m.KeyPath { + l = len(b) + n += 1 + l + sovCommitment(uint64(l)) + } + } + return n +} + +func sovCommitment(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCommitment(x uint64) (n int) { + return sovCommitment(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MerklePath) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MerklePath: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MerklePath: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KeyPath", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCommitment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCommitment + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCommitment + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KeyPath = append(m.KeyPath, make([]byte, postIndex-iNdEx)) + copy(m.KeyPath[len(m.KeyPath)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCommitment(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCommitment + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCommitment(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitment + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitment + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCommitment + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCommitment + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCommitment + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCommitment + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCommitment = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCommitment = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCommitment = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/core/23-commitment/types/v2/merkle.go b/modules/core/23-commitment/types/v2/merkle.go new file mode 100644 index 00000000000..84944565788 --- /dev/null +++ b/modules/core/23-commitment/types/v2/merkle.go @@ -0,0 +1,30 @@ +package v2 + +import ( + "fmt" + + "github.com/cosmos/ibc-go/v8/modules/core/exported" +) + +var _ exported.Path = (*MerklePath)(nil) + +// NewMerklePath creates a new MerklePath instance +// The keys must be passed in from root-to-leaf order +func NewMerklePath(keyPath ...[]byte) MerklePath { + return MerklePath{ + KeyPath: keyPath, + } +} + +// GetKey will return a byte representation of the key +func (mp MerklePath) GetKey(i uint64) ([]byte, error) { + if i >= uint64(len(mp.KeyPath)) { + return nil, fmt.Errorf("index out of range. %d (index) >= %d (len)", i, len(mp.KeyPath)) + } + return mp.KeyPath[i], nil +} + +// Empty returns true if the path is empty +func (mp MerklePath) Empty() bool { + return len(mp.KeyPath) == 0 +} diff --git a/modules/light-clients/06-solomachine/client_state.go b/modules/light-clients/06-solomachine/client_state.go index 43d30fc4577..1bbac3c2314 100644 --- a/modules/light-clients/06-solomachine/client_state.go +++ b/modules/light-clients/06-solomachine/client_state.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -61,9 +61,9 @@ func (cs *ClientState) VerifyMembership( return err } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { @@ -117,9 +117,9 @@ func (cs *ClientState) VerifyNonMembership( return err } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { diff --git a/modules/light-clients/06-solomachine/light_client_module_test.go b/modules/light-clients/06-solomachine/light_client_module_test.go index d80691462a8..46bce0a6ef8 100644 --- a/modules/light-clients/06-solomachine/light_client_module_test.go +++ b/modules/light-clients/06-solomachine/light_client_module_test.go @@ -8,7 +8,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" - commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -247,7 +247,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { suite.Require().NoError(err) path = sm.GetClientStatePath(counterpartyClientIdentifier) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -283,7 +283,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { suite.Require().NoError(err) path = sm.GetConsensusStatePath(counterpartyClientIdentifier, clienttypes.NewHeight(0, 1)) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -322,7 +322,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { suite.Require().NoError(err) path = sm.GetConnectionStatePath(ibctesting.FirstConnectionID) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -362,7 +362,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { suite.Require().NoError(err) path = sm.GetChannelStatePath(ibctesting.MockPort, ibctesting.FirstChannelID) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -399,7 +399,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { suite.Require().True(found) path = sm.GetNextSequenceRecvPath(ibctesting.MockPort, ibctesting.FirstChannelID) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -442,7 +442,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { commitmentBz := channeltypes.CommitPacket(suite.chainA.Codec, packet) path = sm.GetPacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -473,7 +473,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { "success: packet acknowledgement verification", func() { path = sm.GetPacketAcknowledgementPath(ibctesting.MockPort, ibctesting.FirstChannelID, 1) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -504,7 +504,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { "success: packet receipt verification", func() { path = sm.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID, 1) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -617,7 +617,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { { "failure: empty path", func() { - path = commitmenttypes.MerklePath{} + path = commitmenttypesv2.MerklePath{} }, fmt.Errorf("path must be of length 2: []: %s", host.ErrInvalidPath), }, @@ -633,8 +633,8 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { clientID = sm.ClientID clientState = sm.ClientState() - path = commitmenttypes.NewMerklePath("ibc", "solomachine") - merklePath, ok := path.(commitmenttypes.MerklePath) + path = commitmenttypesv2.NewMerklePath([]byte("ibc"), []byte("solomachine")) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -724,7 +724,7 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { "success: packet receipt absence verification", func() { path = sm.GetPacketReceiptPath(ibctesting.MockPort, ibctesting.FirstChannelID, 1) - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store suite.Require().NoError(err) @@ -858,8 +858,8 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { clientState = sm.ClientState() clientID = sm.ClientID - path = commitmenttypes.NewMerklePath("ibc", "solomachine") - merklePath, ok := path.(commitmenttypes.MerklePath) + path = commitmenttypesv2.NewMerklePath([]byte("ibc"), []byte("solomachine")) + merklePath, ok := path.(commitmenttypesv2.MerklePath) suite.Require().True(ok) key, err := merklePath.GetKey(1) // in a multistore context: index 0 is the key for the IBC store in the multistore, index 1 is the key in the IBC store 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 daa14c9e0a1..c089b80a1f5 100644 --- a/modules/light-clients/07-tendermint/client_state.go +++ b/modules/light-clients/07-tendermint/client_state.go @@ -17,6 +17,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -230,9 +231,9 @@ func (cs ClientState) VerifyMembership( return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) @@ -272,9 +273,9 @@ func (cs ClientState) VerifyNonMembership( return errorsmod.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal proof into ICS 23 commitment merkle proof") } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } consensusState, found := GetConsensusState(clientStore, cdc, height) diff --git a/modules/light-clients/07-tendermint/light_client_module_test.go b/modules/light-clients/07-tendermint/light_client_module_test.go index 77c446e5a70..90f401a5b29 100644 --- a/modules/light-clients/07-tendermint/light_client_module_test.go +++ b/modules/light-clients/07-tendermint/light_client_module_test.go @@ -284,7 +284,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { latestHeight := testingpath.EndpointB.GetClientLatestHeight() key := host.FullConsensusStateKey(testingpath.EndpointB.ClientID, latestHeight) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -300,7 +300,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { { "successful Connection verification", func() { key := host.ConnectionKey(testingpath.EndpointB.ConnectionID) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -315,7 +315,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 := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -336,7 +336,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { // make packet commitment proof 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 := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -357,7 +357,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { suite.Require().NoError(err) key := host.PacketAcknowledgementKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -381,7 +381,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { suite.Require().NoError(err) key := host.NextSequenceRecvKey(packet.GetSourcePort(), packet.GetSourceChannel()) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -394,7 +394,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { { "successful verification outside IBC store", func() { key := transfertypes.PortKey - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) suite.Require().NoError(err) @@ -494,7 +494,7 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { // create default proof, merklePath, and value which passes // may be overwritten by malleate() key := host.FullClientStateKey(testingpath.EndpointB.ClientID) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -554,7 +554,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { { "successful ConsensusState verification of non membership", func() { key := host.FullConsensusStateKey(invalidClientID, testingpath.EndpointB.GetClientLatestHeight()) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -565,7 +565,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { { "successful Connection verification of non membership", func() { key := host.ConnectionKey(invalidConnectionID) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -576,7 +576,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 := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -588,7 +588,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "successful PacketCommitment verification of non membership", func() { // make packet commitment proof key := host.PacketCommitmentKey(invalidPortID, invalidChannelID, 1) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -599,7 +599,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { { "successful Acknowledgement verification of non membership", func() { key := host.PacketAcknowledgementKey(invalidPortID, invalidChannelID, 1) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -610,7 +610,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { { "successful NextSequenceRecv verification of non membership", func() { key := host.NextSequenceRecvKey(invalidPortID, invalidChannelID) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -621,7 +621,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { { "successful verification of non membership outside IBC store", func() { key := []byte{0x08} - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) suite.Require().NoError(err) @@ -682,7 +682,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { "verify non membership fails as path exists", func() { // change the value being proved key := host.FullClientStateKey(testingpath.EndpointB.ClientID) - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -724,7 +724,7 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { // may be overwritten by malleate() key := host.FullClientStateKey("invalid-client-id") - merklePath := commitmenttypes.NewMerklePath(string(key)) + merklePath := commitmenttypes.NewMerklePath(key) path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) suite.Require().NoError(err) diff --git a/modules/light-clients/07-tendermint/upgrade.go b/modules/light-clients/07-tendermint/upgrade.go index ef62e707795..f45208c36ea 100644 --- a/modules/light-clients/07-tendermint/upgrade.go +++ b/modules/light-clients/07-tendermint/upgrade.go @@ -12,6 +12,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -124,7 +125,7 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( } // construct MerklePath for the committed client from upgradePath -func constructUpgradeClientMerklePath(upgradePath []string, lastHeight exported.Height) commitmenttypes.MerklePath { +func constructUpgradeClientMerklePath(upgradePath []string, lastHeight exported.Height) commitmenttypesv2.MerklePath { // copy all elements from upgradePath except final element clientPath := make([]string, len(upgradePath)-1) copy(clientPath, upgradePath) @@ -135,11 +136,17 @@ func constructUpgradeClientMerklePath(upgradePath []string, lastHeight exported. appendedKey := fmt.Sprintf("%s/%d/%s", lastKey, lastHeight.GetRevisionHeight(), upgradetypes.KeyUpgradedClient) clientPath = append(clientPath, appendedKey) - return commitmenttypes.NewMerklePath(clientPath...) + + var clientKey [][]byte + for _, part := range clientPath { + clientKey = append(clientKey, []byte(part)) + } + + return commitmenttypes.NewMerklePath(clientKey...) } // construct MerklePath for the committed consensus state from upgradePath -func constructUpgradeConsStateMerklePath(upgradePath []string, lastHeight exported.Height) commitmenttypes.MerklePath { +func constructUpgradeConsStateMerklePath(upgradePath []string, lastHeight exported.Height) commitmenttypesv2.MerklePath { // copy all elements from upgradePath except final element consPath := make([]string, len(upgradePath)-1) copy(consPath, upgradePath) @@ -150,5 +157,11 @@ func constructUpgradeConsStateMerklePath(upgradePath []string, lastHeight export appendedKey := fmt.Sprintf("%s/%d/%s", lastKey, lastHeight.GetRevisionHeight(), upgradetypes.KeyUpgradedConsState) consPath = append(consPath, appendedKey) - return commitmenttypes.NewMerklePath(consPath...) + + var consStateKey [][]byte + for _, part := range consPath { + consStateKey = append(consStateKey, []byte(part)) + } + + return commitmenttypes.NewMerklePath(consStateKey...) } diff --git a/modules/light-clients/08-wasm/CHANGELOG.md b/modules/light-clients/08-wasm/CHANGELOG.md index d6172125d31..f989ec6b5c6 100644 --- a/modules/light-clients/08-wasm/CHANGELOG.md +++ b/modules/light-clients/08-wasm/CHANGELOG.md @@ -34,28 +34,40 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog -## [Unreleased] +## [[Unreleased]] ### Dependencies -* [\#6193](https://github.com/cosmos/ibc-go/pull/6193) Bump Cosmos SDK to v0.50.6. -* [\#6193](https://github.com/cosmos/ibc-go/pull/6193) Bump `cosmossdk.io/store` to v1.1.0. -* [#\6097](https://github.com/cosmos/ibc-go/pull/6097) Update wasmvm to v2.0.1. -* [\#6239](https://github.com/cosmos/ibc-go/pull/6239) Bump CometBFT to v0.38.7. - ### API Breaking +* [\#6644](https://github.com/cosmos/ibc-go/pull/6644) api!: add `v2.MerklePath` for contract api `VerifyMembershipMsg` and `VerifyNonMembershipMsg` structs. Note, this requires a migration for existing client contracts to correctly handle deserialization of `MerklePath.KeyPath` which has changed from `repeated string` to `repeated bytes`. In JSON message structures this change is reflected as the `KeyPath` being a marshalled as a list of base64 encoded byte strings. + ### State Machine Breaking ### Improvements +* [\#5923](https://github.com/cosmos/ibc-go/pull/5923) imp: add 08-wasm build opts for libwasmvm linking disabled + ### Features -* [#\5821](https://github.com/cosmos/ibc-go/pull/5821) feat: add `VerifyMembershipProof` RPC query (querier approach for conditional clients). -* [#\6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`. +* [\#6055](https://github.com/cosmos/ibc-go/pull/6055) feat: add 08-wasm `ConsensusHost` implementation for custom self client/consensus state validation in 03-connection handshake. ### Bug Fixes + +## [v0.2.0+ibc-go-v8.3-wasmvm-v2.0](https://github.com/cosmos/ibc-go/releases/tag/modules%2Flight-clients%2F08-wasm%2Fv0.2.0%2Bibc-go-v8.3-wasmvm-v2.0) - 2024-05-23 + +### Dependencies + +* [\#5909](https://github.com/cosmos/ibc-go/pull/5909) Update wasmvm to v2.0.0 and cometBFT to v0.38.6. +* [\#6097](https://github.com/cosmos/ibc-go/pull/6097) Update wasmvm to v2.0.1. +* [\#6350](https://github.com/cosmos/ibc-go/pull/6350) Upgrade Cosmos SDK to v0.50.6. + +### Features + +* [\#5821](https://github.com/cosmos/ibc-go/pull/5821) feat: add `VerifyMembershipProof` RPC query (querier approach for conditional clients). +* [\#6231](https://github.com/cosmos/ibc-go/pull/6231) feat: add CLI to broadcast transaction with `MsgMigrateContract`. + ## [v0.1.0+ibc-go-v8.0-wasmvm-v1.5](https://github.com/cosmos/ibc-go/releases/tag/modules%2Flight-clients%2F08-wasm%2Fv0.1.0%2Bibc-go-v7.3-wasmvm-v1.5) - 2023-12-18 @@ -68,4 +80,4 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features -* [\#5079](https://github.com/cosmos/ibc-go/pull/5079) feat: 08-wasm light client proxy module for wasm clients. +* [\#5079](https://github.com/cosmos/ibc-go/pull/5079) feat: 08-wasm light client proxy module for wasm clients. \ No newline at end of file diff --git a/modules/light-clients/08-wasm/keeper/querier_test.go b/modules/light-clients/08-wasm/keeper/querier_test.go index 5fb1cf52173..74afd53d121 100644 --- a/modules/light-clients/08-wasm/keeper/querier_test.go +++ b/modules/light-clients/08-wasm/keeper/querier_test.go @@ -213,7 +213,7 @@ func (suite *KeeperTestSuite) TestStargateQuery() { suite.coordinator.CommitBlock(suite.chainA) proof, proofHeight := endpoint.QueryProofAtHeight(proofKey, uint64(suite.chainA.GetContext().BlockHeight())) - merklePath := commitmenttypes.NewMerklePath(string(proofKey)) + merklePath := commitmenttypes.NewMerklePath(proofKey) merklePath, err := commitmenttypes.ApplyPrefix(suite.chainA.GetPrefix(), merklePath) suite.Require().NoError(err) diff --git a/modules/light-clients/08-wasm/light_client_module.go b/modules/light-clients/08-wasm/light_client_module.go index 8e44931ef15..b2d2783f83f 100644 --- a/modules/light-clients/08-wasm/light_client_module.go +++ b/modules/light-clients/08-wasm/light_client_module.go @@ -14,7 +14,7 @@ import ( wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" ) @@ -249,9 +249,9 @@ func (l LightClientModule) VerifyMembership( ) } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } payload := types.SudoMsg{ @@ -264,6 +264,7 @@ func (l LightClientModule) VerifyMembership( Value: value, }, } + _, err := l.keeper.WasmSudo(ctx, clientID, clientStore, clientState, payload) return err } @@ -303,9 +304,9 @@ func (l LightClientModule) VerifyNonMembership( ) } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } payload := types.SudoMsg{ @@ -317,6 +318,7 @@ func (l LightClientModule) VerifyNonMembership( Path: merklePath, }, } + _, err := l.keeper.WasmSudo(ctx, clientID, clientStore, clientState, payload) return err } diff --git a/modules/light-clients/08-wasm/light_client_module_test.go b/modules/light-clients/08-wasm/light_client_module_test.go index ecac00a24d1..03d07daa791 100644 --- a/modules/light-clients/08-wasm/light_client_module_test.go +++ b/modules/light-clients/08-wasm/light_client_module_test.go @@ -412,8 +412,8 @@ func (suite *WasmTestSuite) TestVerifyMembership() { suite.Require().Nil(payload.VerifyNonMembership) suite.Require().Nil(payload.VerifyUpgradeAndUpdateState) suite.Require().Equal(proofHeight, payload.VerifyMembership.Height) - suite.Require().Equal(path, payload.VerifyMembership.Path) suite.Require().Equal(proof, payload.VerifyMembership.Proof) + suite.Require().Equal(path, payload.VerifyMembership.Path) suite.Require().Equal(value, payload.VerifyMembership.Value) bz, err := json.Marshal(types.EmptyResult{}) @@ -480,7 +480,7 @@ func (suite *WasmTestSuite) TestVerifyMembership() { suite.Require().NoError(err) clientID = endpoint.ClientID - path = commitmenttypes.NewMerklePath("/ibc/key/path") + path = commitmenttypes.NewMerklePath([]byte("/ibc/key/path")) proof = wasmtesting.MockValidProofBz proofHeight = clienttypes.NewHeight(0, 1) value = []byte("value") @@ -540,8 +540,8 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() { suite.Require().Nil(payload.VerifyMembership) suite.Require().Nil(payload.VerifyUpgradeAndUpdateState) suite.Require().Equal(proofHeight, payload.VerifyNonMembership.Height) - suite.Require().Equal(path, payload.VerifyNonMembership.Path) suite.Require().Equal(proof, payload.VerifyNonMembership.Proof) + suite.Require().Equal(path, payload.VerifyNonMembership.Path) bz, err := json.Marshal(types.EmptyResult{}) suite.Require().NoError(err) @@ -567,8 +567,8 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() { suite.Require().Nil(payload.VerifyMembership) suite.Require().Nil(payload.VerifyUpgradeAndUpdateState) suite.Require().Equal(proofHeight, payload.VerifyNonMembership.Height) - suite.Require().Equal(path, payload.VerifyNonMembership.Path) suite.Require().Equal(proof, payload.VerifyNonMembership.Proof) + suite.Require().Equal(path, payload.VerifyNonMembership.Path) bz, err := json.Marshal(types.EmptyResult{}) suite.Require().NoError(err) @@ -647,7 +647,7 @@ func (suite *WasmTestSuite) TestVerifyNonMembership() { suite.Require().NoError(err) clientID = endpoint.ClientID - path = commitmenttypes.NewMerklePath("/ibc/key/path") + path = commitmenttypes.NewMerklePath([]byte("/ibc/key/path")) proof = wasmtesting.MockInvalidProofBz proofHeight = clienttypes.NewHeight(0, 1) diff --git a/modules/light-clients/08-wasm/types/contract_api.go b/modules/light-clients/08-wasm/types/contract_api.go index 217818d439e..1c1383682cc 100644 --- a/modules/light-clients/08-wasm/types/contract_api.go +++ b/modules/light-clients/08-wasm/types/contract_api.go @@ -2,7 +2,7 @@ package types import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ) // InstantiateMessage is the message that is sent to the contract's instantiate entry point. @@ -66,21 +66,21 @@ type UpdateStateOnMisbehaviourMsg struct { // VerifyMembershipMsg is a sudoMsg sent to the contract to verify a membership proof. type VerifyMembershipMsg struct { - Height clienttypes.Height `json:"height"` - DelayTimePeriod uint64 `json:"delay_time_period"` - DelayBlockPeriod uint64 `json:"delay_block_period"` - Proof []byte `json:"proof"` - Path commitmenttypes.MerklePath `json:"path"` - Value []byte `json:"value"` + Height clienttypes.Height `json:"height"` + DelayTimePeriod uint64 `json:"delay_time_period"` + DelayBlockPeriod uint64 `json:"delay_block_period"` + Proof []byte `json:"proof"` + Path commitmenttypesv2.MerklePath `json:"path"` + Value []byte `json:"value"` } // VerifyNonMembershipMsg is a sudoMsg sent to the contract to verify a non-membership proof. type VerifyNonMembershipMsg struct { - Height clienttypes.Height `json:"height"` - DelayTimePeriod uint64 `json:"delay_time_period"` - DelayBlockPeriod uint64 `json:"delay_block_period"` - Proof []byte `json:"proof"` - Path commitmenttypes.MerklePath `json:"path"` + Height clienttypes.Height `json:"height"` + DelayTimePeriod uint64 `json:"delay_time_period"` + DelayBlockPeriod uint64 `json:"delay_block_period"` + Proof []byte `json:"proof"` + Path commitmenttypesv2.MerklePath `json:"path"` } // VerifyUpgradeAndUpdateStateMsg is a sudoMsg sent to the contract to verify an upgrade and update its state. diff --git a/modules/light-clients/09-localhost/client_state.go b/modules/light-clients/09-localhost/client_state.go index 114a6837cc4..b5e7cef2d79 100644 --- a/modules/light-clients/09-localhost/client_state.go +++ b/modules/light-clients/09-localhost/client_state.go @@ -11,6 +11,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors" "github.com/cosmos/ibc-go/v8/modules/core/exported" @@ -79,9 +80,9 @@ func (ClientState) VerifyMembership( return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { @@ -89,7 +90,7 @@ func (ClientState) VerifyMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - bz := store.Get([]byte(merklePath.KeyPath[1])) + bz := store.Get(merklePath.KeyPath[1]) if bz == nil { return errorsmod.Wrapf(clienttypes.ErrFailedMembershipVerification, "value not found for path %s", path) } @@ -119,9 +120,9 @@ func (ClientState) VerifyNonMembership( return errorsmod.Wrapf(commitmenttypes.ErrInvalidProof, "expected %s, got %s", string(SentinelProof), string(proof)) } - merklePath, ok := path.(commitmenttypes.MerklePath) + merklePath, ok := path.(commitmenttypesv2.MerklePath) if !ok { - return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path) + return errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", commitmenttypesv2.MerklePath{}, path) } if len(merklePath.GetKeyPath()) != 2 { @@ -129,7 +130,7 @@ func (ClientState) VerifyNonMembership( } // The commitment prefix (eg: "ibc") is omitted when operating on the core IBC store - if store.Has([]byte(merklePath.KeyPath[1])) { + if store.Has(merklePath.KeyPath[1]) { return errorsmod.Wrapf(clienttypes.ErrFailedNonMembershipVerification, "value found for path %s", path) } diff --git a/modules/light-clients/09-localhost/light_client_module_test.go b/modules/light-clients/09-localhost/light_client_module_test.go index 8ea737a1cd9..e0cf02291d3 100644 --- a/modules/light-clients/09-localhost/light_client_module_test.go +++ b/modules/light-clients/09-localhost/light_client_module_test.go @@ -36,7 +36,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { func() { clientState := suite.chain.GetClientState(exported.LocalhostClientID) - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath(exported.LocalhostClientID)) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStateKey(exported.LocalhostClientID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -57,7 +57,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { suite.chain.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chain.GetContext(), exported.LocalhostConnectionID, connectionEnd) - merklePath := commitmenttypes.NewMerklePath(host.ConnectionPath(exported.LocalhostConnectionID)) + merklePath := commitmenttypes.NewMerklePath(host.ConnectionKey(exported.LocalhostConnectionID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -79,7 +79,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) - merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelKey(mock.PortID, ibctesting.FirstChannelID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -94,7 +94,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { nextSeqRecv := uint64(100) suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetNextSequenceRecv(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, nextSeqRecv) - merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath := commitmenttypes.NewMerklePath(host.NextSequenceRecvKey(mock.PortID, ibctesting.FirstChannelID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -120,7 +120,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { commitmentBz := channeltypes.CommitPacket(suite.chain.Codec, packet) suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, commitmentBz) - merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())) + merklePath := commitmenttypes.NewMerklePath(host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -134,7 +134,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { func() { suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1, ibctesting.MockAcknowledgement) - merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementKey(mock.PortID, ibctesting.FirstChannelID, 1)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -153,14 +153,14 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { { "key path has too many elements", func() { - path = commitmenttypes.NewMerklePath("ibc", "test", "key") + path = commitmenttypes.NewMerklePath([]byte("ibc"), []byte("test"), []byte("key")) }, false, }, { "no value found at provided key path", func() { - merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(mock.PortID, ibctesting.FirstChannelID, 100)) + merklePath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementKey(mock.PortID, ibctesting.FirstChannelID, 100)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -182,7 +182,7 @@ func (suite *LocalhostTestSuite) TestVerifyMembership() { suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetChannel(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, channel) - merklePath := commitmenttypes.NewMerklePath(host.ChannelPath(mock.PortID, ibctesting.FirstChannelID)) + merklePath := commitmenttypes.NewMerklePath(host.ChannelKey(mock.PortID, ibctesting.FirstChannelID)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -237,7 +237,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { { "success: packet receipt absence verification", func() { - merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptKey(mock.PortID, ibctesting.FirstChannelID, 1)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -250,7 +250,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { func() { suite.chain.GetSimApp().GetIBCKeeper().ChannelKeeper.SetPacketReceipt(suite.chain.GetContext(), mock.PortID, ibctesting.FirstChannelID, 1) - merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(mock.PortID, ibctesting.FirstChannelID, 1)) + merklePath := commitmenttypes.NewMerklePath(host.PacketReceiptKey(mock.PortID, ibctesting.FirstChannelID, 1)) merklePath, err := commitmenttypes.ApplyPrefix(suite.chain.GetPrefix(), merklePath) suite.Require().NoError(err) @@ -268,7 +268,7 @@ func (suite *LocalhostTestSuite) TestVerifyNonMembership() { { "key path has too many elements", func() { - path = commitmenttypes.NewMerklePath("ibc", "test", "key") + path = commitmenttypes.NewMerklePath([]byte("ibc"), []byte("test"), []byte("key")) }, false, }, diff --git a/proto/ibc/core/client/v1/query.proto b/proto/ibc/core/client/v1/query.proto index 905a9188b16..804618dc1df 100644 --- a/proto/ibc/core/client/v1/query.proto +++ b/proto/ibc/core/client/v1/query.proto @@ -7,7 +7,7 @@ option go_package = "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"; import "cosmos/base/query/v1beta1/pagination.proto"; import "cosmos/query/v1/query.proto"; import "ibc/core/client/v1/client.proto"; -import "ibc/core/commitment/v1/commitment.proto"; +import "ibc/core/commitment/v2/commitment.proto"; import "google/protobuf/any.proto"; import "google/api/annotations.proto"; import "gogoproto/gogo.proto"; @@ -225,14 +225,16 @@ message QueryVerifyMembershipRequest { bytes proof = 2; // the height of the commitment root at which the proof is verified. ibc.core.client.v1.Height proof_height = 3 [(gogoproto.nullable) = false]; - // the commitment key path. - ibc.core.commitment.v1.MerklePath merkle_path = 4 [(gogoproto.nullable) = false]; + // reserved: deprecated field. + reserved 4; // the value which is proven. bytes value = 5; // optional time delay uint64 time_delay = 6; // optional block delay uint64 block_delay = 7; + // the commitment key path. + ibc.core.commitment.v2.MerklePath merkle_path = 8 [(gogoproto.nullable) = false]; } // QueryVerifyMembershipResponse is the response type for the Query/VerifyMembership RPC method diff --git a/proto/ibc/core/commitment/v1/commitment.proto b/proto/ibc/core/commitment/v1/commitment.proto index 3cdaadffd04..8fec9ec45e7 100644 --- a/proto/ibc/core/commitment/v1/commitment.proto +++ b/proto/ibc/core/commitment/v1/commitment.proto @@ -25,8 +25,9 @@ message MerklePrefix { // MerklePath is the path used to verify commitment proofs, which can be an // arbitrary structured object (defined by a commitment type). // MerklePath is represented from root-to-leaf +// Deprecated: Please use commitment/v2 MerklePath instead which supports non UTF-8 key paths. message MerklePath { - repeated bytes key_path = 1; + repeated string key_path = 1; } // MerkleProof is a wrapper type over a chain of CommitmentProofs. diff --git a/proto/ibc/core/commitment/v2/commitment.proto b/proto/ibc/core/commitment/v2/commitment.proto new file mode 100644 index 00000000000..d86c69538a6 --- /dev/null +++ b/proto/ibc/core/commitment/v2/commitment.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package ibc.core.commitment.v2; + +option go_package = "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2"; + +// MerklePath is the path used to verify commitment proofs, which can be an +// arbitrary structured object (defined by a commitment type). +// MerklePath is represented from root-to-leaf +message MerklePath { + repeated bytes key_path = 1; +} \ No newline at end of file diff --git a/testing/solomachine.go b/testing/solomachine.go index 9d431313457..47cf78a2e21 100644 --- a/testing/solomachine.go +++ b/testing/solomachine.go @@ -20,6 +20,7 @@ import ( connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" "github.com/cosmos/ibc-go/v8/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine" @@ -200,7 +201,7 @@ func (solo *Solomachine) CreateHeader(newDiversifier string) *solomachine.Header // CreateMisbehaviour constructs testing misbehaviour for the solo machine client // by signing over two different data bytes at the same sequence. func (solo *Solomachine) CreateMisbehaviour() *solomachine.Misbehaviour { - merklePath := commitmenttypes.NewMerklePath(host.FullClientStatePath("counterparty")) + merklePath := commitmenttypes.NewMerklePath(host.FullClientStateKey("counterparty")) path, err := solo.cdc.Marshal(&merklePath) require.NoError(solo.t, err) @@ -229,7 +230,7 @@ func (solo *Solomachine) CreateMisbehaviour() *solomachine.Misbehaviour { // misbehaviour signaturess can have different timestamps solo.Time++ - merklePath = commitmenttypes.NewMerklePath(host.FullConsensusStatePath("counterparty", clienttypes.NewHeight(0, 1))) + merklePath = commitmenttypes.NewMerklePath(host.FullConsensusStateKey("counterparty", clienttypes.NewHeight(0, 1))) path, err = solo.cdc.Marshal(&merklePath) require.NoError(solo.t, err) @@ -657,24 +658,24 @@ func (solo *Solomachine) GenerateReceiptAbsenceProof(packet channeltypes.Packet) } // GetClientStatePath returns the commitment path for the client state. -func (solo *Solomachine) GetClientStatePath(counterpartyClientIdentifier string) commitmenttypes.MerklePath { - path, err := commitmenttypes.ApplyPrefix(prefix, commitmenttypes.NewMerklePath(host.FullClientStatePath(counterpartyClientIdentifier))) +func (solo *Solomachine) GetClientStatePath(counterpartyClientIdentifier string) commitmenttypesv2.MerklePath { + path, err := commitmenttypes.ApplyPrefix(prefix, commitmenttypes.NewMerklePath(host.FullClientStateKey(counterpartyClientIdentifier))) require.NoError(solo.t, err) return path } // GetConsensusStatePath returns the commitment path for the consensus state. -func (solo *Solomachine) GetConsensusStatePath(counterpartyClientIdentifier string, consensusHeight exported.Height) commitmenttypes.MerklePath { - path, err := commitmenttypes.ApplyPrefix(prefix, commitmenttypes.NewMerklePath(host.FullConsensusStatePath(counterpartyClientIdentifier, consensusHeight))) +func (solo *Solomachine) GetConsensusStatePath(counterpartyClientIdentifier string, consensusHeight exported.Height) commitmenttypesv2.MerklePath { + path, err := commitmenttypes.ApplyPrefix(prefix, commitmenttypes.NewMerklePath(host.FullConsensusStateKey(counterpartyClientIdentifier, consensusHeight))) require.NoError(solo.t, err) return path } // GetConnectionStatePath returns the commitment path for the connection state. -func (solo *Solomachine) GetConnectionStatePath(connID string) commitmenttypes.MerklePath { - connectionPath := commitmenttypes.NewMerklePath(host.ConnectionPath(connID)) +func (solo *Solomachine) GetConnectionStatePath(connID string) commitmenttypesv2.MerklePath { + connectionPath := commitmenttypes.NewMerklePath(host.ConnectionKey(connID)) path, err := commitmenttypes.ApplyPrefix(prefix, connectionPath) require.NoError(solo.t, err) @@ -682,8 +683,8 @@ func (solo *Solomachine) GetConnectionStatePath(connID string) commitmenttypes.M } // GetChannelStatePath returns the commitment path for that channel state. -func (solo *Solomachine) GetChannelStatePath(portID, channelID string) commitmenttypes.MerklePath { - channelPath := commitmenttypes.NewMerklePath(host.ChannelPath(portID, channelID)) +func (solo *Solomachine) GetChannelStatePath(portID, channelID string) commitmenttypesv2.MerklePath { + channelPath := commitmenttypes.NewMerklePath(host.ChannelKey(portID, channelID)) path, err := commitmenttypes.ApplyPrefix(prefix, channelPath) require.NoError(solo.t, err) @@ -691,8 +692,8 @@ func (solo *Solomachine) GetChannelStatePath(portID, channelID string) commitmen } // GetPacketCommitmentPath returns the commitment path for a packet commitment. -func (solo *Solomachine) GetPacketCommitmentPath(portID, channelID string, sequence uint64) commitmenttypes.MerklePath { - commitmentPath := commitmenttypes.NewMerklePath(host.PacketCommitmentPath(portID, channelID, sequence)) +func (solo *Solomachine) GetPacketCommitmentPath(portID, channelID string, sequence uint64) commitmenttypesv2.MerklePath { + commitmentPath := commitmenttypes.NewMerklePath(host.PacketCommitmentKey(portID, channelID, sequence)) path, err := commitmenttypes.ApplyPrefix(prefix, commitmentPath) require.NoError(solo.t, err) @@ -700,8 +701,8 @@ func (solo *Solomachine) GetPacketCommitmentPath(portID, channelID string, seque } // GetPacketAcknowledgementPath returns the commitment path for a packet acknowledgement. -func (solo *Solomachine) GetPacketAcknowledgementPath(portID, channelID string, sequence uint64) commitmenttypes.MerklePath { - ackPath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementPath(portID, channelID, sequence)) +func (solo *Solomachine) GetPacketAcknowledgementPath(portID, channelID string, sequence uint64) commitmenttypesv2.MerklePath { + ackPath := commitmenttypes.NewMerklePath(host.PacketAcknowledgementKey(portID, channelID, sequence)) path, err := commitmenttypes.ApplyPrefix(prefix, ackPath) require.NoError(solo.t, err) @@ -710,8 +711,8 @@ func (solo *Solomachine) GetPacketAcknowledgementPath(portID, channelID string, // GetPacketReceiptPath returns the commitment path for a packet receipt // and an absent receipts. -func (solo *Solomachine) GetPacketReceiptPath(portID, channelID string, sequence uint64) commitmenttypes.MerklePath { - receiptPath := commitmenttypes.NewMerklePath(host.PacketReceiptPath(portID, channelID, sequence)) +func (solo *Solomachine) GetPacketReceiptPath(portID, channelID string, sequence uint64) commitmenttypesv2.MerklePath { + receiptPath := commitmenttypes.NewMerklePath(host.PacketReceiptKey(portID, channelID, sequence)) path, err := commitmenttypes.ApplyPrefix(prefix, receiptPath) require.NoError(solo.t, err) @@ -719,8 +720,8 @@ func (solo *Solomachine) GetPacketReceiptPath(portID, channelID string, sequence } // GetNextSequenceRecvPath returns the commitment path for the next sequence recv counter. -func (solo *Solomachine) GetNextSequenceRecvPath(portID, channelID string) commitmenttypes.MerklePath { - nextSequenceRecvPath := commitmenttypes.NewMerklePath(host.NextSequenceRecvPath(portID, channelID)) +func (solo *Solomachine) GetNextSequenceRecvPath(portID, channelID string) commitmenttypesv2.MerklePath { + nextSequenceRecvPath := commitmenttypes.NewMerklePath(host.NextSequenceRecvKey(portID, channelID)) path, err := commitmenttypes.ApplyPrefix(prefix, nextSequenceRecvPath) require.NoError(solo.t, err)