pub struct Felt(/* private fields */);
Expand description
Definition of the Field Element type.
Implementations§
Source§impl Felt
impl Felt
Sourcepub const ELEMENT_UPPER_BOUND: Felt
pub const ELEMENT_UPPER_BOUND: Felt
2 ** 251
Sourcepub const fn from_raw(val: [u64; 4]) -> Felt
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.
pub const fn from_hex_unchecked(val: &str) -> Felt
Sourcepub fn from_bytes_be(bytes: &[u8; 32]) -> Felt
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.
Sourcepub fn from_bytes_le(bytes: &[u8; 32]) -> Felt
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.
Sourcepub fn from_bytes_be_slice(bytes: &[u8]) -> Felt
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.
Sourcepub fn from_bytes_le_slice(bytes: &[u8]) -> Felt
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.
Sourcepub fn to_bytes_be(&self) -> [u8; 32]
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
Sourcepub fn to_bytes_le(&self) -> [u8; 32]
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
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Helper to produce a hexadecimal formatted string.
Equivalent to calling format!("{self:#x}")
.
Sourcepub fn to_fixed_hex_string(&self) -> String
pub fn to_fixed_hex_string(&self) -> String
Helper to produce a hexadecimal formatted string of 66 chars.
Sourcepub fn to_bits_le(&self) -> [bool; 256]
pub fn to_bits_le(&self) -> [bool; 256]
Converts to little-endian bit representation.
Sourcepub fn to_bits_be(&self) -> [bool; 256]
pub fn to_bits_be(&self) -> [bool; 256]
Converts to big-endian bit representation.
Sourcepub fn field_div(&self, rhs: &NonZeroFelt) -> Felt
pub fn field_div(&self, rhs: &NonZeroFelt) -> Felt
Finite field division.
Sourcepub fn floor_div(&self, rhs: &NonZeroFelt) -> Felt
pub fn floor_div(&self, rhs: &NonZeroFelt) -> Felt
Truncated quotient between self
and rhs
.
Sourcepub fn div_rem(&self, rhs: &NonZeroFelt) -> (Felt, Felt)
pub fn div_rem(&self, rhs: &NonZeroFelt) -> (Felt, Felt)
Quotient and remainder between self
and rhs
.
Sourcepub fn sqrt(&self) -> Option<Felt>
pub fn sqrt(&self) -> Option<Felt>
Finds the square root. There may be 2 roots for each square, and the lower one is returned.
Sourcepub fn mul_mod(&self, rhs: &Felt, p: &NonZeroFelt) -> Felt
pub fn mul_mod(&self, rhs: &Felt, p: &NonZeroFelt) -> Felt
Modular multiplication between self
and rhs
in modulo p
.
Sourcepub fn mod_inverse(&self, p: &NonZeroFelt) -> Option<Felt>
pub fn mod_inverse(&self, p: &NonZeroFelt) -> Option<Felt>
Multiplicative inverse of self
in modulo p
.
Sourcepub fn mod_floor(&self, n: &NonZeroFelt) -> Felt
pub fn mod_floor(&self, n: &NonZeroFelt) -> Felt
Remainder of dividing self
by n
as integers.
Sourcepub fn from_hex(hex_string: &str) -> Result<Felt, FromStrError>
pub fn from_hex(hex_string: &str) -> Result<Felt, FromStrError>
Parse a hex-encoded number into Felt
.
Sourcepub fn from_dec_str(dec_string: &str) -> Result<Felt, FromStrError>
pub fn from_dec_str(dec_string: &str) -> Result<Felt, FromStrError>
Parse a decimal-encoded number into Felt
.
Sourcepub fn to_raw_reversed(&self) -> [u64; 4]
pub fn to_raw_reversed(&self) -> [u64; 4]
Returns the internal representation of a felt and reverses it to match starknet-rs mont representation
Sourcepub fn to_le_digits(&self) -> [u64; 4]
pub fn to_le_digits(&self) -> [u64; 4]
Convert self
’s representative into an array of u64
digits,
least significant digits first.
Sourcepub fn to_be_digits(&self) -> [u64; 4]
pub fn to_be_digits(&self) -> [u64; 4]
Convert self
’s representative into an array of u64
digits,
most significant digits first.
Sourcepub fn bits(&self) -> usize
pub fn bits(&self) -> usize
Count the minimum number of bits needed to express self
’s representative.
pub fn to_biguint(&self) -> BigUint
pub fn to_bigint(&self) -> BigInt
Trait Implementations§
Source§impl AddAssign<&Felt> for Felt
Field addition. Never overflows/underflows.
impl AddAssign<&Felt> for Felt
Field addition. Never overflows/underflows.
Source§fn add_assign(&mut self, rhs: &Felt)
fn add_assign(&mut self, rhs: &Felt)
+=
operation. Read moreSource§impl AddAssign for Felt
Field addition. Never overflows/underflows.
impl AddAssign for Felt
Field addition. Never overflows/underflows.
Source§fn add_assign(&mut self, rhs: Felt)
fn add_assign(&mut self, rhs: Felt)
+=
operation. Read moreSource§impl Default for Felt
Defaults to Felt::ZERO.
impl Default for Felt
Defaults to Felt::ZERO.
Source§impl From<&NonZeroFelt> for Felt
impl From<&NonZeroFelt> for Felt
Source§fn from(value: &NonZeroFelt) -> Felt
fn from(value: &NonZeroFelt) -> Felt
Source§impl From<NonZeroFelt> for Felt
impl From<NonZeroFelt> for Felt
Source§fn from(value: NonZeroFelt) -> Felt
fn from(value: NonZeroFelt) -> Felt
Source§impl MulAssign<&Felt> for Felt
Field multiplication. Never overflows/underflows.
impl MulAssign<&Felt> for Felt
Field multiplication. Never overflows/underflows.
Source§fn mul_assign(&mut self, rhs: &Felt)
fn mul_assign(&mut self, rhs: &Felt)
*=
operation. Read moreSource§impl MulAssign for Felt
Field multiplication. Never overflows/underflows.
impl MulAssign for Felt
Field multiplication. Never overflows/underflows.
Source§fn mul_assign(&mut self, rhs: Felt)
fn mul_assign(&mut self, rhs: Felt)
*=
operation. Read moreSource§impl Ord for Felt
impl Ord for Felt
Source§impl PartialOrd for Felt
impl PartialOrd for Felt
Source§impl SubAssign<&Felt> for Felt
Field subtraction. Never overflows/underflows.
impl SubAssign<&Felt> for Felt
Field subtraction. Never overflows/underflows.
Source§fn sub_assign(&mut self, rhs: &Felt)
fn sub_assign(&mut self, rhs: &Felt)
-=
operation. Read moreSource§impl SubAssign for Felt
Field subtraction. Never overflows/underflows.
impl SubAssign for Felt
Field subtraction. Never overflows/underflows.
Source§fn sub_assign(&mut self, rhs: Felt)
fn sub_assign(&mut self, rhs: Felt)
-=
operation. Read more