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 Light Client verification predicates interface for use from IBC #960

Merged
merged 10 commits into from
Sep 17, 2021

Conversation

thanethomson
Copy link
Contributor

@thanethomson thanethomson commented Aug 27, 2021

Closes #956

The main aim of this PR is to remove references to the LightBlock type from the verification predicates, as the LightBlock type isn't used in informalsystems/hermes#1252

Tomorrow I'll try working on refactoring that PR to make use of this code to see if it will work.

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Added entry in .changelog/

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2021

Codecov Report

Merging #960 (d70a2c8) into master (bbad6fa) will increase coverage by 0.0%.
The diff coverage is 79.2%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #960    +/-   ##
=======================================
  Coverage    72.0%   72.1%            
=======================================
  Files         203     203            
  Lines       16522   16632   +110     
=======================================
+ Hits        11912   12005    +93     
- Misses       4610    4627    +17     
Impacted Files Coverage Δ
light-client-js/src/lib.rs 6.6% <ø> (ø)
light-client/src/builder/light_client.rs 0.0% <0.0%> (ø)
tendermint/src/block/signed_header.rs 91.6% <ø> (ø)
tendermint/src/error.rs 0.0% <0.0%> (ø)
light-client/src/types.rs 34.9% <42.8%> (+4.8%) ⬆️
light-client/src/operations/commit_validator.rs 98.0% <66.6%> (-2.0%) ⬇️
light-client/src/components/verifier.rs 87.9% <86.9%> (-12.1%) ⬇️
light-client/src/light_client.rs 83.6% <92.3%> (+0.3%) ⬆️
light-client/src/operations/hasher.rs 100.0% <100.0%> (ø)
light-client/src/operations/voting_power.rs 97.9% <100.0%> (-0.1%) ⬇️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbad6fa...d70a2c8. Read the comment docs.

This commit refactors the light client verifier to require the minimum
possible amount of detail in its parameters to perform verification.
(The LightBlock structure provides far more data than is actually
necessary)

This refactor makes it much easier to reuse the verification code from
ibc-rs.

Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
thanethomson added a commit to informalsystems/hermes that referenced this pull request Sep 9, 2021
This commit makes use of the latest code from
informalsystems/tendermint-rs#960 in order to
reuse the light client's verification predicates instead of
reimplementing them in the `ibc` crate.

Signed-off-by: Thane Thomson <[email protected]>
@thanethomson
Copy link
Contributor Author

The rustdoc error seems to only pop up with Rust nightly 1.57.0, whereas it compiles just fine with 1.56.0.

It's a problem in prost-derive's documentation:

error[E0034]: multiple applicable items in scope
Error:    --> /home/runner/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/prost-derive-0.7.0/src/lib.rs:109:14
    |
109 |             .intersperse(quote!(|));
    |              ^^^^^^^^^^^ multiple `intersperse` found
    |
    = note: candidate #1 is defined in an impl of the trait `Iterator` for the type `Map<I, F>`
    = note: candidate #2 is defined in an impl of the trait `Itertools` for the type `T`
help: disambiguate the associated function for candidate #1
    |
105 ~         let tags = Iterator::intersperse(field
106 +             .tags()
107 +             .into_iter()
108 +             .map(|tag| quote!(#tag)), {
109 +         let mut _s = $crate::__private::TokenStream::new();
110 +         $crate::quote_each_token!(_s $($tt)*);
  ...
help: disambiguate the associated function for candidate #2
    |
105 ~         let tags = Itertools::intersperse(field
106 +             .tags()
107 +             .into_iter()
108 +             .map(|tag| quote!(#tag)), {
109 +         let mut _s = $crate::__private::TokenStream::new();
110 +         $crate::quote_each_token!(_s $($tt)*);
  ...

@thanethomson thanethomson marked this pull request as ready for review September 9, 2021 23:52
&self.hasher,
));

// TODO(thane): Is this check necessary for IBC?
Copy link
Member

Choose a reason for hiding this comment

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

@josef-widder We may need your help here.

It seems the IBC handler (ICS 07) has no access to the set of next_validators for the untrusted header. For this reason, this field is an Option here. When the IBC handler calls into verify it does so with this field to None (cf. https://github.com/informalsystems/ibc-rs/pull/1321/files#diff-9a833365bf13b4ff1ce2cc757bf18ebabea582b2b97774040e0b7be03fcacbf4R93-R95). This check will effectively be disabled in the context of the IBC handler. This is probably a problem and we need to sort it out.

Copy link
Member

Choose a reason for hiding this comment

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

FYI this concern need not block the PR. (Josef will only return from holidays after Sept 27). Maybe @ancazamfir could help us sort out the problem.

Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

Structurally the refactoring makes sense to me, can't comment much on the internals of the verification.

light-client/src/types.rs Show resolved Hide resolved
light-client/src/types.rs Show resolved Hide resolved
light-client/src/types.rs Show resolved Hide resolved
light-client/src/components/verifier.rs Show resolved Hide resolved
}
}

/// The default production implementation of the [`PredicateVerifier`].
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies that there is a common understanding what a "production" environment constitutes. More qualification would aid in contextualised this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is something we've been talking/thinking about for a year now 😄 We're definitely open to suggestions on the naming front.

The original purpose, afaik, was to disambiguate mock versions from non-mock versions of the types, but I think @romac can elaborate on this better than I can?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I am not super happy with the current terminology (that I came up with). I guess we need to differentiate between:
a) the trait (previously Predicates, now Verifier)
b) the "production" implementation (previously ProdPredicates, now ProdVerifier)
c) the potential mock implementations of the trait (no use for that yet)

