pub struct FieldElement<F: IsField> { /* private fields */ }
Expand description

A field element with operations algorithms defined in F

Implementations§

source§

impl<F: IsField> FieldElement<F>

source

pub fn inplace_batch_inverse(numbers: &mut [Self])

source§

impl<F> FieldElement<F>where F::BaseType: Clone, F: IsField,

source

pub fn from_raw(value: &F::BaseType) -> Self

source§

impl<F> FieldElement<F>where F: IsField,

FieldElement general implementation Most of this is delegated to the trait F that implements the field operations.

source

pub fn new(value: F::BaseType) -> Self

Creates a field element from value

source

pub fn value(&self) -> &F::BaseType

Returns the underlying value

source

pub fn inv(&self) -> Self

Returns the multiplicative inverse of self

source

pub fn square(&self) -> Self

Returns the square of self

source

pub fn pow<T>(&self, exponent: T) -> Selfwhere T: IsUnsignedInteger,

Returns self raised to the power of exponent

source

pub fn one() -> Self

Returns the multiplicative neutral element of the field.

source

pub fn zero() -> Self

Returns the additive neutral element of the field.

source§

impl<F: IsPrimeField> FieldElement<F>

source§

impl<M, const NUM_LIMBS: usize> FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,

source

pub const fn from_hex_unchecked(hex: &str) -> Self

Creates a FieldElement from a hexstring. It can contain 0x or not.

Panics

Panics if value is not a hexstring

source

pub fn from_hex(hex: &str) -> Result<Self, CreationError>

Creates a FieldElement from a hexstring. It can contain 0x or not. Returns an CreationError::InvalidHexStringif the value is not a hexstring

source§

impl<Q> FieldElement<QuadraticExtensionField<Q>>where Q: Clone + Debug + HasQuadraticNonResidue,

source

pub fn conjugate(&self) -> Self

source§

impl FieldElement<Stark252PrimeField>

source

pub fn to_bytes_le(&self) -> [u8; 32]

No std version of to_bytes_le from ByteConversion trait This follows the convention used by Starkware and Lambdaclass Cairo VM It’s the same as ByteConversion to_bytes_le.

source§

impl FieldElement<BLS12377PrimeField>

source

pub fn new_base(a_hex: &str) -> Self

source§

impl FieldElement<BLS12381PrimeField>

source

pub fn new_base(a_hex: &str) -> Self

source§

impl FieldElement<Degree2ExtensionField>

source

pub fn new_base(a_hex: &str) -> Self

source§

impl FieldElement<Degree6ExtensionField>

source

pub fn new_base(a_hex: &str) -> Self

source§

impl FieldElement<Degree12ExtensionField>

source

pub fn new_base(a_hex: &str) -> Self

source

pub fn from_coefficients(coefficients: &[&str; 12]) -> Self

Trait Implementations§

source§

impl<F> Add<&FieldElement<F>> for &FieldElement<F>where F: IsField,

Addition operator overloading for field elements

§

type Output = FieldElement<F>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &FieldElement<F>) -> Self::Output

Performs the + operation. Read more
source§

impl<F: IsField> Add<&FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F> Add<&FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &FieldElement<F>) -> Self::Output

Performs the + operation. Read more
source§

impl<F: IsField> Add<&FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F: IsField> Add<&Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F> Add<FieldElement<F>> for &FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the + operator.
source§

fn add(self, rhs: FieldElement<F>) -> Self::Output

Performs the + operation. Read more
source§

impl<F: IsField> Add<FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F> Add<FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the + operator.
source§

fn add(self, rhs: FieldElement<F>) -> Self::Output

Performs the + operation. Read more
source§

impl<F: IsField> Add<FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F: IsField> Add<Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F: IsField> Add<Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the + operator.
source§

fn add(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the + operation. Read more
source§

impl<F> AddAssign<FieldElement<F>> for FieldElement<F>where F: IsField,

AddAssign operator overloading for field elements

source§

fn add_assign(&mut self, rhs: FieldElement<F>)

Performs the += operation. Read more
source§

impl ByteConversion for FieldElement<Degree2ExtensionField>

source§

fn to_bytes_be(&self) -> Vec<u8>

Returns the byte representation of the element in big-endian order.}
source§

fn to_bytes_le(&self) -> Vec<u8>

Returns the byte representation of the element in little-endian order.
source§

fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>where Self: Sized,

Returns the element from its byte representation in big-endian order.
source§

fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>where Self: Sized,

Returns the element from its byte representation in little-endian order.
source§

impl<M, const NUM_LIMBS: usize> ByteConversion for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,

source§

fn to_bytes_be(&self) -> Vec<u8>

Returns the byte representation of the element in big-endian order.}
source§

fn to_bytes_le(&self) -> Vec<u8>

Returns the byte representation of the element in little-endian order.
source§

fn from_bytes_be(bytes: &[u8]) -> Result<Self, ByteConversionError>

Returns the element from its byte representation in big-endian order.
source§

fn from_bytes_le(bytes: &[u8]) -> Result<Self, ByteConversionError>

Returns the element from its byte representation in little-endian order.
source§

impl<F: Clone + IsField> Clone for FieldElement<F>where F::BaseType: Clone,

