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

Verify Client on Connection Handshake #7057

Merged
merged 27 commits into from
Aug 20, 2020
Merged

Verify Client on Connection Handshake #7057

merged 27 commits into from
Aug 20, 2020

Conversation

AdityaSripal
Copy link
Member

@AdityaSripal AdityaSripal commented Aug 14, 2020

Description

closes: #6524


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Aug 14, 2020

Codecov Report

Merging #7057 into master will decrease coverage by 1.15%.
The diff coverage is 52.66%.

@@            Coverage Diff             @@
##           master    #7057      +/-   ##
==========================================
- Coverage   55.60%   54.44%   -1.16%     
==========================================
  Files         457      547      +90     
  Lines       27440    37659   +10219     
==========================================
+ Hits        15257    20503    +5246     
- Misses      11083    15469    +4386     
- Partials     1100     1687     +587     

expectedUbdPeriod, tmClient.UnbondingPeriod)
}

if tmClient.UnbondingPeriod < tmClient.TrustingPeriod {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently the only check I enforce on TrustingPeriod, should I add others? @cwgoes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so; although some values (almost unbonding period and very very low) are practically unworkable, that should be paid attention to by users or relayers when creating a client

@AdityaSripal AdityaSripal marked this pull request as ready for review August 17, 2020 23:39
x/ibc/02-client/types/codec.go Outdated Show resolved Hide resolved
x/ibc/03-connection/client/cli/tx.go Outdated Show resolved Hide resolved
x/ibc/03-connection/client/cli/tx.go Outdated Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake.go Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake.go Show resolved Hide resolved
x/ibc/03-connection/keeper/verify.go Show resolved Hide resolved
x/ibc/03-connection/types/connection_test.go Outdated Show resolved Hide resolved
x/ibc/03-connection/types/msgs.go Show resolved Hide resolved
x/ibc/03-connection/types/msgs.go Show resolved Hide resolved
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very quick pass, please update spec/docs as well

x/ibc/03-connection/client/utils/utils.go Show resolved Hide resolved
x/ibc/02-client/types/codec.go Outdated Show resolved Hide resolved
x/ibc/03-connection/handler.go Outdated Show resolved Hide resolved
x/ibc/03-connection/handler.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
@AdityaSripal
Copy link
Member Author

please update spec/docs as well

Do you mean in the ics repo @colin-axner ? I believe I've updated the docs of function in code, but I've missed any or they're insufficient please point them out and ill fix them

@AdityaSripal AdityaSripal requested a review from fedekunze August 18, 2020 22:17
@colin-axner colin-axner mentioned this pull request Aug 19, 2020
4 tasks
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM, left a lot of suggestions

proto/ibc/connection/connection.proto Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/02-client/types/codec_test.go Outdated Show resolved Hide resolved
x/ibc/02-client/types/codec_test.go Outdated Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake_test.go Outdated Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake_test.go Show resolved Hide resolved
x/ibc/03-connection/keeper/handshake_test.go Show resolved Hide resolved
@colin-axner
Copy link
Contributor

Do you mean in the ics repo @colin-axner ? I believe I've updated the docs of function in code, but I've missed any or they're insufficient please point them out and ill fix them

No not ICS specs, x/ibc/spec, specifically 04-messages.md and it'd be lovely if you could add a section in 01-concepts.md on self client validation/consensus state (related to TM). We should probably begin adding sections on the Verify funcs but maybe we can add a wishlist of concept sections to an issue. I think docs/ibc/overview.md also needs to be updated on the handshake section

x/ibc/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
x/ibc/03-connection/types/msgs.go Show resolved Hide resolved
x/ibc/03-connection/types/msgs.go Show resolved Hide resolved
x/ibc/07-tendermint/types/client_state.go Outdated Show resolved Hide resolved
Comment on lines +117 to 118
// VerifyClientConsensusState returns nil since a local host client does not store consensus
// states.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually not intuitive to me and is also not documented on the spec if it should return an error or not. cc @cwgoes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this returns an error, then you can never open a connection with localhost client because the VerifyClientConsensusState will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto on adding to localhost spec dir

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not return an error; it should just pass.

_ []byte,
connectionID string,
connectionEnd connectionexported.ConnectionI,
) error {
path, err := commitmenttypes.ApplyPrefix(prefix, host.ConnectionPath(connectionID))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this requires a spec change too. @cwgoes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not, document why the implementation differs from spec

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need a prefix because we are already being passed in the clientID prefixed store into our function.

So we shouldn't be prefixing at all with ibc. We really only need that prefix in the specific clients when we are construcing the proof path. It's not needed to get from the clientStore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good info for when we add a spec dir for locahost since this differs from the ICS spec in implementation but not semantics

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, excellent use-case for a spec directory.

@AdityaSripal
Copy link
Member Author

@colin-axner updated the spec for messages. The docs/ibc/overview.md is a very cursory explanation of connections so it doesn't dive into the abstraction level where explaining the details of the handshake is necessary.

Although I do believe an in-depth explanation of the handshakes (which will explain proving self consensus states and clients for the connection handshake) in IBC is sorely needed so I will add it to an IBC docs wishlist issue to be tackled in separate PR.

Added that item to this issue: #6134 (comment)

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, pending minor test fixes, which can be incorporated in a follow-up if you want

x/ibc/02-client/keeper/keeper_test.go Outdated Show resolved Hide resolved
x/ibc/02-client/keeper/keeper_test.go Outdated Show resolved Hide resolved
@@ -91,13 +91,36 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
return nil, sdkerrors.Wrap(clienttypes.ErrInvalidEvidence, "cannot submit misbehaviour to localhost client")
}

