Felt

Struct Felt 

Source
pub struct Felt(/* private fields */);
Expand description

Definition of the Field Element type.

Implementations§

Source§

impl Felt

Source

pub fn to_hex_string(&self) -> String

Helper to represent the felt value as a zero-padded hexadecimal string.

Equivalent to calling format!("{self:#x}").

Source

pub fn to_fixed_hex_string(&self) -> String

Helper to represent the felt value as a zero-padded hexadecimal string.

The resulting string will consist of:

  1. A0x prefix,
  2. an amount of padding zeros so that the resulting string length is fixed (This amount may be 0),
  3. the felt value represented in hexadecimal

The resulting string is guaranted to be 66 chars long, which is enough to represent Felt::MAX: 2 chars for the 0x prefix and 64 chars for the padded hexadecimal felt value.

Source§

impl Felt

Source

pub const ZERO: Felt

Felt constant that’s equal to 0.

Source

pub const ONE: Felt

Felt constant that’s equal to 1.

Source

pub const TWO: Felt

Felt constant that’s equal to 2.

Source

pub const THREE: Felt

Felt constant that’s equal to 3.

Source

pub const MAX: Felt

Maximum value of Felt. Equals to 2^251 + 17 * 2^192.

Source

pub const ELEMENT_UPPER_BOUND: Felt

2 ** 251

Source

pub const fn from_raw(val: [u64; 4]) -> Felt

Creates a new Felt from the raw internal representation. See UnsignedInteger to understand how it works under the hood.

Source

pub const fn from_hex_unchecked(val: &str) -> Felt

Source

pub fn from_bytes_be(bytes: &[u8; 32]) -> Felt

Creates a new Felt from its big-endian representation in a [u8; 32] array. This is as performant as from_bytes_le.

Source

pub fn from_bytes_le(bytes: &[u8; 32]) -> Felt

Creates a new Felt from its little-endian representation in a [u8; 32] array. This is as performant as from_bytes_le.

Source

pub fn from_bytes_be_slice(bytes: &[u8]) -> Felt

Creates a new Felt from its big-endian representation in a u8 slice. This is as performant as from_bytes_le. All bytes in the slice are consumed, as if first creating a big integer from them, but the conversion is performed in constant space on the stack.

Source

pub fn from_bytes_le_slice(bytes: &[u8]) -> Felt

Creates a new Felt from its little-endian representation in a u8 slice. This is as performant as from_bytes_be. All bytes in the slice are consumed, as if first creating a big integer from them, but the conversion is performed in constant space on the stack.

Source

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

Converts to big-endian byte representation in a u8 array. This is as performant as to_bytes_le

Source

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

Converts to little-endian byte representation in a u8 array. This is as performant as to_bytes_be

Source

pub fn to_bits_le(&self) -> [bool; 256]

Converts to little-endian bit representation.

Source

pub fn to_bits_be(&self) -> [bool; 256]

Converts to big-endian bit representation.

Source

pub fn field_div(&self, rhs: &NonZeroFelt) -> Felt

Finite field division.

Source

pub fn floor_div(&self, rhs: &NonZeroFelt) -> Felt

Truncated quotient between self and rhs.

Source

pub fn div_rem(&self, rhs: &NonZeroFelt) -> (Felt, Felt)

Quotient and remainder between self and rhs.

Source

pub fn inverse(&self) -> Option<Felt>

Multiplicative inverse inside field.

Source

pub fn sqrt(&self) -> Option<Felt>

Finds the square root. There may be 2 roots for each square, and the lower one is returned.

Source

pub fn square(&self) -> Felt

Raises self to the power of 2.

Source

pub fn double(&self) -> Felt

Doubles the point self

Source

pub fn pow(&self, exponent: impl Into<u128>) -> Felt

Raises self to the power of exponent.

Source

pub fn pow_felt(&self, exponent: &Felt) -> Felt

Raises self to the power of exponent.

Source

pub fn mul_mod(&self, rhs: &Felt, p: &NonZeroFelt) -> Felt

Modular multiplication between self and rhs in modulo p.

Source

pub fn mod_inverse(&self, p: &NonZeroFelt) -> Option<Felt>

Multiplicative inverse of self in modulo p.

Source

pub fn mod_floor(&self, n: &NonZeroFelt) -> Felt

Remainder of dividing self by n as integers.

Source

pub fn from_hex(hex_string: &str) -> Result<Felt, FromStrError>

