Struct risc0_zkp::field::baby_bear::Elem

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

Create a new BabyBear from a raw integer.

Return the Montgomery form representation used for byte-based hashes of slices of BabyBears.

Trait Implementations§

Addition for Baby Bear Elem

The resulting type after applying the + operator.

Simple addition case for Baby Bear 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
Returns the “default value” for a type. Read more

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 Baby Bear 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.
Converts to this type from the input type.
Converts to this type from the input type.

Multiplication for Baby Bear Elem

The resulting type after applying the * operator.

Multiplication by a Baby Bear Elem

The resulting type after applying the * operator.

Multiplication for a subfield Elem by an ExtElem

The resulting type after applying the * operator.

Simple multiplication case for Baby Bear Elem

Simple multiplication case by a Baby Bear Elem

The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
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.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

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

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

Subtraction for Baby Bear Elem

The resulting type after applying the - operator.

Simple subtraction case for Baby Bear 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