#[repr(transparent)]pub struct Fp(_);
Expand description
The Fp 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
sourceimpl Fp
impl Fp
sourcepub fn inv(self) -> Self
pub fn inv(self) -> Self
Compute the multiplicative inverse of x
, or 1 / x
in finite field
terms. Since x ^ (P - 1) == 1 % P
for any x != 0
(as a
consequence of Fermat’s little theorem), it follows that x * x ^ (P - 2) == 1 % P
for x != 0
. That is, x ^ (P - 2)
is the
multiplicative inverse of x
. Computed this way, the inverse of
zero comes out as zero, which is convenient in many cases, so we
leave it.
Trait Implementations
sourceimpl AddAssign<Fp> for Fp
impl AddAssign<Fp> for Fp
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the +=
operation. Read more
sourceimpl MulAssign<Fp> for Fp
impl MulAssign<Fp> for Fp
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the *=
operation. Read more
sourceimpl MulAssign<Fp> for Fp4
impl MulAssign<Fp> for Fp4
Implement the simple multiplication case by the subfield Fp.
sourcefn mul_assign(&mut self, rhs: Fp)
fn mul_assign(&mut self, rhs: Fp)
Performs the *=
operation. Read more
sourceimpl PartialOrd<Fp> for Fp
impl PartialOrd<Fp> for Fp
sourcefn partial_cmp(&self, other: &Fp) -> Option<Ordering>
fn partial_cmp(&self, other: &Fp) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SubAssign<Fp> for Fp
impl SubAssign<Fp> for Fp
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -=
operation. Read more
impl Copy for Fp
impl Eq for Fp
impl Pod for Fp
impl StructuralEq for Fp
impl StructuralPartialEq for Fp
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedBitPattern for T where
T: AnyBitPattern,
impl<T> CheckedBitPattern for T where
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
. Read more
sourcefn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret bits
as &Self
.
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more