source§

fn clone(&self) -> FieldElement<F>

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
source§

impl<F: Debug + IsField> Debug for FieldElement<F>where F::BaseType: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<F> Default for FieldElement<F>where F: IsField,

source§

fn default() -> Self

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

impl<const MODULUS: u64> Deserializable for FieldElement<U64PrimeField<MODULUS>>

source§

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

source§

impl<M, const NUM_LIMBS: usize> Display for FieldElement<MontgomeryBackendPrimeField<M, NUM_LIMBS>>where M: IsModulus<UnsignedInteger<NUM_LIMBS>> + Clone + Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<F> Div<&FieldElement<F>> for &FieldElement<F>where F: IsField,

Division operator overloading for field elements*/

§

type Output = FieldElement<F>

The resulting type after applying the / operator.
source§

fn div(self, rhs: &FieldElement<F>) -> Self::Output

Performs the / operation. Read more
source§

impl<F> Div<&FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the / operator.
source§

fn div(self, rhs: &FieldElement<F>) -> Self::Output

Performs the / operation. Read more
source§

impl<F> Div<FieldElement<F>> for &FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the / operator.
source§

fn div(self, rhs: FieldElement<F>) -> Self::Output

Performs the / operation. Read more
source§

impl<F> Div<FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the / operator.
source§

fn div(self, rhs: FieldElement<F>) -> Self::Output

Performs the / operation. Read more
source§

impl<F> From<&<F as IsField>::BaseType> for FieldElement<F>where F::BaseType: Clone, F: IsField,

From overloading for field elements

source§

fn from(value: &F::BaseType) -> Self

Converts to this type from the input type.
source§

impl<F> From<u64> for FieldElement<F>where F: IsField,

From overloading for U64

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl<F: Hash + IsField> Hash for FieldElement<F>where F::BaseType: Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<F> Mul<&FieldElement<F>> for &FieldElement<F>where F: IsField,

Multiplication operator overloading for field elements*/

§

type Output = FieldElement<F>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &FieldElement<F>) -> Self::Output

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F> Mul<&FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &FieldElement<F>) -> Self::Output

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: &Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<&Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: &Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F> Mul<FieldElement<F>> for &FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FieldElement<F>) -> Self::Output

Performs the * operation. Read more
source§

impl<F: IsField> Mul<FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F> Mul<FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FieldElement<F>) -> Self::Output

Performs the * operation. Read more
source§

impl<F: IsField> Mul<FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul(self, multiplicand: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F: IsField> Mul<Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the * operator.
source§

fn mul( self, multiplicand: Polynomial<FieldElement<F>> ) -> Polynomial<FieldElement<F>>

Performs the * operation. Read more
source§

impl<F> Neg for &FieldElement<F>where F: IsField,

Negation operator overloading for field elements*/

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<F> Neg for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<F> PartialEq<FieldElement<F>> for FieldElement<F>where F: IsField,

Equality operator overloading for field elements

source§

fn eq(&self, other: &FieldElement<F>) -> 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.
source§

impl<const MODULUS: u64> Serializable for FieldElement<U64PrimeField<MODULUS>>

source§

fn serialize(&self) -> Vec<u8>

Default serialize without args
source§

impl<F> Sub<&FieldElement<F>> for &FieldElement<F>where F: IsField,

Subtraction operator overloading for field elements*/

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &FieldElement<F>) -> Self::Output

Performs the - operation. Read more
source§

impl<F: IsField> Sub<&FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F> Sub<&FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &FieldElement<F>) -> Self::Output

Performs the - operation. Read more
source§

impl<F: IsField> Sub<&FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F: IsField> Sub<&Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F> Sub<FieldElement<F>> for &FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FieldElement<F>) -> Self::Output

Performs the - operation. Read more
source§

impl<F: IsField> Sub<FieldElement<F>> for &Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F> Sub<FieldElement<F>> for FieldElement<F>where F: IsField,

§

type Output = FieldElement<F>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FieldElement<F>) -> Self::Output

Performs the - operation. Read more
source§

impl<F: IsField> Sub<FieldElement<F>> for Polynomial<FieldElement<F>>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: FieldElement<F>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for &FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F: IsField> Sub<Polynomial<FieldElement<F>>> for FieldElement<F>

§

type Output = Polynomial<FieldElement<F>>

The resulting type after applying the - operator.
source§

fn sub(self, other: Polynomial<FieldElement<F>>) -> Polynomial<FieldElement<F>>

Performs the - operation. Read more
source§

impl<F> Sum<FieldElement<F>> for FieldElement<F>where F: IsField,

Sum operator for field elements

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<F> Eq for FieldElement<F>where F: IsField,

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for FieldElement<F>where <F as IsField>::BaseType: RefUnwindSafe,

§

impl<F> Send for FieldElement<F>where <F as IsField>::BaseType: Send,

§

impl<F> Sync for FieldElement<F>where <F as IsField>::BaseType: Sync,

§

impl<F> Unpin for FieldElement<F>

§

impl<F> UnwindSafe for FieldElement<F>where <F as IsField>::BaseType: UnwindSafe,

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
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.
source§

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

Performs the conversion.