pub struct Fp(/* private fields */);
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§
Source§impl 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§
Source§impl AddAssign for Fp
impl AddAssign for Fp
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl MulAssign<Fp> for Fp4
Implement the simple multiplication case by the subfield Fp.
impl MulAssign<Fp> for Fp4
Implement the simple multiplication case by the subfield Fp.
Source§fn mul_assign(&mut self, rhs: Fp)
fn mul_assign(&mut self, rhs: Fp)
*=
operation. Read moreSource§impl MulAssign for Fp
impl MulAssign for Fp
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl PartialOrd for Fp
impl PartialOrd for Fp
Source§impl SubAssign for Fp
impl SubAssign for Fp
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moreimpl Copy for Fp
impl Eq for Fp
impl Pod for Fp
impl StructuralPartialEq for Fp
Auto Trait Implementations§
impl Freeze for Fp
impl RefUnwindSafe for Fp
impl Send for Fp
impl Sync for Fp
impl Unpin for Fp
impl UnwindSafe for Fp
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
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§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
.