Skip to content

Commit cd4242d

Browse files
committed
core/vm: cap CometBFT light client validator count to prevent DoS
1 parent f2d351c commit cd4242d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

core/vm/lightclient/v2/lightclient.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func DecodeConsensusState(input []byte) (ConsensusState, error) {
143143
if inputLen <= minimumLength || (inputLen-minimumLength)%singleValidatorBytesLength != 0 {
144144
return ConsensusState{}, fmt.Errorf("expected input size %d+%d*N, actual input size: %d", minimumLength, singleValidatorBytesLength, inputLen)
145145
}
146+
if inputLen > maxConsensusStateLength {
147+
return ConsensusState{}, fmt.Errorf("consensus state too large: %d bytes exceeds maximum %d (max 99 validators)", inputLen, maxConsensusStateLength)
148+
}
146149

147150
pos := uint64(0)
148151
chainID := string(bytes.Trim(input[pos:pos+chainIDLength], "\x00"))
@@ -207,6 +210,10 @@ func DecodeLightBlockValidationInput(input []byte) (*ConsensusState, *types.Ligh
207210
return nil, nil, fmt.Errorf("integer overflow, csLen: %d", csLen)
208211
}
209212

213+
if csLen > maxConsensusStateLength {
214+
return nil, nil, fmt.Errorf("consensus state length %d exceeds maximum %d", csLen, maxConsensusStateLength)
215+
}
216+
210217
if uint64(len(input)) <= consensusStateLengthBytesLength+csLen {
211218
return nil, nil, fmt.Errorf("expected payload size %d, actual size: %d", consensusStateLengthBytesLength+csLen, len(input))
212219
}

0 commit comments

Comments
 (0)