-
Notifications
You must be signed in to change notification settings - Fork 110
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!: add check for the height of evidence #2007
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Add missing check for the minimum height of evidence in the consumer double-vote handler. | ||
[#2007](https://github.com/cosmos/interchain-security/pull/2007) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Add missing check for the minimum height of evidence in the consumer double-vote handler. | ||
[#2007](https://github.com/cosmos/interchain-security/pull/2007) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |||||
"bytes" | ||||||
"encoding/binary" | ||||||
"fmt" | ||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||||||
|
||||||
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" | ||||||
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" | ||||||
|
@@ -35,6 +36,27 @@ func (k Keeper) HandleConsumerDoubleVoting( | |||||
chainID string, | ||||||
pubkey cryptotypes.PubKey, | ||||||
) error { | ||||||
// check that the evidence is for an ICS consumer chain | ||||||
if _, found := k.GetConsumerClientId(ctx, chainID); !found { | ||||||
return errorsmod.Wrapf( | ||||||
ccvtypes.ErrInvalidDoubleVotingEvidence, | ||||||
"cannot find consumer chain %s", | ||||||
chainID, | ||||||
) | ||||||
} | ||||||
|
||||||
// check that the evidence is not too old | ||||||
minHeight := k.GetEquivocationEvidenceMinHeight(ctx, chainID) | ||||||
if uint64(evidence.VoteA.Height) < minHeight { | ||||||
return errorsmod.Wrapf( | ||||||
ccvtypes.ErrInvalidDoubleVotingEvidence, | ||||||
"evidence for consumer chain %s is too old - evidence height (%d), min (%d)", | ||||||
chainID, | ||||||
evidence.VoteA.Height, | ||||||
minHeight, | ||||||
) | ||||||
} | ||||||
|
||||||
// verifies the double voting evidence using the consumer chain public key | ||||||
if err := k.VerifyDoubleVotingEvidence(*evidence, chainID, pubkey); err != nil { | ||||||
return err | ||||||
|
@@ -269,34 +291,51 @@ func headerToLightBlock(h ibctmtypes.Header) (*tmtypes.LightBlock, error) { | |||||
} | ||||||
|
||||||
// CheckMisbehaviour checks that headers in the given misbehaviour forms | ||||||
// a valid light client attack on a light client that tracks an ICS consumer chain | ||||||
// a valid light client attack from an ICS consumer chain and that the light client isn't expired | ||||||
func (k Keeper) CheckMisbehaviour(ctx sdk.Context, misbehaviour ibctmtypes.Misbehaviour) error { | ||||||
consumerChainID := misbehaviour.Header1.Header.ChainID | ||||||
|
||||||
// check that the misbehaviour is for an ICS consumer chain | ||||||
clientId, found := k.GetConsumerClientId(ctx, misbehaviour.Header1.Header.ChainID) | ||||||
clientId, found := k.GetConsumerClientId(ctx, consumerChainID) | ||||||
if !found { | ||||||
return fmt.Errorf("incorrect misbehaviour with conflicting headers from a non-existent consumer chain: %s", misbehaviour.Header1.Header.ChainID) | ||||||
return fmt.Errorf("incorrect misbehaviour with conflicting headers from a non-existent consumer chain: %s", consumerChainID) | ||||||
} else if misbehaviour.ClientId != clientId { | ||||||
return fmt.Errorf("incorrect misbehaviour: expected client ID for consumer chain %s is %s got %s", | ||||||
misbehaviour.Header1.Header.ChainID, | ||||||
consumerChainID, | ||||||
clientId, | ||||||
misbehaviour.ClientId, | ||||||
) | ||||||
} | ||||||
|
||||||
// Check that the headers are at the same height to ensure that | ||||||
// the misbehaviour is for a light client attack and not a time violation, | ||||||
// see ibc-go/modules/light-clients/07-tendermint/types/misbehaviour_handle.go | ||||||
if !misbehaviour.Header1.GetHeight().EQ(misbehaviour.Header2.GetHeight()) { | ||||||
return sdkerrors.Wrap(ibcclienttypes.ErrInvalidMisbehaviour, "headers are not at same height") | ||||||
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. Replace deprecated sdkerrors.Wrap.
- return sdkerrors.Wrap(ibcclienttypes.ErrInvalidMisbehaviour, "headers are not at same height")
+ return errorsmod.Wrap(ibcclienttypes.ErrInvalidMisbehaviour, "headers are not at same height") Committable suggestion
Suggested change
Toolsgolangci-lint
|
||||||
} | ||||||
|
||||||
// Check that the evidence is not too old | ||||||
minHeight := k.GetEquivocationEvidenceMinHeight(ctx, consumerChainID) | ||||||
evidenceHeight := misbehaviour.Header1.GetHeight().GetRevisionHeight() | ||||||
// Note that the revision number is not relevant for checking the age of evidence | ||||||
// as it's already part of the chain ID and the minimum height is mapped to chain IDs | ||||||
if evidenceHeight < minHeight { | ||||||
return errorsmod.Wrapf( | ||||||
ccvtypes.ErrInvalidDoubleVotingEvidence, | ||||||
"evidence for consumer chain %s is too old - evidence height (%d), min (%d)", | ||||||
consumerChainID, | ||||||
evidenceHeight, | ||||||
minHeight, | ||||||
) | ||||||
} | ||||||
|
||||||
clientState, found := k.clientKeeper.GetClientState(ctx, clientId) | ||||||
if !found { | ||||||
return errorsmod.Wrapf(ibcclienttypes.ErrClientNotFound, "cannot find client state for client with ID %s", clientId) | ||||||
} | ||||||
|
||||||
clientStore := k.clientKeeper.ClientStore(ctx, clientId) | ||||||
|
||||||
// Check that the headers are at the same height to ensure that | ||||||
// the misbehaviour is for a light client attack and not a time violation, | ||||||
// see CheckForMisbehaviour in ibc-go/blob/v7.3.0/modules/light-clients/07-tendermint/misbehaviour_handle.go#L73 | ||||||
if !misbehaviour.Header1.GetHeight().EQ(misbehaviour.Header2.GetHeight()) { | ||||||
return errorsmod.Wrap(ibcclienttypes.ErrInvalidMisbehaviour, "headers are not at same height") | ||||||
} | ||||||
|
||||||
// CheckForMisbehaviour verifies that the headers have different blockID hashes | ||||||
ok := clientState.CheckForMisbehaviour(ctx, k.cdc, clientStore, &misbehaviour) | ||||||
if !ok { | ||||||
|
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.
Sort imports according to the Uber Golang style guide.
The imports should be sorted according to the Uber Golang style guide.
Committable suggestion
Tools
golangci-lint