Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func (l *LightClientAttackEvidence) ValidateBasic() error {
return errors.New("conflicting block is nil")
}

if l.ConflictingBlock.SignedHeader == nil {
return errors.New("conflicting block missing signed header")
}

// this check needs to be done before we can run validate basic
if l.ConflictingBlock.Header == nil {
return errors.New("conflicting block missing header")
Expand Down
21 changes: 21 additions & 0 deletions types/evidence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) {
{"Height is equal to the divergent block", func(ev *LightClientAttackEvidence) {
ev.CommonHeight = height
}, false},
{"Nil conflicting signed header", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock.SignedHeader = nil }, true},
{"Nil conflicting header", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock.Header = nil }, true},
{"Nil conflicting blocl", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock = nil }, true},
{"Nil validator set", func(ev *LightClientAttackEvidence) {
Expand Down Expand Up @@ -229,6 +230,26 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) {

}

func TestLightClientAttackEvidenceFromProtoNilConflictingSignedHeader(t *testing.T) {
height := int64(5)
_, valSet, _ := randVoteSet(height, 1, cmtproto.PrecommitType, 10, 1, false)
valsProto, err := valSet.ToProto()
require.NoError(t, err)

evidenceProto := &cmtproto.LightClientAttackEvidence{
ConflictingBlock: &cmtproto.LightBlock{
ValidatorSet: valsProto,
},
CommonHeight: height - 1,
TotalVotingPower: valSet.TotalVotingPower(),
}

require.NotPanics(t, func() {
_, err = LightClientAttackEvidenceFromProto(evidenceProto)
})
require.ErrorContains(t, err, "conflicting block missing signed header")
}

func TestMockEvidenceValidateBasic(t *testing.T) {
goodEvidence, err := NewMockDuplicateVoteEvidence(int64(1), time.Now(), "mock-chain-id")
require.NoError(t, err)
Expand Down
Loading