Parse a hex-encoded number into Felt.

Source

pub fn from_dec_str(dec_string: &str) -> Result<Felt, FromStrError>

Parse a decimal-encoded number into Felt.

Source

pub fn to_raw_reversed(&self) -> [u64; 4]

Returns the internal representation of a felt and reverses it to match starknet-rs mont representation

Source

pub fn to_raw(&self) -> [u64; 4]

Returns the internal representation of a felt

Source

pub fn to_le_digits(&self) -> [u64; 4]

Convert self’s representative into an array of u64 digits, least significant digits first.

Source

pub fn to_be_digits(&self) -> [u64; 4]

Convert self’s representative into an array of u64 digits, most significant digits first.

Source

pub fn bits(&self) -> usize

Count the minimum number of bits needed to express self’s representative.

Source

pub fn to_biguint(&self) -> BigUint

Source

pub fn to_bigint(&self) -> BigInt

Source§

impl Felt

Source

pub fn parse_cairo_short_string( string: &str, ) -> Result<Felt, TryShortStringFromStringError>

Create a felt value from a cairo short string.

The string must contains only ascii characters and its length must not exceed 31.

The returned felt value be that of the input raw bytes.

Trait Implementations§

Source§

impl Add<&Felt> for &Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Felt) -> <&Felt as Add<&Felt>>::Output

Performs the + operation. Read more
Source§

impl Add<&Felt> for Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Felt) -> <Felt as Add<&Felt>>::Output

Performs the + operation. Read more
Source§

impl Add<Felt> for &Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Felt) -> <&Felt as Add<Felt>>::Output

Performs the + operation. Read more
Source§

impl Add<u64> for &Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u64) -> <&Felt as Add<u64>>::Output

Performs the + operation. Read more
Source§

impl Add<u64> for Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: u64) -> <Felt as Add<u64>>::Output

Performs the + operation. Read more
Source§

impl Add for Felt

Field addition. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Felt) -> <Felt as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign<&Felt> for Felt

Field addition. Never overflows/underflows.

Source§

fn add_assign(&mut self, rhs: &Felt)

Performs the += operation. Read more
Source§

impl AddAssign for Felt

Field addition. Never overflows/underflows.

Source§

fn add_assign(&mut self, rhs: Felt)

Performs the += operation. Read more
Source§

impl AsRef<Felt> for Felt

Source§

fn as_ref(&self) -> &Felt

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Felt

Source§

fn clone(&self) -> Felt

Returns a duplicate 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 Debug for Felt

Source§

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

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

impl Default for Felt

Defaults to Felt::ZERO.

Source§

fn default() -> Felt

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

impl Display for Felt

Represents Felt in decimal by default.

Source§

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

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

impl From<&BigInt> for Felt

Source§

fn from(bigint: &BigInt) -> Felt

Converts to this type from the input type.
Source§

impl From<&BigUint> for Felt

Source§

fn from(biguint: &BigUint) -> Felt

Converts to this type from the input type.
Source§

impl From<&NonZeroFelt> for Felt

Source§

fn from(value: &NonZeroFelt) -> Felt

Converts to this type from the input type.
Source§

impl From<BigInt> for Felt

Source§

fn from(bigint: BigInt) -> Felt

Converts to this type from the input type.
Source§

impl From<BigUint> for Felt

Source§

fn from(biguint: BigUint) -> Felt

Converts to this type from the input type.
Source§

impl From<NonZeroFelt> for Felt

Source§

fn from(value: NonZeroFelt) -> Felt

Converts to this type from the input type.
Source§

impl From<ShortString> for Felt

Source§

fn from(ss: ShortString) -> Felt

Converts to this type from the input type.
Source§

impl From<bool> for Felt

Source§

fn from(value: bool) -> Felt

Converts to this type from the input type.
Source§

impl From<i128> for Felt

Source§

fn from(value: i128) -> Felt

Converts to this type from the input type.
Source§

impl From<i16> for Felt

Source§

fn from(value: i16) -> Felt

Converts to this type from the input type.
Source§

impl From<i32> for Felt

Source§

fn from(value: i32) -> Felt

Converts to this type from the input type.
Source§

impl From<i64> for Felt

Source§

fn from(value: i64) -> Felt

Converts to this type from the input type.
Source§

impl From<i8> for Felt

Source§

fn from(value: i8) -> Felt

Converts to this type from the input type.
Source§

impl From<isize> for Felt

Source§