// VerifyClientConsensusState returns an error since a local host client does not store consensus
// VerifyClientState verifies that the localhost client state is stored locally
func (cs ClientState) VerifyClientState(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending test

if err != nil {
return err
}

if connectionEnd != &prevConnection {
if !reflect.DeepEqual(&prevConnection, connectionEnd) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, this line is not covered by tests

if err != nil {
return err
}

if channel != &prevChannel {
if !reflect.DeepEqual(&prevChannel, channel) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@colin-axner
Copy link
Contributor

I opened an issue to begin tracking things that should be noted in the client specs #7119 . Feel free to add to the comment anything in particular that is important to note or is non-trivial to understand

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great work! agree with @fedekunze pending test request

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK but see comments on ValidateSelfClient. I wonder if there is a way to write this function such that if we add a field to the client state that is unequal, it fails by default instead of passing by default.

expectedUbdPeriod, tmClient.UnbondingPeriod)
}

if tmClient.UnbondingPeriod < tmClient.TrustingPeriod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so; although some values (almost unbonding period and very very low) are practically unworkable, that should be paid attention to by users or relayers when creating a client

Comment on lines +117 to 118
// VerifyClientConsensusState returns nil since a local host client does not store consensus
// states.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not return an error; it should just pass.

_ []byte,
connectionID string,
connectionEnd connectionexported.ConnectionI,
) error {
path, err := commitmenttypes.ApplyPrefix(prefix, host.ConnectionPath(connectionID))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, excellent use-case for a spec directory.

@@ -197,6 +200,48 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height uint64) (exported.
return consensusState, true
}

// ValidateSelfClient validates the client parameters for a client of the running chain
// This function is only used to validate the client state the counterparty stores for this chain
func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't check:

  • Max clock drift
  • Frozen height

Maximum clock drift can vary, so I think it's alright not to check that, but we should just make sure there aren't any values which will cause Tendermint to throw errors.

We should probably verify that the latter is 0 initially? Not required security-wise though.

Once we add an epoch number we'll need to check that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can add a frozen check, also epoch is implicitly checked by checking equality on chainID

@AdityaSripal AdityaSripal added the A:automerge Automatically merge PR once all prerequisites pass. label Aug 20, 2020
@mergify mergify bot merged commit 97df8b6 into master Aug 20, 2020
@mergify mergify bot deleted the aditya/verify-client branch August 20, 2020 22:05
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* verify client state

* add client state to msgs and retrieve in handler

* fix connection msgs

* fixed handshake tests

* fix tests

* fix sim tests

* revert pb edit

* add ValidateClient tests

* Apply suggestions from code review

Co-authored-by: Federico Kunze <[email protected]>

* fix tests

* fixed msgs test

* use ibctesting for client state consts

* Apply suggestions from code review

Co-authored-by: colin axnér <[email protected]>
Co-authored-by: Federico Kunze <[email protected]>

* address rest of comments

* rename to ValidateSelfClient and update spec

* lint

* Update x/ibc/02-client/keeper/keeper_test.go

* Update x/ibc/02-client/keeper/keeper_test.go

* complete rest of review

* improve cov

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: colin axnér <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Determine what in ClientState needs to be verified by counterparty
4 participants