#[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§

Create a new Goldilocks field Elem from a raw integer.

Trait Implementations§

Addition for Goldilocks field Elem

The resulting type after applying the + operator.

Simple addition case for Goldilocks field Elem

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

As a default, return the zero Elem.

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.

Generate a random value within the Goldilocks field

Invalid, a value that is not a member of the field. This should only be used with the “is_valid” or “unwrap_or_zero” methods.
Zero, the additive identity.
One, the multiplicative identity.
How many u32 words are required to hold a single element
Import a number into the field from the natural numbers.
Represent a field element as a sequence of u32s
Interpret a sequence of u32s as a field element
Returns true if this element is not INVALID. Unlike most methods, this may be called on an INVALID element.
Return an element raised to the given power.
Returns 0 if this element is INVALID, else the value of this element. Unlike most methods, this may be called on an INVALID element.
Returns this element, but checks to make sure it’s valid.
Interprets a slice of these elements as u32s. These elements may not be INVALID.
Interprets a slice of these elements as u32s. These elements may potentially be INVALID.
Interprets a slice of u32s as a slice of these elements. These elements may not be INVALID.
Interprets a slice of u32s as a slice of these elements. These elements may be INVALID.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Multiplication for Goldilocks field Elem

The resulting type after applying the * operator.

Multiplication for ExtElem

The resulting type after applying the * operator.

Multiplication of Elem by Goldilocks ExtElem

The resulting type after applying the * operator.

Simple multiplication case for Goldilocks field Elem

Simple multiplication case for Goldilocks ExtElem

Negation for Goldilocks field Elem

The resulting type after applying the - operator.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Maximum power of two for which we have a root of unity using Goldilocks field

‘Forward’ root of unity for each power of two.

‘Reverse’ root of unity for each power of two.

Subtraction for Goldilocks field Elem

The resulting type after applying the - operator.

Simple subtraction case for Goldilocks field Elem

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
If this function returns true, then it must be valid to reinterpret bits as &Self.

Returns the argument unchanged.

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

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more