Struct miden_air::Felt

pub struct Felt(_);
Expand description

Represents base field element in the field using Montgomery representation.

Internal values represent x * R mod M where R = 2^64 mod M and x in [0, M). The backing type is u64 but the internal values are always in the range [0, M).

Implementations§

§

impl BaseElement

pub const fn new(value: u64) -> BaseElement

Creates a new field element from the provided value; the value is converted into Montgomery representation.

pub const fn from_mont(value: u64) -> BaseElement

Returns a new field element from the provided ‘value’. Assumes that ‘value’ is already in canonical Montgomery form.

pub const fn inner(&self) -> u64

Returns the non-canonical u64 inner value.

pub fn exp7(self) -> BaseElement

Computes an exponentiation to the power 7. This is useful for computing Rescue-Prime S-Box over this field.

pub fn mul_small(self, rhs: u32) -> BaseElement

Multiplies an element that is less than 2^32 by a field element. This implementation is faster as it avoids the use of Montgomery reduction.

Trait Implementations§

§

impl Add<BaseElement> for BaseElement

§

type Output = BaseElement

The resulting type after applying the + operator.
§

fn add(self, rhs: BaseElement) -> BaseElement

Performs the + operation. Read more
§

impl AddAssign<BaseElement> for BaseElement

§

fn add_assign(&mut self, rhs: BaseElement)

Performs the += operation. Read more
§

impl AsBytes for BaseElement

§

fn as_bytes(&self) -> &[u8]

Returns a byte representation of self. Read more
§

impl Clone for BaseElement

§

fn clone(&self) -> BaseElement

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for BaseElement

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for BaseElement

§

fn default() -> BaseElement

Returns the “default value” for a type. Read more
§

impl Deserializable for BaseElement

§

fn read_from<R>(source: &mut R) -> Result<BaseElement, DeserializationError>where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
§

fn read_batch_from<R>( source: &mut R, num_elements: usize ) -> Result<Vec<Self, Global>, DeserializationError>where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into a vector with the specified number of Self elements, and returns the result. Read more
§

impl Display for BaseElement

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Div<BaseElement> for BaseElement

§

type Output = BaseElement

The resulting type after applying the / operator.
§

fn div(self, rhs: BaseElement) -> BaseElement

Performs the / operation. Read more
§

impl DivAssign<BaseElement> for BaseElement

§

fn div_assign(&mut self, rhs: BaseElement)

Performs the /= operation. Read more
§

impl ExtensibleField<2> for BaseElement

Defines a quadratic extension of the base field over an irreducible polynomial x2 - x + 2. Thus, an extension element is defined as α + β * φ, where φ is a root of this polynomial, and α and β are base field elements.

§

fn mul(a: [BaseElement; 2], b: [BaseElement; 2]) -> [BaseElement; 2]

Returns a product of a and b in the field defined by this extension.
§

fn square(a: [BaseElement; 2]) -> [BaseElement; 2]

Returns the square of a in the field defined by this extension.
§

fn mul_base(a: [BaseElement; 2], b: BaseElement) -> [BaseElement; 2]

Returns a product of a and b in the field defined by this extension. b represents an element in the base field.
§

fn frobenius(x: [BaseElement; 2]) -> [BaseElement; 2]

Returns Frobenius automorphisms for x in the field defined by this extension.
§

fn is_supported() -> bool

Returns true if this extension is supported for the underlying base field.
§

impl ExtensibleField<3> for BaseElement

Defines a cubic extension of the base field over an irreducible polynomial x3 - x - 1. Thus, an extension element is defined as α + β * φ + γ * φ^2, where φ is a root of this polynomial, and α, β and γ are base field elements.

§

fn mul(a: [BaseElement; 3], b: [BaseElement; 3]) -> [BaseElement; 3]

Returns a product of a and b in the field defined by this extension.
§

fn square(a: [BaseElement; 3]) -> [BaseElement; 3]

Returns the square of a in the field defined by this extension.
§

fn mul_base(a: [BaseElement; 3], b: BaseElement) -> [BaseElement; 3]

