sanity check on validity-votes length (#354)

This commit is contained in:
Robert Habermeier
2019-08-06 15:37:38 +02:00
committed by Gavin Wood
parent 14cf3142d3
commit 8c4d882407
+15 -2
View File
@@ -737,12 +737,20 @@ impl<T: Trait> Module<T> {
let mut encoded_implicit = None; let mut encoded_implicit = None;
let mut encoded_explicit = None; let mut encoded_explicit = None;
for ((auth_index, _), validity_attestation) in candidate.validator_indices let mut expected_votes_len = 0;
for (vote_index, (auth_index, _)) in candidate.validator_indices
.iter() .iter()
.enumerate() .enumerate()
.filter(|(_, bit)| *bit) .filter(|(_, bit)| *bit)
.zip(candidate.validity_votes.iter()) .enumerate()
{ {
let validity_attestation = match candidate.validity_votes.get(vote_index) {
None => return Err("Not enough validity votes"),
Some(v) => {
expected_votes_len = vote_index + 1;
v
}
};
if validator_group.iter().find(|&(idx, _)| *idx == auth_index).is_none() { if validator_group.iter().find(|&(idx, _)| *idx == auth_index).is_none() {
return Err("Attesting validator not on this chain's validation duty."); return Err("Attesting validator not on this chain's validation duty.");
@@ -774,6 +782,11 @@ impl<T: Trait> Module<T> {
"Candidate validity attestation signature is bad." "Candidate validity attestation signature is bad."
); );
} }
ensure!(
candidate.validity_votes.len() == expected_votes_len,
"Extra untagged validity votes along with candidate"
);
} }
Ok(()) Ok(())