Skip to content

Commit

Permalink
Merge pull request #2125 from ljedrz/fix/2121
Browse files Browse the repository at this point in the history
Avoid indexing out of range in skip_leading_zeros_and_convert_to_bigints
  • Loading branch information
howardwu authored Dec 17, 2023
2 parents 2857b2e + 72192cf commit cd607f5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions algorithms/src/polycommit/kzg10/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,12 @@ fn skip_leading_zeros_and_convert_to_bigints<F: PrimeField>(p: &DensePolynomial<
if p.coeffs.is_empty() {
(0, vec![])
} else {
let mut num_leading_zeros = 0;
while p.coeffs[num_leading_zeros].is_zero() && num_leading_zeros < p.coeffs.len() {
num_leading_zeros += 1;
}
let coeffs = convert_to_bigints(&p.coeffs[num_leading_zeros..]);
let num_leading_zeros = p.coeffs.iter().take_while(|c| c.is_zero()).count();
let coeffs = if num_leading_zeros == p.coeffs.len() {
vec![]
} else {
convert_to_bigints(&p.coeffs[num_leading_zeros..])
};
(num_leading_zeros, coeffs)
}
}
Expand Down

0 comments on commit cd607f5

Please sign in to comment.