I agree that the Prod prefix is subpar, maybe Default or Standard would be a better fit?

Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

LGTM

🛀 😷 🌽 💐

Copy link
Member

@romac romac left a comment

Choose a reason for hiding this comment

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

Amazing job, @thanethomson! Very much an improvement over the previous API 💯

light-client/src/components/verifier.rs Show resolved Hide resolved
}
}

/// The default production implementation of the [`PredicateVerifier`].
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I am not super happy with the current terminology (that I came up with). I guess we need to differentiate between:
a) the trait (previously Predicates, now Verifier)
b) the "production" implementation (previously ProdPredicates, now ProdVerifier)
c) the potential mock implementations of the trait (no use for that yet)

I agree that the Prod prefix is subpar, maybe Default or Standard would be a better fit?

@@ -77,6 +77,28 @@ impl Status {
}
}

/// Trusted block parameters needed for light client verification.
pub struct TrustedBlockState<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

😍

@thanethomson thanethomson merged commit d89a33d into master Sep 17, 2021
@thanethomson thanethomson deleted the thane/ibc-1252 branch September 17, 2021 15:15
adizere added a commit to informalsystems/hermes that referenced this pull request Oct 19, 2021
* bla

* on going

* ongoing

* on going

* on going

* timestamp default changed from none to now

* failed ping pong - signs

* Update context.rs

* bla

* blabla

* fixed test client_update_ping_pong

* fmt + clippy

* Update context.rs

* Update context.rs

* remove comments

* Update host.rs

* Update to tendermint-rs v0.20.0

* Update changelog

* Fix tendermint-rs version in changelog

* Update predicates.rs

* Update context.rs

* tests

* tendermint stuff in

* Update Cargo.toml

* clippy + fmt

* moved predicates into ics07 header.rs

* Adapted to latest TM changes

* Fixed MockHeader test

* Fmt & clippy

* Removed irrelevant file

* Bit more cleanup

* fixed tests

* upgraded to new error  model

* fmt

* errors and timestamp changes

* Fix error notation and formatting

Signed-off-by: Thane Thomson <[email protected]>

* Upgrade to tendermint-rs master

Signed-off-by: Thane Thomson <[email protected]>

* Use tendermint-rs from branch thane/ibc-1252

Signed-off-by: Thane Thomson <[email protected]>

* Refactor ICS07 update handler to reuse light client verifier

This commit makes use of the latest code from
informalsystems/tendermint-rs#960 in order to
reuse the light client's verification predicates instead of
reimplementing them in the `ibc` crate.

Signed-off-by: Thane Thomson <[email protected]>

* Update Cargo.lock to address zeroize issue

Signed-off-by: Thane Thomson <[email protected]>

* Bump tendermint-light-client dep to v0.22.0 for ibc module

Signed-off-by: Thane Thomson <[email protected]>

* Refactor to accommodate new context API

Signed-off-by: Thane Thomson <[email protected]>

* Fix missing import

Signed-off-by: Thane Thomson <[email protected]>

* Fix imports

Signed-off-by: Thane Thomson <[email protected]>

* Fix error check in test

Signed-off-by: Thane Thomson <[email protected]>

* Output debug version of error

Signed-off-by: Thane Thomson <[email protected]>

* Remove test as per #1321 (comment)

Signed-off-by: Thane Thomson <[email protected]>

* Address comments from Adi

Signed-off-by: Thane Thomson <[email protected]>

* Cosmetic tweaks

Signed-off-by: Thane Thomson <[email protected]>

* Add revision number check

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken test

Signed-off-by: Thane Thomson <[email protected]>

