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

moved non-verification misbehaviour checks to checkForMisbehaviour #2971

Conversation

Daniyal98
Copy link
Contributor

@Daniyal98 Daniyal98 commented Dec 22, 2022

Description

closes: #2007

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

@charleenfei
Copy link
Contributor

charleenfei commented Jan 2, 2023

hey @Daniyal98, thanks for the pr, there are some failing tests in the 07 tendermint client, i think it's because the test is checking to see if VerifyClientMessage will catch the valid misbehaviour cases but since the logic was moved out of that function it is no longer erroring as expected. We should make sure that the test CheckForMisbehaviour function catches these cases :)

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started @Daniyal98!

Left some comments regarding the logic as we are now expecting to return a boolean value rather than an error case. I think some of the test cases would also need to be refactored to accommodate the restructuring of the code.

Comment on lines 54 to 55
// The correctness of Misbehaviour ClientMessage types is ensured by calling VerifyClientMessage prior to this function
// Thus, here we can return true, as ClientMessage is of type Misbehaviour
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment can be removed

Comment on lines 59 to 67
blockID1, err := tmtypes.BlockIDFromProto(&msg.Header1.SignedHeader.Commit.BlockID)
if err != nil {
return true
}

blockID2, err := tmtypes.BlockIDFromProto(&msg.Header2.SignedHeader.Commit.BlockID)
if err != nil {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the method signature only returns a bool I think it would be more appropriate to return false in both of these conditionals. In reality, BlockIDFromProto should never return errors here as its checked in ValidateBasic before this code would be reached.

The alternative option is to panic given its unreachable code, but I think I would rather opt for returning false.

Comment on lines 70 to 72
if bytes.Equal(blockID1.Hash, blockID2.Hash) {
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If both headers are at the same height then the hashes must be different in order to be valid fork misbehaviour.

Suggested change
if bytes.Equal(blockID1.Hash, blockID2.Hash) {
return true
}
if !bytes.Equal(blockID1.Hash, blockID2.Hash) {
return true
}

Comment on lines 74 to 77
} else if msg.Header1.SignedHeader.Header.Time.After(msg.Header2.SignedHeader.Header.Time) {
// Header1 is at greater height than Header2, therefore Header1 time must be less than or equal to
// Header2 time in order to be valid misbehaviour (violation of monotonic time).
return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if msg.Header1.SignedHeader.Header.Time.After(msg.Header2.SignedHeader.Header.Time) {
// Header1 is at greater height than Header2, therefore Header1 time must be less than or equal to
// Header2 time in order to be valid misbehaviour (violation of monotonic time).
return true
} else if !msg.Header1.SignedHeader.Header.Time.After(msg.Header2.SignedHeader.Header.Time) {
// Header1 is at greater height than Header2, therefore Header1 time must be less than or equal to
// Header2 time in order to be valid misbehaviour (violation of monotonic time).
return true

ValidateBasic ensures that header1 height is greater than or equal to header2 height. Therefore, header1 time must be after header2. If it is not, then we violate time monotonicity and should return true as this is considered misbehaviour.

// Header1 is at greater height than Header2, therefore Header1 time must be less than or equal to
// Header2 time in order to be valid misbehaviour (violation of monotonic time).
return true
}
return true
Copy link
Contributor

@damiannolan damiannolan Jan 2, 2023

Choose a reason for hiding this comment

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

If we do not hit a case for valid misbehaviour above we should return false.

edit; this could actually be removed as we would fall out of the switch case and return false on line 82.

@damiannolan
Copy link
Contributor

Hey @Daniyal98, if its okay for you we can push some updates to address some of the comments here if you don't have the capacity.

@Daniyal98
Copy link
Contributor Author

Hey @damiannolan , sorry, it took me a little to resolve this. I have addressed these problems now. Let me know if there is anything missing. Thank you!

@charleenfei
Copy link
Contributor

hey @Daniyal98 it looks like there are still failing tests -- would you mind taking a look and fixing? or let us know if we should take over this pr. thank you!

@Daniyal98
Copy link
Contributor Author

Hey @charleenfei, I am unable to find the time nowadays to work on this. Could you please take over this PR? Thank you

@damiannolan
Copy link
Contributor

Hey @charleenfei, I am unable to find the time nowadays to work on this. Could you please take over this PR? Thank you

Thanks for letting us know @Daniyal98, we can take this over. Thanks for the work you've done on it, much appreciated! ❤️

@charleenfei
Copy link
Contributor

closing in favour of #3046

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.

Move non-verification misbehaviour checks to CheckForMisbehaviour
3 participants