Skip to content

Commit

Permalink
polynomial: make Eq/PartialEq take leading zeros into account
Browse files Browse the repository at this point in the history
Two polynomials are equal even if they have a different number of
leading zeros.

Putting this into its own commit rather than folding it into one of the
FieldVec commits, because this bug was present even before the FieldVec
stuff.

Also remove the `Hash` impl because it's unneeded and we would be
expected to keep it in sync with Eq.
  • Loading branch information
apoelstra committed Sep 22, 2024
1 parent d08da46 commit 0e3d954
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/primitives/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ use super::{ExtensionField, Field, FieldVec};
use crate::Fe32;

/// A polynomial over some field.
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
#[derive(Clone, Debug)]
pub struct Polynomial<F> {
/// The coefficients of the polynomial, in "little-endian" order.
/// That is the constant term is at index 0.
inner: FieldVec<F>,
}

impl<F: Field> PartialEq for Polynomial<F> {
fn eq(&self, other: &Self) -> bool {
self.inner[..self.degree()] == other.inner[..other.degree()]
}
}

impl<F: Field> Eq for Polynomial<F> {}

impl Polynomial<Fe32> {
pub fn from_residue<R: PackedFe32>(residue: R) -> Self {
(0..R::WIDTH).rev().map(|i| Fe32(residue.unpack(i))).collect()
}
}

impl<F: Field> Polynomial<F> {
/// Determines whether the residue is representable, given the current
/// compilation context.
Expand Down

0 comments on commit 0e3d954

Please sign in to comment.