Skip to main content

Mask

Struct Mask 

Source
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 variables
  • m_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>

Source

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.
Source

pub const fn n_vars(&self) -> usize

Returns the number of variables.

Source

pub const fn degree(&self) -> usize

Returns the degree of each univariate polynomial.

Source

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$).

Source

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.

Source

pub fn evaluate_univariate(&self, var_index: usize, x: F) -> F

Evaluates g_i(x) for a specific variable using Horner’s method.

Source

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>

Source§

fn as_ref(&self) -> &FieldBuffer<P, Data>

Converts this type into a shared reference of the (usually inferred) input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more