pub struct Mask<P: PackedField, Data: Deref<Target = [P]> = Box<[P]>> { /* private fields */ }Expand description
Libra mask polynomial for ZK MLE-check protocols.
Stores coefficients for a separable polynomial $g(X) = \sum_i g_i(X_i)$ where each $g_i$ is a univariate polynomial of degree $d$.
The coefficients are stored in a FieldBuffer with m_n + m_d variables where:
m_n = ceil(log2(n))- log of number of variablesm_d = ceil(log2(d + 1))- log of degree + 1
The buffer is conceptually an n × (d+1) matrix padded to 2^m_n × 2^m_d,
with random values in the n × (d+1) submatrix and zeros elsewhere.
The type is generic over the buffer storage type Data, allowing it to work
with both owned buffers (Box<[P]>) and borrowed slices.
Implementations§
Source§impl<F: Field, P: PackedField<Scalar = F>, Data: Deref<Target = [P]>> Mask<P, Data>
impl<F: Field, P: PackedField<Scalar = F>, Data: Deref<Target = [P]>> Mask<P, Data>
Sourcepub const fn new(
n_vars: usize,
degree: usize,
buffer: FieldBuffer<P, Data>,
) -> Self
pub const fn new( n_vars: usize, degree: usize, buffer: FieldBuffer<P, Data>, ) -> Self
Creates a new mask polynomial from a pre-allocated buffer.
§Arguments
n_vars- Number of variables (n).degree- Degree of each univariate polynomial (d).buffer- Buffer with log_len = m_n + m_d.
Sourcepub fn get_coeff(&self, var_index: usize, coeff_index: usize) -> F
pub fn get_coeff(&self, var_index: usize, coeff_index: usize) -> F
Gets the coefficient $g_{i,j}$ (coefficient of $X^j$ in $g_i$).
Sourcepub fn coeffs_for_var(&self, var_index: usize) -> impl Iterator<Item = F> + '_
pub fn coeffs_for_var(&self, var_index: usize) -> impl Iterator<Item = F> + '_
Returns the monomial coefficients [g_{i,0}, g_{i,1}, …, g_{i,d}] for variable i.
Sourcepub fn evaluate_univariate(&self, var_index: usize, x: F) -> F
pub fn evaluate_univariate(&self, var_index: usize, x: F) -> F
Evaluates g_i(x) for a specific variable using Horner’s method.
Sourcepub fn evaluate_mle(&self, eval_point: &[F]) -> F
pub fn evaluate_mle(&self, eval_point: &[F]) -> F
Computes the MLE of the mask polynomial at a point.
For a mask polynomial $g(X) = \sum_i g_i(X_i)$ where each $g_i$ is univariate, the MLE at point $z$ is:
$$ \sum_{v \in {0,1}^n} g(v) \cdot eq(v, z) = \sum_i [(1-z_i) g_i(0) + z_i g_i(1)] $$
This simplification arises because $\sum_{v_j \in {0,1}} eq_1(v_j, z_j) = 1$.
Trait Implementations§
Source§impl<P: PackedField, Data: Deref<Target = [P]>> AsRef<FieldBuffer<P, Data>> for Mask<P, Data>
impl<P: PackedField, Data: Deref<Target = [P]>> AsRef<FieldBuffer<P, Data>> for Mask<P, Data>
Source§fn as_ref(&self) -> &FieldBuffer<P, Data>
fn as_ref(&self) -> &FieldBuffer<P, Data>
Auto Trait Implementations§
impl<P, Data> Freeze for Mask<P, Data>where
Data: Freeze,
impl<P, Data> RefUnwindSafe for Mask<P, Data>where
Data: RefUnwindSafe,
impl<P, Data> Send for Mask<P, Data>where
Data: Send,
impl<P, Data> Sync for Mask<P, Data>where
Data: Sync,
impl<P, Data> Unpin for Mask<P, Data>where
Data: Unpin,
impl<P, Data> UnsafeUnpin for Mask<P, Data>where
Data: UnsafeUnpin,
impl<P, Data> UnwindSafe for Mask<P, Data>where
Data: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more