Skip to content

Commit 16755fe

Browse files
mpokesainoe
andauthored
feat!: add height-base filter for consumer equivocation evidence (#1435)
* 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]>
1 parent 37982d4 commit 16755fe

13 files changed

+920
-760
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
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.
66

7+
* (feat!) [#1435](https://github.com/cosmos/interchain-security/pull/1435) Add height-base filter for consumer equivocation evidence.
8+
79
## v2.3.0-provider-lsm
810

911
*November 15, 2023*

tests/integration/double_vote.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
3535
blockID1 := testutil.MakeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
3636
blockID2 := testutil.MakeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))
3737

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

@@ -76,6 +83,17 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
7683
s.consumerChain.ChainID,
7784
)
7885

86+
// create a vote using the consumer validator key
87+
// with block height that is smaller than the equivocation evidence min height
88+
consuVoteOld := testutil.MakeAndSignVote(
89+
blockID1,
90+
int64(equivocationEvidenceMinHeight-1),
91+
s.consumerCtx().BlockTime(),
92+
consuValSet,
93+
consuSigner,
94+
s.consumerChain.ChainID,
95+
)
96+
7997
testCases := []struct {
8098
name string
8199
ev *tmtypes.DuplicateVoteEvidence
@@ -84,7 +102,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
84102
expPass bool
85103
}{
86104
{
87-
"invalid consumer chain id - shouldn't pass",
105+
"cannot find consumer chain for the given chain ID - shouldn't pass",
88106
&tmtypes.DuplicateVoteEvidence{
89107
VoteA: consuVote,
90108
VoteB: consuBadVote,
@@ -96,6 +114,32 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
96114
consuVal.PubKey,
97115
false,
98116
},
117+
{
118+
"evidence is older than equivocation evidence min height - shouldn't pass",
119+
&tmtypes.DuplicateVoteEvidence{
120+
VoteA: consuVoteOld,
121+
VoteB: consuBadVote,
122+
ValidatorPower: consuVal.VotingPower,
123+
TotalVotingPower: consuVal.VotingPower,
124+
Timestamp: s.consumerCtx().BlockTime(),
125+
},
126+
s.consumerChain.ChainID,
127+
consuVal.PubKey,
128+
false,
129+
},
130+
{
131+
"the votes in the evidence are for different height - shouldn't pass",
132+
&tmtypes.DuplicateVoteEvidence{
133+
VoteA: consuVote,
134+
VoteB: consuVoteOld,
135+
ValidatorPower: consuVal.VotingPower,
136+
TotalVotingPower: consuVal.VotingPower,
137+
Timestamp: s.consumerCtx().BlockTime(),
138+
},
139+
s.consumerChain.ChainID,
140+
consuVal.PubKey,
141+
false,
142+
},
99143
{
100144
"wrong public key - shouldn't pass",
101145
&tmtypes.DuplicateVoteEvidence{

tests/integration/misbehaviour.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
408408
altSigners2,
409409
)
410410

411+
// Set the equivocation evidence min height to the previous block height
412+
equivocationEvidenceMinHeight := clientHeight.RevisionHeight + 1
413+
s.providerApp.GetProviderKeeper().SetEquivocationEvidenceMinHeight(
414+
s.providerCtx(),
415+
s.consumerChain.ChainID,
416+
equivocationEvidenceMinHeight,
417+
)
418+
411419
testCases := []struct {
412420
name string
413421
misbehaviour *ibctmtypes.Misbehaviour
@@ -476,6 +484,24 @@ func (s *CCVTestSuite) TestCheckMisbehaviour() {
476484
},
477485
false,
478486
},
487+
{
488+
"invalid misbehaviour older than the min equivocation evidence height - shouldn't pass",
489+
&ibctmtypes.Misbehaviour{
490+
ClientId: s.path.EndpointA.ClientID,
491+
Header1: s.consumerChain.CreateTMClientHeader(
492+
s.consumerChain.ChainID,
493+
int64(equivocationEvidenceMinHeight-1),
494+
clientHeight,
495+
headerTs,
496+
altValset,
497+
altValset,
498+
clientTMValset,
499+
altSigners,
500+
),
501+
Header2: clientHeader,
502+
},
503+
false,
504+
},
479505
{
480506
"one header of the misbehaviour has insufficient voting power - shouldn't pass",
481507
&ibctmtypes.Misbehaviour{

0 commit comments

Comments
 (0)