Skip to content

Commit

Permalink
check that header1 and header2 have the same TrustedValidators
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Jul 21, 2023
1 parent b60499c commit b00337a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NewSubmitConsumerMisbehaviourCmd() *cobra.Command {
Long: strings.TrimSpace(
fmt.Sprintf(`Submit a IBC misbehaviour detected on a consumer chain.
A IBC misbehaviour contains two conflicting IBC client headers, which are used to form a light client attack evidence.
The misbehaviour type definition can be found in the IBC client messages, see ibc-go/proto/ibc/core/client/v1/tx.proto`.
The misbehaviour type definition can be found in the IBC client messages, see ibc-go/proto/ibc/core/client/v1/tx.proto.
Examples:
%s tx provider submit-consumer-misbehaviour [path/to/misbehaviour.json] --from node0 --home ../node0 --chain-id $CID
Expand Down
14 changes: 10 additions & 4 deletions x/ccv/provider/keeper/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"reflect"
"time"

"github.com/cosmos/interchain-security/v2/x/ccv/provider/types"
Expand All @@ -16,7 +17,7 @@ import (
// CheckConsumerMisbehaviour check that the given IBC misbehaviour headers forms a valid light client attack evidence.
// proceed to the jailing and tombstoning of the bzyantine validators.
func (k Keeper) HandleConsumerMisbehaviour(ctx sdk.Context, misbehaviour ibctmtypes.Misbehaviour) error {
logger := ctx.Logger()
logger := k.Logger(ctx)

if err := k.clientKeeper.CheckMisbehaviourAndUpdateState(ctx, &misbehaviour); err != nil {
return err
Expand Down Expand Up @@ -111,18 +112,23 @@ func (k Keeper) ConstructLightClientEvidence(ctx sdk.Context, misbehaviour ibctm
// GetCommonFromMisbehaviour checks whether the given ibc misbehaviour's headers share common trusted height
// and that a consensus state exists for this height. In this case, it returns the associated trusted height, timestamp and valset.
func (k Keeper) GetTrustedInfoFromMisbehaviour(ctx sdk.Context, misbehaviour ibctmtypes.Misbehaviour) (int64, time.Time, *tmtypes.ValidatorSet, error) {
// a common trusted height is required
// a common trusted validator set and height is required
commonHeight := misbehaviour.Header1.TrustedHeight
if !commonHeight.EQ(misbehaviour.Header2.TrustedHeight) {
return 0, time.Time{}, nil, fmt.Errorf("misbehaviour headers have different trusted height: %v , %v", commonHeight, misbehaviour.Header2.TrustedHeight)
}

cs, ok := k.clientKeeper.GetClientConsensusState(ctx, misbehaviour.GetClientID(), misbehaviour.Header1.TrustedHeight)
commonValset := misbehaviour.Header1.TrustedValidators
if !reflect.DeepEqual(commonValset.Validators, misbehaviour.Header2.TrustedValidators.Validators) {
return 0, time.Time{}, nil, fmt.Errorf("misbehaviour headers have different trusted validator set: %v , %v", commonHeight, misbehaviour.Header2.TrustedHeight)
}

cs, ok := k.clientKeeper.GetClientConsensusState(ctx, misbehaviour.GetClientID(), commonHeight)
if !ok {
return 0, time.Time{}, nil, fmt.Errorf("cannot find consensus state at trusted height %d for client %s", commonHeight, misbehaviour.GetClientID())
}

vs, err := tmtypes.ValidatorSetFromProto(misbehaviour.Header1.ValidatorSet)
vs, err := tmtypes.ValidatorSetFromProto(commonValset)
if err != nil {
return 0, time.Time{}, nil, err
}
Expand Down

0 comments on commit b00337a

Please sign in to comment.