Skip to content

Commit

Permalink
explain why won't panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole authored and Nicole committed Oct 30, 2024
1 parent 0a50704 commit c00a223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion math/src/circle/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub fn evaluate_cfft(
pub fn interpolate_cfft(
mut eval: Vec<FieldElement<Mersenne31Field>>,
) -> Vec<FieldElement<Mersenne31Field>> {
if eval.len() == 0 {
return vec![FieldElement::<Mersenne31Field>::zero()];
}

// We get the twiddles for the interpolation.
let domain_log_2_size: u32 = eval.len().trailing_zeros();
let coset = Coset::new_standard(domain_log_2_size);
Expand All @@ -53,7 +57,8 @@ pub fn interpolate_cfft(
in_place_bit_reverse_permute::<FieldElement<Mersenne31Field>>(&mut eval_ordered);

// The icfft returns all the coefficients multiplied by 2^n, the length of the evaluations.
// So we multiply every element that outputs the icfft byt the inverse of 2^n to get the actual coefficients.
// So we multiply every element that outputs the icfft by the inverse of 2^n to get the actual coefficients.
// Note that this `unwrap` will never panic because eval.len() != 0.
let factor = (FieldElement::<Mersenne31Field>::from(eval.len() as u64))
.inv()
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions math/src/circle/twiddles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub fn get_twiddles(

if config == TwiddlesConfig::Interpolation {
// For the interpolation, we need to take the inverse element of each twiddle in the default order.
// We can take inverse being sure that the `unwrap` won't panic because the twiddles are coordinates
// of elements of the coset (or their squares) so they can't be zero.
twiddles.iter_mut().for_each(|x| {
FieldElement::<Mersenne31Field>::inplace_batch_inverse(x).unwrap();
});
Expand Down

0 comments on commit c00a223

Please sign in to comment.