Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: add v2 MerklePath with bytes in favour of strings #6644

Merged
merged 21 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a0d2789
refactor: adapt merkle path to use repeated bytes in favour of strings
damiannolan Jun 18, 2024
a82bdbb
Merge branch 'main' into damian/6496-merklepath-bz
damiannolan Jun 18, 2024
9bb5066
refactor: update NewMerklePath func sig to take bytes
damiannolan Jun 19, 2024
5cbded9
nit: rm unnecessary variable
damiannolan Jun 19, 2024
f722998
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
damiannolan Jun 19, 2024
0ddbc9c
nit: rename var
damiannolan Jun 19, 2024
4435588
chore: add changelog
damiannolan Jun 20, 2024
eab33ad
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
damiannolan Jun 20, 2024
733539c
fix: introduce legacy merkle path type for encoding compatibility wit…
damiannolan Jun 20, 2024
4c66e27
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
damiannolan Jun 24, 2024
e09a2af
refactor: adapt code to handle v2 proto MerklePath
damiannolan Jun 25, 2024
dc567e9
chore: add deprecation notices for v1 merkle path
damiannolan Jun 25, 2024
9aca51c
chore: update changelog
damiannolan Jun 25, 2024
5b35718
fix: use pointer to leverage omitempty correctly in contract api
damiannolan Jun 25, 2024
47460fa
test: add tests for 08-wasm contract api encoding
damiannolan Jun 26, 2024
adc9718
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
damiannolan Jun 26, 2024
ba58f37
refactor: adapt IsValidUTF func per review suggestion and add more tests
damiannolan Jun 26, 2024
7667e2e
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
crodriguezvega Jul 2, 2024
dc34a09
refactor: use v2.MerklePath in contract api and update 08-wasm changelog
damiannolan Jul 3, 2024
6016180
Update CHANGELOG.md
damiannolan Jul 3, 2024
25733bf
Merge branch 'main' into damian/6496-merkle-path-constructor-breakage
damiannolan Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"),
Expand All @@ -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},
}
},
Expand All @@ -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},
}
},
Expand Down
20 changes: 10 additions & 10 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
62 changes: 31 additions & 31 deletions modules/core/23-commitment/types/commitment.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions modules/core/23-commitment/types/merkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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 {
func NewMerklePath(keyPath ...[]byte) MerklePath {
return MerklePath{
KeyPath: keyPath,
}
Expand All @@ -81,7 +81,7 @@ 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 []byte(mp.KeyPath[i]), nil
return mp.KeyPath[i], nil
}

// Empty returns true if the path is empty
Expand All @@ -95,7 +95,8 @@ func ApplyPrefix(prefix exported.Prefix, path MerklePath) (MerklePath, error) {
if prefix == nil || prefix.Empty() {
return MerklePath{}, errorsmod.Wrap(ErrInvalidPrefix, "prefix can't be empty")
}
return NewMerklePath(append([]string{string(prefix.Bytes())}, path.KeyPath...)...), nil

return NewMerklePath(append([][]byte{prefix.Bytes()}, path.KeyPath...)...), nil
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
}

// VerifyMembership verifies the membership of a merkle proof against the given root, path, and value.
Expand Down
Loading
Loading