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

light-client: Verification fails for target height between two trusted heights #1246

Closed
kostko opened this issue Dec 6, 2022 · 2 comments · Fixed by #1247
Closed

light-client: Verification fails for target height between two trusted heights #1246

kostko opened this issue Dec 6, 2022 · 2 comments · Fixed by #1247
Assignees
Labels
bug Something isn't working

Comments

@kostko
Copy link
Contributor

kostko commented Dec 6, 2022

Imagine the light store contains two trusted light blocks at heights H1 and H2 (where H2 > H1). Attempting to verify a light block at height V that falls between H1 and H2 (e.g., H1 < V < H2) will incorrectly fall back to backwards verification and in case the unstable feature is not enabled, it will incorrectly fail with the target_lower_than_trusted_state error.

Given that both H1 and H2 are trusted, there is actually no reason to need backwards verification in this case as it should be enough to start at H1 and perform the usual bisection verification algorithm. It seems this is also what the Go implementation does.

The Rust implementation does not seem to have a nicely-contained implementation of bisection, but it instead relies on the light block store for tracking the "highest trusted light block" and all the various places are querying it.

My proposal for implementing this with minimum disruption is to add two methods to the LightStore trait, namely:

    /// Get the light block of greatest hight before the given height with the given status.
    fn highest_before(&self, height: Height, status: Status) -> Option<LightBlock>;

    /// Get the first light block before the given height with the trusted or verified status.
    fn highest_trusted_or_verified_before(&self, height: Height) -> Option<LightBlock>;

Where the second method is provided as a default implementation on the LightStore trait (similar to the other ones).

Then only slight modifications are needed to the stores, light client and scheduler to make this work. I have a draft implementation of this in a local branch but need to figure out how to add some longer verification tests with the current framework.

@kostko kostko added the bug Something isn't working label Dec 6, 2022
@romac
Copy link
Member

romac commented Dec 6, 2022

Good catch! Your proposal sounds good to me, so feel free to open a PR already and we can then discuss how best to test it. Thanks :)

@kostko
Copy link
Contributor Author

kostko commented Jan 4, 2023

@romac Added tests, please take a look.

In order for the failure to be evident with the unpatched code I needed to add a step in the test workflow that tests without the unstable feature as otherwise, with all features enabled, it would just enable backward verification and make the test appear to pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants