Skip to content

Commit

Permalink
chore: updating VerifyMembership and VerifyNonMembership methods …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
damiannolan authored Nov 15, 2022
1 parent 1b7745f commit fb9dedd
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 213 deletions.
4 changes: 2 additions & 2 deletions modules/core/02-client/legacy/v100/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (cs *ClientState) VerifyMembership(
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path exported.Path,
value []byte,
) error {
panic("legacy solo machine is deprecated!")
Expand All @@ -242,7 +242,7 @@ func (cs *ClientState) VerifyNonMembership(
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path exported.Path,
) error {
panic("legacy solo machine is deprecated")
}
Expand Down
56 changes: 8 additions & 48 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func (k Keeper) VerifyClientState(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

bz, err := k.cdc.MarshalInterface(clientState)
if err != nil {
return err
Expand All @@ -54,7 +49,7 @@ func (k Keeper) VerifyClientState(
if err := targetClient.VerifyMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, path, bz,
proof, merklePath, bz,
); err != nil {
return sdkerrors.Wrapf(err, "failed client state verification for target client: %s", clientID)
}
Expand Down Expand Up @@ -90,11 +85,6 @@ func (k Keeper) VerifyClientConsensusState(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

bz, err := k.cdc.MarshalInterface(consensusState)
if err != nil {
return err
Expand All @@ -103,7 +93,7 @@ func (k Keeper) VerifyClientConsensusState(
if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, path, bz,
proof, merklePath, bz,
); err != nil {
return sdkerrors.Wrapf(err, "failed consensus state verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -139,11 +129,6 @@ func (k Keeper) VerifyConnectionState(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

connectionEnd, ok := counterpartyConnection.(connectiontypes.ConnectionEnd)
if !ok {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid connection type %T", counterpartyConnection)
Expand All @@ -157,7 +142,7 @@ func (k Keeper) VerifyConnectionState(
if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, path, bz,
proof, merklePath, bz,
); err != nil {
return sdkerrors.Wrapf(err, "failed connection state verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -194,11 +179,6 @@ func (k Keeper) VerifyChannelState(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

channelEnd, ok := channel.(channeltypes.Channel)
if !ok {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "invalid channel type %T", channel)
Expand All @@ -212,7 +192,7 @@ func (k Keeper) VerifyChannelState(
if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
0, 0, // skip delay period checks for non-packet processing verification
proof, path, bz,
proof, merklePath, bz,
); err != nil {
return sdkerrors.Wrapf(err, "failed channel state verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -254,15 +234,10 @@ func (k Keeper) VerifyPacketCommitment(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
timeDelay, blockDelay,
proof, path, commitmentBytes,
proof, merklePath, commitmentBytes,
); err != nil {
return sdkerrors.Wrapf(err, "failed packet commitment verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -304,15 +279,10 @@ func (k Keeper) VerifyPacketAcknowledgement(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
timeDelay, blockDelay,
proof, path, channeltypes.CommitAcknowledgement(acknowledgement),
proof, merklePath, channeltypes.CommitAcknowledgement(acknowledgement),
); err != nil {
return sdkerrors.Wrapf(err, "failed packet acknowledgement verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -354,15 +324,10 @@ func (k Keeper) VerifyPacketReceiptAbsence(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

if err := clientState.VerifyNonMembership(
ctx, clientStore, k.cdc, height,
timeDelay, blockDelay,
proof, path,
proof, merklePath,
); err != nil {
return sdkerrors.Wrapf(err, "failed packet receipt absence verification for client (%s)", clientID)
}
Expand Down Expand Up @@ -403,15 +368,10 @@ func (k Keeper) VerifyNextSequenceRecv(
return err
}

path, err := k.cdc.Marshal(&merklePath)
if err != nil {
return err
}

if err := clientState.VerifyMembership(
ctx, clientStore, k.cdc, height,
timeDelay, blockDelay,
proof, path, sdk.Uint64ToBigEndian(nextSequenceRecv),
proof, merklePath, sdk.Uint64ToBigEndian(nextSequenceRecv),
); err != nil {
return sdkerrors.Wrapf(err, "failed next sequence receive verification for client (%s)", clientID)
}
Expand Down
4 changes: 2 additions & 2 deletions modules/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type ClientState interface {
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path Path,
value []byte,
) error

Expand All @@ -88,7 +88,7 @@ type ClientState interface {
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path Path,
) error

// VerifyClientMessage must verify a ClientMessage. A ClientMessage could be a Header, Misbehaviour, or batch update.
Expand Down
16 changes: 8 additions & 8 deletions modules/light-clients/06-solomachine/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func (cs *ClientState) VerifyMembership(
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path exported.Path,
value []byte,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof)
if err != nil {
return err
}

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

signBytes := &SignBytes{
Expand Down Expand Up @@ -159,16 +159,16 @@ func (cs *ClientState) VerifyNonMembership(
delayTimePeriod uint64,
delayBlockPeriod uint64,
proof []byte,
path []byte,
path exported.Path,
) error {
publicKey, sigData, timestamp, sequence, err := produceVerificationArgs(cdc, cs, height, proof)
if err != nil {
return err
}

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

signBytes := &SignBytes{
Expand Down
Loading

0 comments on commit fb9dedd

Please sign in to comment.