Returns a product of a and b in the field defined by this extension. b represents an element in the base field.
§

fn frobenius(x: [BaseElement; 3]) -> [BaseElement; 3]

Returns Frobenius automorphisms for x in the field defined by this extension.
§

fn is_supported() -> bool

Returns true if this extension is supported for the underlying base field.
§

impl FieldElement for BaseElement

§

type PositiveInteger = u64

A type defining positive integers big enough to describe a field modulus for Self::BaseField with no loss of precision.
§

type BaseField = BaseElement

Base field type for this finite field. For prime fields, BaseField should be set to Self.
§

const EXTENSION_DEGREE: usize = 1usize

Extension degree of this field with respect to Self::BaseField. For prime fields, extension degree should be set to 1.
§

const ZERO: BaseElement = Self::new(0)

The additive identity.
§

const ONE: BaseElement = Self::new(1)

The multiplicative identity.
§

const ELEMENT_BYTES: usize = 8usize

Number of bytes needed to encode an element
§

const IS_CANONICAL: bool = false

True if internal representation of the element is the same as its canonical representation.
§

fn double(self) -> BaseElement

Returns this field element added to itself.
§

fn exp( self, power: <BaseElement as FieldElement>::PositiveInteger ) -> BaseElement

Exponentiates this field element by power parameter.
§

fn inv(self) -> BaseElement

Returns a multiplicative inverse of this field element. If this element is ZERO, ZERO is returned.
§

fn conjugate(&self) -> BaseElement

Returns a conjugate of this field element.
§

fn base_element(&self, i: usize) -> <BaseElement as FieldElement>::BaseField

Return base filed element component of this field element at the specified index i. Read more
§

fn slice_as_base_elements( elements: &[BaseElement] ) -> &[<BaseElement as FieldElement>::BaseField]

Converts a slice of field elements into a slice of elements in the underlying base field. Read more
§

fn slice_from_base_elements( elements: &[<BaseElement as FieldElement>::BaseField] ) -> &[BaseElement]

Convert a slice of base field elements into a slice of field elements. Read more
§

fn elements_as_bytes(elements: &[BaseElement]) -> &[u8]

Converts a list of elements into a list of bytes. Read more
§

unsafe fn bytes_as_elements( bytes: &[u8] ) -> Result<&[BaseElement], DeserializationError>

Converts a list of bytes into a list of field elements. Read more
§

fn zeroed_vector(n: usize) -> Vec<BaseElement, Global>

Returns a vector of length n initialized with all ZERO elements. Read more
§

fn square(self) -> Self

Returns this field element raised to power 2.
§

fn cube(self) -> Self

Returns this field element raised to power 3.
§

fn exp_vartime(self, power: Self::PositiveInteger) -> Self

Exponentiates this field element by power parameter. This function is expressly variable time, to speed-up verifier computations.
§

impl From<[u8; 8]> for BaseElement

§

fn from(bytes: [u8; 8]) -> BaseElement

Converts the value encoded in an array of 8 bytes into a field element. The bytes are assumed to encode the element in the canonical representation in little-endian byte order. If the value is greater than or equal to the field modulus, modular reduction is silently performed.

§

impl From<u128> for BaseElement

§

fn from(x: u128) -> BaseElement

Converts a 128-bit value into a field element.

§

impl From<u16> for BaseElement

§

fn from(value: u16) -> BaseElement

Converts a 16-bit value into a field element.

§

impl From<u32> for BaseElement

§

fn from(value: u32) -> BaseElement

Converts a 32-bit value into a field element.

§

impl From<u64> for BaseElement

§

fn from(value: u64) -> BaseElement

Converts a 64-bit value into a field element. If the value is greater than or equal to the field modulus, modular reduction is silently performed.

§

impl From<u8> for BaseElement

§

fn from(value: u8) -> BaseElement

Converts an 8-bit value into a field element.

§

impl Mul<BaseElement> for BaseElement

§

type Output = BaseElement

The resulting type after applying the * operator.
§

fn mul(self, rhs: BaseElement) -> BaseElement