fn from(value: isize) -> Felt

Converts to this type from the input type.
Source§

impl From<u128> for Felt

Source§

fn from(value: u128) -> Felt

Converts to this type from the input type.
Source§

impl From<u16> for Felt

Source§

fn from(value: u16) -> Felt

Converts to this type from the input type.
Source§

impl From<u32> for Felt

Source§

fn from(value: u32) -> Felt

Converts to this type from the input type.
Source§

impl From<u64> for Felt

Source§

fn from(value: u64) -> Felt

Converts to this type from the input type.
Source§

impl From<u8> for Felt

Source§

fn from(value: u8) -> Felt

Converts to this type from the input type.
Source§

impl From<usize> for Felt

Source§

fn from(value: usize) -> Felt

Converts to this type from the input type.
Source§

impl FromStr for Felt

Source§

fn from_str(s: &str) -> Result<Felt, <Felt as FromStr>::Err>

Converts a hex (0x-prefixed) or decimal string to a Felt. e.g., ‘0x123abc’ or ‘1337’.

Source§

type Err = FromStrError

The associated error which can be returned from parsing.
Source§

impl Hash for Felt

Source§

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

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 LowerHex for Felt

Represents Felt in lowercase hexadecimal format.

Source§

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

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

impl Mul<&Felt> for &Felt

Field multiplication. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Felt) -> <&Felt as Mul<&Felt>>::Output

Performs the * operation. Read more
Source§

impl Mul<&Felt> for Felt

Field multiplication. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Felt) -> <Felt as Mul<&Felt>>::Output

Performs the * operation. Read more
Source§

impl Mul<Felt> for &Felt

Field multiplication. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Felt) -> <&Felt as Mul<Felt>>::Output

Performs the * operation. Read more
Source§

impl Mul for Felt

Field multiplication. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Felt) -> <Felt as Mul>::Output

Performs the * operation. Read more
Source§

impl MulAssign<&Felt> for Felt

Field multiplication. Never overflows/underflows.

Source§

fn mul_assign(&mut self, rhs: &Felt)

Performs the *= operation. Read more
Source§

impl MulAssign for Felt

Field multiplication. Never overflows/underflows.

Source§

fn mul_assign(&mut self, rhs: Felt)

Performs the *= operation. Read more
Source§

impl Neg for &Felt

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn neg(self) -> <&Felt as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Neg for Felt

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Felt as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Ord for Felt

Source§

fn cmp(&self, other: &Felt) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Felt

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl PartialOrd for Felt

Source§

fn partial_cmp(&self, other: &Felt) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<&Felt> for &Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Felt) -> <&Felt as Sub<&Felt>>::Output

Performs the - operation. Read more
Source§

impl Sub<&Felt> for Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Felt) -> <Felt as Sub<&Felt>>::Output

Performs the - operation. Read more
Source§

impl Sub<Felt> for &Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Felt) -> <&Felt as Sub<Felt>>::Output

Performs the - operation. Read more
Source§

impl Sub<u64> for &Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u64) -> <&Felt as Sub<u64>>::Output

Performs the - operation. Read more
Source§

impl Sub<u64> for Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: u64) -> <Felt as Sub<u64>>::Output

Performs the - operation. Read more
Source§

impl Sub for Felt

Field subtraction. Never overflows/underflows.

Source§

type Output = Felt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Felt) -> <Felt as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign<&Felt> for Felt

Field subtraction. Never overflows/underflows.

Source§

fn sub_assign(&mut self, rhs: &Felt)

Performs the -= operation. Read more
Source§

impl SubAssign for Felt

Field subtraction. Never overflows/underflows.

Source§

fn sub_assign(&mut self, rhs: Felt)

Performs the -= operation. Read more
Source§

impl<'a> Sum<&'a Felt> for Felt

Source§

fn sum<I>(iter: I) -> Felt
where I: Iterator<Item = &'a Felt>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for Felt

Source§

fn sum<I>(iter: I) -> Felt
where I: Iterator<Item = Felt>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl UpperHex for Felt

Represents Felt in uppercase hexadecimal format.

Source§

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

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

impl Copy for Felt

Source§

impl Eq for Felt

Source§

impl StructuralPartialEq for Felt

Auto Trait Implementations§

§

impl Freeze for Felt

§

impl RefUnwindSafe for Felt

§

impl Send for Felt

§

impl Sync for Felt

§

impl Unpin for Felt

§

impl UnwindSafe for Felt

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.