Skip to content

Commit

Permalink
feat!: add height-base filter for consumer equivocation evidence (#1435)
Browse files Browse the repository at this point in the history
* check the chainID for ConsumerDoubleVoting

* refactor: move all equivocation work in one file

* filter consumer evidence based on min height

* set min evidence height on CreateConsumerClient

* cleanup state on chain removal

* add CRUD test

* add integration tests for double voting

* add integration tests for misbehaviour

* update proposal UTs

* add changelog entry

---------

Co-authored-by: Simon Noetzlin <[email protected]>
  • Loading branch information
mpoke and sainoe authored Nov 17, 2023
1 parent 37982d4 commit 16755fe
Show file tree
Hide file tree
Showing 13 changed files with 920 additions and 760 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Add an entry to the unreleased section whenever merging a PR to main that is not targeted at a specific release. These entries will eventually be included in a release.

* (feat!) [#1435](https://github.com/cosmos/interchain-security/pull/1435) Add height-base filter for consumer equivocation evidence.

## v2.3.0-provider-lsm

*November 15, 2023*
Expand Down
46 changes: 45 additions & 1 deletion tests/integration/double_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
blockID1 := testutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
blockID2 := testutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))

// Set the equivocation evidence min height to the previous block height
equivocationEvidenceMinHeight := uint64(s.consumerCtx().BlockHeight() - 1)
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
s.providerCtx(),
s.consumerChain.ChainID,
equivocationEvidenceMinHeight,
)
// Note that votes are signed along with the chain ID
// see VoteSignBytes in https://github.com/cometbft/cometbft/blob/main/types/vote.go#L139

Expand Down Expand Up @@ -76,6 +83,17 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
s.consumerChain.ChainID,
)

// create a vote using the consumer validator key
// with block height that is smaller than the equivocation evidence min height
consuVoteOld := testutil.MakeAndSignVote(
blockID1,
int64(equivocationEvidenceMinHeight-1),
s.consumerCtx().BlockTime(),
consuValSet,
consuSigner,
s.consumerChain.ChainID,
)

testCases := []struct {
name string
ev *tmtypes.DuplicateVoteEvidence
Expand All @@ -84,7 +102,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
expPass bool
}{
{
"invalid consumer chain id - shouldn't pass",
"cannot find consumer chain for the given chain ID - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuBadVote,
Expand All @@ -96,6 +114,32 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
consuVal.PubKey,
false,
},
{
"evidence is older than equivocation evidence min height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVoteOld,
VoteB: consuBadVote,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"the votes in the evidence are for different height - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuVoteOld,
ValidatorPower: consuVal.VotingPower,
TotalVotingPower: consuVal.VotingPower,
Timestamp: s.consumerCtx().BlockTime(),
},
s.consumerChain.ChainID,
consuVal.PubKey,
false,
},
{
"wrong public key - shouldn't pass",
&tmtypes.DuplicateVoteEvidence{
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
altSigners2,
)

// Set the equivocation evidence min height to the previous block height
equivocationEvidenceMinHeight := clientHeight.RevisionHeight + 1
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
s.providerCtx(),
s.consumerChain.ChainID,
equivocationEvidenceMinHeight,
)

testCases := []struct {
name string
misbehaviour *ibctmtypes.Misbehaviour
Expand Down Expand Up @@ -476,6 +484,24 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
},
false,
},
{
"invalid misbehaviour older than the min equivocation evidence height - shouldn't pass",
&ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(equivocationEvidenceMinHeight-1),
clientHeight,
headerTs,
altValset,
altValset,
clientTMValset,
altSigners,
),
Header2: clientHeader,
},
false,
},
{
"one header of the misbehaviour has insufficient voting power - shouldn't pass",
&ibctmtypes.Misbehaviour{
Expand Down
Loading

0 comments on commit 16755fe

Please sign in to comment.