Skip to content

Commit

Permalink
last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 13, 2023
1 parent b5241a1 commit 65b6bae
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
60 changes: 49 additions & 11 deletions tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
clientSigners,
)

// create conflicting header with 2/4 validators voting nil
clientHeaderWithNilVotes := s.consumerChain.CreateTMClientHeader(
clientHeaderWithCorruptedValset := s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
Expand All @@ -161,15 +160,54 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
clientSigners,
)

testutil.CorruptValidatorPubkeyInHeader(clientHeaderWithNilVotes, clientTMValset.Validators[0].Address)
// change a validator public key in one the second header
testutil.CorruptValidatorPubkeyInHeader(clientHeaderWithCorruptedValset, clientTMValset.Validators[0].Address)

return &ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: clientHeader,
Header2: clientHeaderWithNilVotes,
Header2: clientHeaderWithCorruptedValset,
}
},
[]*tmtypes.Validator{},
false,
},
{
"incorrect valset 2 - shouldn't pass",
func() *ibctmtypes.Misbehaviour {
clientHeader := s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime.Add(time.Minute),
clientTMValset,
clientTMValset,
clientTMValset,
clientSigners,
)

clientHeaderWithCorruptedSigs := s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime.Add(time.Hour),
clientTMValset,
clientTMValset,
clientTMValset,
clientSigners,
)

// change the valset in the header
vs, _ := altValset.ToProto()
clientHeader.ValidatorSet.Validators = vs.Validators[:3]
clientHeaderWithCorruptedSigs.ValidatorSet.Validators = vs.Validators[:3]

return &ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: clientHeader,
Header2: clientHeaderWithCorruptedSigs,
}
},
// Expect validators who did NOT vote nil
[]*tmtypes.Validator{},
false,
},
Expand All @@ -187,8 +225,7 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
clientSigners,
)

// create conflicting header with 2/4 validators voting nil
clientHeaderWithNilVotes := s.consumerChain.CreateTMClientHeader(
clientHeaderWithCorruptedSigs := s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
Expand All @@ -198,15 +235,16 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
clientTMValset,
clientSigners,
)
testutil.CorruptCommitSigsInHeader(clientHeaderWithNilVotes, clientTMValset.Validators[0].Address)

// change the signature of one of the validator in the header
testutil.CorruptCommitSigsInHeader(clientHeaderWithCorruptedSigs, clientTMValset.Validators[0].Address)

return &ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: clientHeader,
Header2: clientHeaderWithNilVotes,
Header2: clientHeaderWithCorruptedSigs,
}
},
// Expect validators who did NOT vote nil
[]*tmtypes.Validator{},
false,
},
Expand Down Expand Up @@ -300,7 +338,7 @@ func (s *CCVTestSuite) TestGetByzantineValidators() {
s.Equal(len(tc.expByzantineValidators), len(byzantineValidators))

// For both lunatic and equivocation attacks, all the validators
// who signed both headers and didn't vote nil should be returned
// who signed both headers
if len(tc.expByzantineValidators) > 0 {
expValset := tmtypes.NewValidatorSet(tc.expByzantineValidators)
s.NoError(err)
Expand Down
7 changes: 5 additions & 2 deletions x/ccv/provider/keeper/misbehaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@ func verifyLightBlockCommitSig(lightBlock tmtypes.LightBlock, sigIdx int) error
sig := lightBlock.Commit.Signatures[sigIdx]

// get validator
_, val := lightBlock.ValidatorSet.GetByAddress(sig.ValidatorAddress)
idx, val := lightBlock.ValidatorSet.GetByAddress(sig.ValidatorAddress)
if idx == -1 {
return fmt.Errorf("incorrect signature: validator address %s isn't part of the validator set", sig.ValidatorAddress.String())
}

// verify validator pubkey corresponds to signature validator address
if !bytes.Equal(val.PubKey.Address(), sig.ValidatorAddress) {
return fmt.Errorf("validator public key doesn't correspond to signature validator address: %d!= %d", val.PubKey.Address(), sig.ValidatorAddress)
return fmt.Errorf("validator public key doesn't correspond to signature validator address: %s!= %s", val.PubKey.Address(), sig.ValidatorAddress)
}

// validate signature
Expand Down

0 comments on commit 65b6bae

Please sign in to comment.