-
Notifications
You must be signed in to change notification settings - Fork 585
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
fix: moved non-verification misbehaviour checks to checkForMisbehaviour #3046
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
63e205e
move misbehaviour check
charleenfei 3579706
rm redundant return
charleenfei 6d6a6eb
add test coverage
charleenfei 2917473
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei 5738890
pr review comments
charleenfei 754cb08
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei 95acc3f
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei d2c27ab
add link to hyperlink
crodriguezvega 2f8d406
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei 03b2078
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei d056c7c
Merge branch 'main' into charly/non-verification-misbehaviour
crodriguezvega 132dd06
Merge branch 'main' into charly/non-verification-misbehaviour
charleenfei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
) | ||
|
||
// CheckForMisbehaviour detects duplicate height misbehaviour and BFT time violation misbehaviour | ||
// in a submitted Header message and verifies the correctness of a submitted Misbehaviour ClientMessage | ||
func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool { | ||
switch msg := msg.(type) { | ||
case *Header: | ||
|
@@ -51,9 +52,29 @@ func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCode | |
return true | ||
} | ||
case *Misbehaviour: | ||
// 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 | ||
return true | ||
// if heights are equal check that this is valid misbehaviour of a fork | ||
// otherwise if heights are unequal check that this is valid misbehavior of BFT time violation | ||
if msg.Header1.GetHeight().EQ(msg.Header2.GetHeight()) { | ||
blockID1, err := tmtypes.BlockIDFromProto(&msg.Header1.SignedHeader.Commit.BlockID) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
blockID2, err := tmtypes.BlockIDFromProto(&msg.Header2.SignedHeader.Commit.BlockID) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
// Ensure that Commit Hashes are different | ||
if !bytes.Equal(blockID1.Hash, blockID2.Hash) { | ||
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 | ||
} | ||
} | ||
|
||
return false | ||
|
@@ -68,30 +89,6 @@ func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCode | |
// to misbehaviour.Header2 | ||
// Misbehaviour sets frozen height to {0, 1} since it is only used as a boolean value (zero or non-zero). | ||
func (cs *ClientState) verifyMisbehaviour(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, misbehaviour *Misbehaviour) error { | ||
// if heights are equal check that this is valid misbehaviour of a fork | ||
// otherwise if heights are unequal check that this is valid misbehavior of BFT time violation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also copy over these 2 lines of comments? |
||
if misbehaviour.Header1.GetHeight().EQ(misbehaviour.Header2.GetHeight()) { | ||
blockID1, err := tmtypes.BlockIDFromProto(&misbehaviour.Header1.SignedHeader.Commit.BlockID) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "invalid block ID from header 1 in misbehaviour") | ||
} | ||
|
||
blockID2, err := tmtypes.BlockIDFromProto(&misbehaviour.Header2.SignedHeader.Commit.BlockID) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "invalid block ID from header 2 in misbehaviour") | ||
} | ||
|
||
// Ensure that Commit Hashes are different | ||
if bytes.Equal(blockID1.Hash, blockID2.Hash) { | ||
return sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers block hashes are equal") | ||
} | ||
|
||
} else if misbehaviour.Header1.SignedHeader.Header.Time.After(misbehaviour.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 sdkerrors.Wrap(clienttypes.ErrInvalidMisbehaviour, "headers are not at same height and are monotonically increasing") | ||
} | ||
|
||
// Regardless of the type of misbehaviour, ensure that both headers are valid and would have been accepted by light-client | ||
|
||
// Retrieve trusted consensus states for each Header in misbehaviour | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything we should update in the godoc of this function after this change?