Skip to content

Commit

Permalink
do not panic on invalid ValidatorIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Nov 6, 2024
1 parent cfee87f commit 46a2453
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,14 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error
// Here, we verify the signature of the vote extension included in the vote
// message.
_, val := cs.state.Validators.GetByIndex(vote.ValidatorIndex)
if val == nil { // TODO: we should disconnect from this malicious peer
valsCount := cs.state.Validators.Size()
cs.Logger.Info("Peer sent us vote with invalid ValidatorIndex",
"peer", peerID,
"validator_index", vote.ValidatorIndex,
"len_validators", valsCount)
return added, fmt.Errorf("ValidatorIndex %d is out of bounds [0, %d)", vote.ValidatorIndex, valsCount)
}
if err := vote.VerifyExtension(cs.state.ChainID, val.PubKey); err != nil {
return false, err
}
Expand Down

0 comments on commit 46a2453

Please sign in to comment.