#[repr(transparent)]pub struct Elem(_);
Expand description
The BabyBear class is an element of the finite field F_p, where P is the prime number 15*2^27 + 1. Put another way, Fp is basically integer arithmetic modulo P.
The Fp
datatype is the core type of all of the operations done within the
zero knowledge proofs, and is the smallest ‘addressable’ datatype, and the
base type of which all composite types are built. In many ways, one can
imagine it as the word size of a very strange architecture.
This specific prime P was chosen to:
- Be less than 2^31 so that it fits within a 32 bit word and doesn’t overflow on addition.
- Otherwise have as large a power of 2 in the factors of P-1 as possible.
This last property is useful for number theoretical transforms (the fast fourier transform equivelant on finite fields). See NTT.h for details.
The Fp class wraps all the standard arithmetic operations to make the finite field elements look basically like ordinary numbers (which they mostly are).
Implementations§
Trait Implementations§
source§impl AddAssign<Elem> for Elem
impl AddAssign<Elem> for Elem
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Simple addition case for Baby Bear Elem
source§impl Elem for Elem
impl Elem for Elem
source§fn inv(self) -> Self
fn inv(self) -> Self
Compute the multiplicative inverse of x
, or 1 / x
in finite field
terms. Since we know by Fermat’s Little Theorem that
x ^ (P - 1) == 1 % P
for any x != 0
,
it follows that x * x ^ (P - 2) == 1 % P
for x != 0
.
That is, x ^ (P - 2)
is the multiplicative inverse of x
.
Note that if computed this way, the inverse of zero comes out as zero,
which we allow because it is convenient in many cases.
source§const INVALID: Self = _
const INVALID: Self = _
source§fn to_u32_words(&self) -> Vec<u32>
fn to_u32_words(&self) -> Vec<u32>
source§fn from_u32_words(val: &[u32]) -> Self
fn from_u32_words(val: &[u32]) -> Self
source§fn is_valid(&self) -> bool
fn is_valid(&self) -> bool
source§fn valid_or_zero(&self) -> Self
fn valid_or_zero(&self) -> Self
source§fn ensure_valid(&self) -> &Self
fn ensure_valid(&self) -> &Self
source§fn as_u32_slice(elems: &[Self]) -> &[u32]
fn as_u32_slice(elems: &[Self]) -> &[u32]
source§fn as_u32_slice_unchecked(elems: &[Self]) -> &[u32]
fn as_u32_slice_unchecked(elems: &[Self]) -> &[u32]
source§impl MulAssign<Elem> for Elem
impl MulAssign<Elem> for Elem
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Simple multiplication case for Baby Bear Elem
source§impl MulAssign<Elem> for ExtElem
impl MulAssign<Elem> for ExtElem
source§fn mul_assign(&mut self, rhs: Elem)
fn mul_assign(&mut self, rhs: Elem)
Simple multiplication case by a Baby Bear Elem
source§impl Ord for Elem
impl Ord for Elem
source§impl PartialOrd<Elem> for Elem
impl PartialOrd<Elem> for Elem
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl RootsOfUnity for Elem
impl RootsOfUnity for Elem
source§impl SubAssign<Elem> for Elem
impl SubAssign<Elem> for Elem
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Simple subtraction case for Baby Bear Elem
impl Copy for Elem
impl Eq for Elem
impl Pod for Elem
impl Send for Elem
impl StructuralEq for Elem
impl Sync for Elem
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.