Skip to content

Commit fb9dedd

Browse files
authored
chore: updating VerifyMembership and VerifyNonMembership methods to use Path interface (#2736)
* updating VerifyMembership and VerifyNonMembership interfaces to use exported.Path in favour of []byte * adding mock struct KeyPath to ibcmock testing pkg, adding additional tests to solomachine and tm clients
1 parent 1b7745f commit fb9dedd

File tree

8 files changed

+106
-213
lines changed

8 files changed

+106
-213
lines changed

modules/core/02-client/legacy/v100/solomachine.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (cs *ClientState) VerifyMembership(
227227
delayTimePeriod uint64,
228228
delayBlockPeriod uint64,
229229
proof []byte,
230-
path []byte,
230+
path exported.Path,
231231
value []byte,
232232
) error {
233233
panic("legacy solo machine is deprecated!")
@@ -242,7 +242,7 @@ func (cs *ClientState) VerifyNonMembership(
242242
delayTimePeriod uint64,
243243
delayBlockPeriod uint64,
244244
proof []byte,
245-
path []byte,
245+
path exported.Path,
246246
) error {
247247
panic("legacy solo machine is deprecated")
248248
}

modules/core/03-connection/keeper/verify.go

+8-48
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ func (k Keeper) VerifyClientState(
4141
return err
4242
}
4343

44-
path, err := k.cdc.Marshal(&merklePath)
45-
if err != nil {
46-
return err
47-
}
48-
4944
bz, err := k.cdc.MarshalInterface(clientState)
5045
if err != nil {
5146
return err
@@ -54,7 +49,7 @@ func (k Keeper) VerifyClientState(
5449
if err := targetClient.VerifyMembership(
5550
ctx, clientStore, k.cdc, height,
5651
0, 0, // skip delay period checks for non-packet processing verification
57-
proof, path, bz,
52+
proof, merklePath, bz,
5853
); err != nil {
5954
return sdkerrors.Wrapf(err, "failed client state verification for target client: %s", clientID)
6055
}
@@ -90,11 +85,6 @@ func (k Keeper) VerifyClientConsensusState(
9085
return err
9186
}
9287

93-
path, err := k.cdc.Marshal(&merklePath)
94-
if err != nil {
95-
return err
96-
}
97-
9888
bz, err := k.cdc.MarshalInterface(consensusState)
9989
if err != nil {
10090
return err
@@ -103,7 +93,7 @@ func (k Keeper) VerifyClientConsensusState(
10393
if err := clientState.VerifyMembership(
10494
ctx, clientStore, k.cdc, height,
10595
0, 0, // skip delay period checks for non-packet processing verification
106-
proof, path, bz,
96+
proof, merklePath, bz,
10797
); err != nil {
10898
return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", clientID)
10999
}
@@ -139,11 +129,6 @@ func (k Keeper) VerifyConnectionState(
139129
return err
140130
}
141131

142-
path, err := k.cdc.Marshal(&merklePath)
143-
if err != nil {
144-
return err
145-
}
146-
147132
connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd)
148133
if !ok {
149134
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection)
@@ -157,7 +142,7 @@ func (k Keeper) VerifyConnectionState(
157142
if err := clientState.VerifyMembership(
158143
ctx, clientStore, k.cdc, height,
159144
0, 0, // skip delay period checks for non-packet processing verification
160-
proof, path, bz,
145+
proof, merklePath, bz,
161146
); err != nil {
162147
return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", clientID)
163148
}
@@ -194,11 +179,6 @@ func (k Keeper) VerifyChannelState(
194179
return err
195180
}
196181

197-
path, err := k.cdc.Marshal(&merklePath)
198-
if err != nil {
199-
return err
200-
}
201-
202182
channelEnd, ok := channel.(channeltypes.Channel)
203183
if !ok {
204184
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid channel type %T", channel)
@@ -212,7 +192,7 @@ func (k Keeper) VerifyChannelState(
212192
if err := clientState.VerifyMembership(
213193
ctx, clientStore, k.cdc, height,
214194
0, 0, // skip delay period checks for non-packet processing verification
215-
proof, path, bz,
195+
proof, merklePath, bz,
216196
); err != nil {
217197
return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", clientID)
218198
}
@@ -254,15 +234,10 @@ func (k Keeper) VerifyPacketCommitment(
254234
return err
255235
}
256236

257-
path, err := k.cdc.Marshal(&merklePath)
258-
if err != nil {
259-
return err
260-
}
261-
262237
if err := clientState.VerifyMembership(
263238
ctx, clientStore, k.cdc, height,
264239
timeDelay, blockDelay,
265-
proof, path, commitmentBytes,
240+
proof, merklePath, commitmentBytes,
266241
); err != nil {
267242
return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", clientID)
268243
}
@@ -304,15 +279,10 @@ func (k Keeper) VerifyPacketAcknowledgement(
304279
return err
305280
}
306281

307-
path, err := k.cdc.Marshal(&merklePath)
308-
if err != nil {
309-
return err
310-
}
311-
312282
if err := clientState.VerifyMembership(
313283
ctx, clientStore, k.cdc, height,
314284
timeDelay, blockDelay,
315-
proof, path, channeltypes.CommitAcknowledgement(acknowledgement),
285+
proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement),
316286
); err != nil {
317287
return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID)
318288
}
@@ -354,15 +324,10 @@ func (k Keeper) VerifyPacketReceiptAbsence(
354324
return err
355325
}
356326

357-
path, err := k.cdc.Marshal(&merklePath)
358-
if err != nil {
359-
return err
360-
}
361-
362327
if err := clientState.VerifyNonMembership(
363328
ctx, clientStore, k.cdc, height,
364329
timeDelay, blockDelay,
365-
proof, path,
330+
proof, merklePath,
366331
); err != nil {
367332
return sdkerrors.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID)
368333
}
@@ -403,15 +368,10 @@ func (k Keeper) VerifyNextSequenceRecv(
403368
return err
404369
}
405370

406-
path, err := k.cdc.Marshal(&merklePath)
407-
if err != nil {
408-
return err
409-
}
410-
411371
if err := clientState.VerifyMembership(
412372
ctx, clientStore, k.cdc, height,
413373
timeDelay, blockDelay,
414-
proof, path, sdk.Uint64ToBigEndian(nextSequenceRecv),
374+
proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv),
415375
); err != nil {
416376
return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID)
417377
}

modules/core/exported/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type ClientState interface {
7474
delayTimePeriod uint64,
7575
delayBlockPeriod uint64,
7676
proof []byte,
77-
path []byte,
77+
path Path,
7878
value []byte,
7979
) error
8080

@@ -88,7 +88,7 @@ type ClientState interface {
8888
delayTimePeriod uint64,
8989
delayBlockPeriod uint64,
9090
proof []byte,
91-
path []byte,
91+
path Path,
9292
) error
9393

9494
// VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update.

modules/light-clients/06-solomachine/client_state.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ func (cs *ClientState) VerifyMembership(
112112
delayTimePeriod uint64,
113113
delayBlockPeriod uint64,
114114
proof []byte,
115-
path []byte,
115+
path exported.Path,
116116
value []byte,
117117
) error {
118118
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof)
119119
if err != nil {
120120
return err
121121
}
122122

123-
var merklePath commitmenttypes.MerklePath
124-
if err := cdc.Unmarshal(path, &merklePath); err != nil {
125-
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path")
123+
merklePath, ok := path.(commitmenttypes.MerklePath)
124+
if !ok {
125+
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
126126
}
127127

128128
signBytes := &SignBytes{
@@ -159,16 +159,16 @@ func (cs *ClientState) VerifyNonMembership(
159159
delayTimePeriod uint64,
160160
delayBlockPeriod uint64,
161161
proof []byte,
162-
path []byte,
162+
path exported.Path,
163163
) error {
164164
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof)
165165
if err != nil {
166166
return err
167167
}
168168

169-
var merklePath commitmenttypes.MerklePath
170-
if err := cdc.Unmarshal(path, &merklePath); err != nil {
171-
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path")
169+
merklePath, ok := path.(commitmenttypes.MerklePath)
170+
if !ok {
171+
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", commitmenttypes.MerklePath{}, path)
172172
}
173173

174174
signBytes := &SignBytes{

0 commit comments

Comments
 (0)