Struct risc0_zkp::field::goldilocks::Elem
source · #[repr(transparent)]pub struct Elem(_);
Expand description
The Goldilocks class is an element of the finite field F_p, where P is the prime number 2^64 - 2^32 + 1. Here we implement integer arithmetic modulo P for both Goldilocks and for a field extension of Goldilocks.
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 strange architecture,
and its operations as wrapping operations which respect word size P.
The Fp class wraps all standard arithmetic operations to make finite field elements appear like ordinary numbers (which, for the most part, they 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 Goldilocks field 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 Goldilocks field 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 for Goldilocks ExtElem
source§impl PartialEq<Elem> for Elem
impl PartialEq<Elem> for Elem
source§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 Goldilocks field Elem
impl Copy for Elem
impl Eq for Elem
impl Pod for Elem
impl StructuralEq for Elem
impl StructuralPartialEq for Elem
Auto Trait Implementations§
impl RefUnwindSafe for Elem
impl Send for Elem
impl Sync for Elem
impl Unpin for Elem
impl UnwindSafe for Elem
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
.