* Check incoming header height against chain ID version from client state

Signed-off-by: Thane Thomson <[email protected]>

* Add revision_number consistency check when deserializing header

Signed-off-by: Thane Thomson <[email protected]>

* Clarify MismatchedRevisions error message

Signed-off-by: Thane Thomson <[email protected]>

* Add changelog entries

Signed-off-by: Thane Thomson <[email protected]>

* Commented import no longer necessary

Signed-off-by: Thane Thomson <[email protected]>

* Add in-the-middle monotonicity checks

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken dep tree relating to Prometheus

Signed-off-by: Thane Thomson <[email protected]>

* Move next/prev consensus state search functionality to ClientReader trait

Signed-off-by: Thane Thomson <[email protected]>

* Move impl of prev/next to the specific implementation and simplify signatures

* Disable `tendermint-light-client` default features, ie. RPC client, std and color-eyre

* Apply suggestions from code review

* Fix compilation

* Cleanup BTreeMap import

* Always show underlying reason in ics07_tendermint errors

* Update modules/src/ics02_client/handler/update_client.rs

* Fix compilation

Co-authored-by: cezarad <[email protected]>
Co-authored-by: Romain Ruetschi <[email protected]>
Co-authored-by: cezarad <[email protected]>
Co-authored-by: Adi Seredinschi <[email protected]>
Co-authored-by: Anca Zamfir <[email protected]>
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
…tems#1321)

* bla

* on going

* ongoing

* on going

* on going

* timestamp default changed from none to now

* failed ping pong - signs

* Update context.rs

* bla

* blabla

* fixed test client_update_ping_pong

* fmt + clippy

* Update context.rs

* Update context.rs

* remove comments

* Update host.rs

* Update to tendermint-rs v0.20.0

* Update changelog

* Fix tendermint-rs version in changelog

* Update predicates.rs

* Update context.rs

* tests

* tendermint stuff in

* Update Cargo.toml

* clippy + fmt

* moved predicates into ics07 header.rs

* Adapted to latest TM changes

* Fixed MockHeader test

* Fmt & clippy

* Removed irrelevant file

* Bit more cleanup

* fixed tests

* upgraded to new error  model

* fmt

* errors and timestamp changes

* Fix error notation and formatting

Signed-off-by: Thane Thomson <[email protected]>

* Upgrade to tendermint-rs master

Signed-off-by: Thane Thomson <[email protected]>

* Use tendermint-rs from branch thane/ibc-1252

Signed-off-by: Thane Thomson <[email protected]>

* Refactor ICS07 update handler to reuse light client verifier

This commit makes use of the latest code from
informalsystems/tendermint-rs#960 in order to
reuse the light client's verification predicates instead of
reimplementing them in the `ibc` crate.

Signed-off-by: Thane Thomson <[email protected]>

* Update Cargo.lock to address zeroize issue

Signed-off-by: Thane Thomson <[email protected]>

* Bump tendermint-light-client dep to v0.22.0 for ibc module

Signed-off-by: Thane Thomson <[email protected]>

* Refactor to accommodate new context API

Signed-off-by: Thane Thomson <[email protected]>

* Fix missing import

Signed-off-by: Thane Thomson <[email protected]>

* Fix imports

Signed-off-by: Thane Thomson <[email protected]>

* Fix error check in test

Signed-off-by: Thane Thomson <[email protected]>

* Output debug version of error

Signed-off-by: Thane Thomson <[email protected]>

* Remove test as per informalsystems#1321 (comment)

Signed-off-by: Thane Thomson <[email protected]>

* Address comments from Adi

Signed-off-by: Thane Thomson <[email protected]>

* Cosmetic tweaks

Signed-off-by: Thane Thomson <[email protected]>

* Add revision number check

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken test

Signed-off-by: Thane Thomson <[email protected]>

* Check incoming header height against chain ID version from client state

Signed-off-by: Thane Thomson <[email protected]>

* Add revision_number consistency check when deserializing header

Signed-off-by: Thane Thomson <[email protected]>

* Clarify MismatchedRevisions error message

Signed-off-by: Thane Thomson <[email protected]>

* Add changelog entries

Signed-off-by: Thane Thomson <[email protected]>

* Commented import no longer necessary

Signed-off-by: Thane Thomson <[email protected]>

* Add in-the-middle monotonicity checks

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken dep tree relating to Prometheus

Signed-off-by: Thane Thomson <[email protected]>

* Move next/prev consensus state search functionality to ClientReader trait

Signed-off-by: Thane Thomson <[email protected]>

* Move impl of prev/next to the specific implementation and simplify signatures