Performs the * operation. Read more
§

impl MulAssign<BaseElement> for BaseElement

§

fn mul_assign(&mut self, rhs: BaseElement)

Performs the *= operation. Read more
§

impl Neg for BaseElement

§

type Output = BaseElement

The resulting type after applying the - operator.
§

fn neg(self) -> BaseElement

Performs the unary - operation. Read more
§

impl PartialEq<BaseElement> for BaseElement

§

fn eq(&self, other: &BaseElement) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Randomizable for BaseElement

§

const VALUE_SIZE: usize = 8usize

Size of Self in bytes. Read more
§

fn from_random_bytes(bytes: &[u8]) -> Option<BaseElement>

Returns Self if the set of bytes forms a valid value, otherwise returns None.
§

impl Serializable for BaseElement

§

fn write_into<W>(&self, target: &mut W)where W: ByteWriter,

Serializes self into bytes and writes these bytes into the target.
§

fn to_bytes(&self) -> Vec<u8, Global>

Serializes self into a vector of bytes.
§

fn write_batch_into<W>(source: &[Self], target: &mut W)where W: ByteWriter,

Serializes all elements of the source and writes these bytes into the target. Read more
§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
§

impl StarkField for BaseElement

§

const MODULUS: <BaseElement as FieldElement>::PositiveInteger = {transmute(0xffffffff00000001): <miden_core::Felt as miden_core::FieldElement>::PositiveInteger}

sage: MODULUS = 2^64 - 2^32 + 1
sage: GF(MODULUS).is_prime_field()
True
sage: GF(MODULUS).order()
18446744069414584321

§

const GENERATOR: BaseElement = Self::new(7)

sage: GF(MODULUS).primitive_element()
7

§

const TWO_ADICITY: u32 = 32u32

sage: is_odd((MODULUS - 1) / 2^32)
True

§

const TWO_ADIC_ROOT_OF_UNITY: BaseElement = Self::new(7277203076849721926)

Root of unity for domain of 2^32 elements. This root of unity is selected because it implies that the generator for domain of size 64 is 8. This is attractive because it allows replacing some multiplications with shifts (e.g., for NTT computations).

sage: Fp = GF(MODULUS)
sage: g = Fp(7277203076849721926)
sage: g^(2^32)
1
sage: [int(g^(2^i) == 1) for i in range(1,32)] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

§

const MODULUS_BITS: u32 = 64u32

The number of bits needed to represents Self::MODULUS.
§

fn get_modulus_le_bytes() -> Vec<u8, Global>

Returns byte representation of the field modulus in little-endian byte order.
§

fn as_int(&self) -> <BaseElement as FieldElement>::PositiveInteger

Returns a canonical integer representation of this field element.
§

fn get_root_of_unity(n: u32) -> Self

Returns the root of unity of order 2^n. Read more
§

impl Sub<BaseElement> for BaseElement

§

type Output = BaseElement

The resulting type after applying the - operator.
§

fn sub(self, rhs: BaseElement) -> BaseElement

Performs the - operation. Read more
§

impl SubAssign<BaseElement> for BaseElement

§

fn sub_assign(&mut self, rhs: BaseElement)

Performs the -= operation. Read more
source§

impl ToElements<BaseElement> for PublicInputs

§

impl<'a> TryFrom<&'a [u8]> for BaseElement

§

fn try_from( bytes: &[u8] ) -> Result<BaseElement, <BaseElement as TryFrom<&'a [u8]>>::Error>

Converts a slice of bytes into a field element; returns error if the value encoded in bytes is not a valid field element. The bytes are assumed to encode the element in the canonical representation in little-endian byte order.

§

type Error = DeserializationError

The type returned in the event of a conversion error.
§

impl Copy for BaseElement

§

impl Eq for BaseElement

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<E> ExtensionOf<E> for Ewhere E: FieldElement,

§

fn mul_base(self, other: E) -> E

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<E> ToElements<E> for Ewhere E: FieldElement,

§

fn to_elements(&self) -> Vec<E, Global>

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.