Skip to content

Commit df5b8bd

Browse files
fix: guard nil light client attack signed header
1 parent 904204b commit df5b8bd

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

types/evidence.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ func (l *LightClientAttackEvidence) ValidateBasic() error {
357357
return errors.New("conflicting block is nil")
358358
}
359359

360+
if l.ConflictingBlock.SignedHeader == nil {
361+
return errors.New("conflicting block missing signed header")
362+
}
363+
360364
// this check needs to be done before we can run validate basic
361365
if l.ConflictingBlock.Header == nil {
362366
return errors.New("conflicting block missing header")

types/evidence_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) {
193193
{"Height is equal to the divergent block", func(ev *LightClientAttackEvidence) {
194194
ev.CommonHeight = height
195195
}, false},
196+
{"Nil conflicting signed header", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock.SignedHeader = nil }, true},
196197
{"Nil conflicting header", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock.Header = nil }, true},
197198
{"Nil conflicting blocl", func(ev *LightClientAttackEvidence) { ev.ConflictingBlock = nil }, true},
198199
{"Nil validator set", func(ev *LightClientAttackEvidence) {
@@ -229,6 +230,26 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) {
229230

230231
}
231232

233+
func TestLightClientAttackEvidenceFromProtoNilConflictingSignedHeader(t *testing.T) {
234+
height := int64(5)
235+
_, valSet, _ := randVoteSet(height, 1, cmtproto.PrecommitType, 10, 1, false)
236+
valsProto, err := valSet.ToProto()
237+
require.NoError(t, err)
238+
239+
evidenceProto := &cmtproto.LightClientAttackEvidence{
240+
ConflictingBlock: &cmtproto.LightBlock{
241+
ValidatorSet: valsProto,
242+
},
243+
CommonHeight: height - 1,
244+
TotalVotingPower: valSet.TotalVotingPower(),
245+
}
246+
247+
require.NotPanics(t, func() {
248+
_, err = LightClientAttackEvidenceFromProto(evidenceProto)
249+
})
250+
require.ErrorContains(t, err, "conflicting block missing signed header")
251+
}
252+
232253
func TestMockEvidenceValidateBasic(t *testing.T) {
233254
goodEvidence, err := NewMockDuplicateVoteEvidence(int64(1), time.Now(), "mock-chain-id")
234255
require.NoError(t, err)

0 commit comments

Comments
 (0)