* Disable `tendermint-light-client` default features, ie. RPC client, std and color-eyre

* Apply suggestions from code review

* Fix compilation

* Cleanup BTreeMap import

* Always show underlying reason in ics07_tendermint errors

* Update modules/src/ics02_client/handler/update_client.rs

* Fix compilation

Co-authored-by: cezarad <[email protected]>
Co-authored-by: Romain Ruetschi <[email protected]>
Co-authored-by: cezarad <[email protected]>
Co-authored-by: Adi Seredinschi <[email protected]>
Co-authored-by: Anca Zamfir <[email protected]>
hu55a1n1 pushed a commit to cosmos/ibc-rs that referenced this pull request Sep 29, 2022
* bla

* on going

* ongoing

* on going

* on going

* timestamp default changed from none to now

* failed ping pong - signs

* Update context.rs

* bla

* blabla

* fixed test client_update_ping_pong

* fmt + clippy

* Update context.rs

* Update context.rs

* remove comments

* Update host.rs

* Update to tendermint-rs v0.20.0

* Update changelog

* Fix tendermint-rs version in changelog

* Update predicates.rs

* Update context.rs

* tests

* tendermint stuff in

* Update Cargo.toml

* clippy + fmt

* moved predicates into ics07 header.rs

* Adapted to latest TM changes

* Fixed MockHeader test

* Fmt & clippy

* Removed irrelevant file

* Bit more cleanup

* fixed tests

* upgraded to new error  model

* fmt

* errors and timestamp changes

* Fix error notation and formatting

Signed-off-by: Thane Thomson <[email protected]>

* Upgrade to tendermint-rs master

Signed-off-by: Thane Thomson <[email protected]>

* Use tendermint-rs from branch thane/ibc-1252

Signed-off-by: Thane Thomson <[email protected]>

* Refactor ICS07 update handler to reuse light client verifier

This commit makes use of the latest code from
informalsystems/tendermint-rs#960 in order to
reuse the light client's verification predicates instead of
reimplementing them in the `ibc` crate.

Signed-off-by: Thane Thomson <[email protected]>

* Update Cargo.lock to address zeroize issue

Signed-off-by: Thane Thomson <[email protected]>

* Bump tendermint-light-client dep to v0.22.0 for ibc module

Signed-off-by: Thane Thomson <[email protected]>

* Refactor to accommodate new context API

Signed-off-by: Thane Thomson <[email protected]>

* Fix missing import

Signed-off-by: Thane Thomson <[email protected]>

* Fix imports

Signed-off-by: Thane Thomson <[email protected]>

* Fix error check in test

Signed-off-by: Thane Thomson <[email protected]>

* Output debug version of error

Signed-off-by: Thane Thomson <[email protected]>

* Remove test as per informalsystems/hermes#1321 (comment)

Signed-off-by: Thane Thomson <[email protected]>

* Address comments from Adi

Signed-off-by: Thane Thomson <[email protected]>

* Cosmetic tweaks

Signed-off-by: Thane Thomson <[email protected]>

* Add revision number check

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken test

Signed-off-by: Thane Thomson <[email protected]>

* Check incoming header height against chain ID version from client state

Signed-off-by: Thane Thomson <[email protected]>

* Add revision_number consistency check when deserializing header

Signed-off-by: Thane Thomson <[email protected]>

* Clarify MismatchedRevisions error message

Signed-off-by: Thane Thomson <[email protected]>

* Add changelog entries

Signed-off-by: Thane Thomson <[email protected]>

* Commented import no longer necessary

Signed-off-by: Thane Thomson <[email protected]>

* Add in-the-middle monotonicity checks

Signed-off-by: Thane Thomson <[email protected]>

* Fix broken dep tree relating to Prometheus

Signed-off-by: Thane Thomson <[email protected]>

* Move next/prev consensus state search functionality to ClientReader trait

Signed-off-by: Thane Thomson <[email protected]>

* Move impl of prev/next to the specific implementation and simplify signatures

* Disable `tendermint-light-client` default features, ie. RPC client, std and color-eyre

* Apply suggestions from code review

* Fix compilation

* Cleanup BTreeMap import

* Always show underlying reason in ics07_tendermint errors

* Update modules/src/ics02_client/handler/update_client.rs

* Fix compilation

Co-authored-by: cezarad <[email protected]>
Co-authored-by: Romain Ruetschi <[email protected]>
Co-authored-by: cezarad <[email protected]>
Co-authored-by: Adi Seredinschi <[email protected]>
Co-authored-by: Anca Zamfir <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Light Client interface to better support IBC-rs and ICS07
5 participants