pub struct Felt(/* private fields */);
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§
source§impl BaseElement
impl BaseElement
sourcepub const fn new(value: u64) -> BaseElement
pub const fn new(value: u64) -> BaseElement
Creates a new field element from the provided value
; the value is converted into
Montgomery representation.
If the value is greater than or equal to the field modulus, modular reduction is silently performed.
sourcepub const fn from_mont(value: u64) -> BaseElement
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.
sourcepub const fn as_int(&self) -> u64
pub const fn as_int(&self) -> u64
Returns canonical integer representation of this field element.
sourcepub fn exp7(self) -> BaseElement
pub fn exp7(self) -> BaseElement
Computes an exponentiation to the power 7. This is useful for computing Rescue-Prime S-Box over this field.
sourcepub const fn mul_small(self, rhs: u32) -> BaseElement
pub const 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§
source§impl Add for BaseElement
impl Add for BaseElement
source§type Output = BaseElement
type Output = BaseElement
+
operator.source§fn add(self, rhs: BaseElement) -> BaseElement
fn add(self, rhs: BaseElement) -> BaseElement
+
operation. Read moresource§impl AddAssign for BaseElement
impl AddAssign for BaseElement
source§fn add_assign(&mut self, rhs: BaseElement)
fn add_assign(&mut self, rhs: BaseElement)
+=
operation. Read moresource§impl AsBytes for BaseElement
impl AsBytes for BaseElement
source§impl Clone for BaseElement
impl Clone for BaseElement
source§fn clone(&self) -> BaseElement
fn clone(&self) -> BaseElement
1.6.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BaseElement
impl Debug for BaseElement
source§impl Default for BaseElement
impl Default for BaseElement
source§fn default() -> BaseElement
fn default() -> BaseElement
source§impl Deserializable for BaseElement
impl Deserializable for BaseElement
source§fn read_from<R>(source: &mut R) -> Result<BaseElement, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<BaseElement, DeserializationError>where
R: ByteReader,
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl Display for BaseElement
impl Display for BaseElement
source§impl Div for BaseElement
impl Div for BaseElement
source§type Output = BaseElement
type Output = BaseElement
/
operator.source§fn div(self, rhs: BaseElement) -> BaseElement
fn div(self, rhs: BaseElement) -> BaseElement
/
operation. Read moresource§impl DivAssign for BaseElement
impl DivAssign for BaseElement
source§fn div_assign(&mut self, rhs: BaseElement)
fn div_assign(&mut self, rhs: BaseElement)
/=
operation. Read moresource§impl ExtensibleField<2> for BaseElement
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.
source§fn mul(a: [BaseElement; 2], b: [BaseElement; 2]) -> [BaseElement; 2]
fn mul(a: [BaseElement; 2], b: [BaseElement; 2]) -> [BaseElement; 2]
a
and b
in the field defined by this extension.source§fn square(a: [BaseElement; 2]) -> [BaseElement; 2]
fn square(a: [BaseElement; 2]) -> [BaseElement; 2]
a
in the field defined by this extension.source§fn mul_base(a: [BaseElement; 2], b: BaseElement) -> [BaseElement; 2]
fn mul_base(a: [BaseElement; 2], b: BaseElement) -> [BaseElement; 2]
a
and b
in the field defined by this extension. b
represents
an element in the base field.source§fn frobenius(x: [BaseElement; 2]) -> [BaseElement; 2]
fn frobenius(x: [BaseElement; 2]) -> [BaseElement; 2]
x
in the field defined by this extension.source§fn is_supported() -> bool
fn is_supported() -> bool
source§impl ExtensibleField<3> for BaseElement
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.
source§fn mul(a: [BaseElement; 3], b: [BaseElement; 3]) -> [BaseElement; 3]
fn mul(a: [BaseElement; 3], b: [BaseElement; 3]) -> [BaseElement; 3]
a
and b
in the field defined by this extension.source§fn square(a: [BaseElement; 3]) -> [BaseElement; 3]
fn square(a: [BaseElement; 3]) -> [BaseElement; 3]
a
in the field defined by this extension.source§fn mul_base(a: [BaseElement; 3], b: BaseElement) -> [BaseElement; 3]
fn mul_base(a: [BaseElement; 3], b: BaseElement) -> [BaseElement; 3]
a
and b
in the field defined by this extension. b
represents
an element in the base field.source§fn frobenius(x: [BaseElement; 3]) -> [BaseElement; 3]
fn frobenius(x: [BaseElement; 3]) -> [BaseElement; 3]
x
in the field defined by this extension.source§fn is_supported() -> bool
fn is_supported() -> bool
source§impl FieldElement for BaseElement
impl FieldElement for BaseElement
source§const EXTENSION_DEGREE: usize = 1usize
const EXTENSION_DEGREE: usize = 1usize
Self::BaseField
. For prime fields,
extension degree should be set to 1.source§const ZERO: BaseElement = _
const ZERO: BaseElement = _
source§const ONE: BaseElement = _
const ONE: BaseElement = _
source§const ELEMENT_BYTES: usize = 8usize
const ELEMENT_BYTES: usize = 8usize
source§const IS_CANONICAL: bool = false
const IS_CANONICAL: bool = false
source§type PositiveInteger = u64
type PositiveInteger = u64
Self::BaseField
with no loss of precision.source§type BaseField = BaseElement
type BaseField = BaseElement
BaseField
should be set
to Self
.source§fn double(self) -> BaseElement
fn double(self) -> BaseElement
source§fn exp(
self,
power: <BaseElement as FieldElement>::PositiveInteger,
) -> BaseElement
fn exp( self, power: <BaseElement as FieldElement>::PositiveInteger, ) -> BaseElement
power
parameter.source§fn inv(self) -> BaseElement
fn inv(self) -> BaseElement
source§fn conjugate(&self) -> BaseElement
fn conjugate(&self) -> BaseElement
source§fn base_element(&self, i: usize) -> <BaseElement as FieldElement>::BaseField
fn base_element(&self, i: usize) -> <BaseElement as FieldElement>::BaseField
i
. Read moresource§fn slice_as_base_elements(
elements: &[BaseElement],
) -> &[<BaseElement as FieldElement>::BaseField]
fn slice_as_base_elements( elements: &[BaseElement], ) -> &[<BaseElement as FieldElement>::BaseField]
source§fn slice_from_base_elements(
elements: &[<BaseElement as FieldElement>::BaseField],
) -> &[BaseElement]
fn slice_from_base_elements( elements: &[<BaseElement as FieldElement>::BaseField], ) -> &[BaseElement]
source§fn elements_as_bytes(elements: &[BaseElement]) -> &[u8] ⓘ
fn elements_as_bytes(elements: &[BaseElement]) -> &[u8] ⓘ
source§unsafe fn bytes_as_elements(
bytes: &[u8],
) -> Result<&[BaseElement], DeserializationError>
unsafe fn bytes_as_elements( bytes: &[u8], ) -> Result<&[BaseElement], DeserializationError>
source§fn exp_vartime(self, power: Self::PositiveInteger) -> Self
fn exp_vartime(self, power: Self::PositiveInteger) -> Self
power
parameter.
This function is expressly variable time, to speed-up verifier computations.source§impl From<bool> for BaseElement
impl From<bool> for BaseElement
source§fn from(value: bool) -> BaseElement
fn from(value: bool) -> BaseElement
source§impl From<u16> for BaseElement
impl From<u16> for BaseElement
source§fn from(value: u16) -> BaseElement
fn from(value: u16) -> BaseElement
source§impl From<u32> for BaseElement
impl From<u32> for BaseElement
source§fn from(value: u32) -> BaseElement
fn from(value: u32) -> BaseElement
source§impl From<u8> for BaseElement
impl From<u8> for BaseElement
source§fn from(value: u8) -> BaseElement
fn from(value: u8) -> BaseElement
source§impl Mul for BaseElement
impl Mul for BaseElement
source§type Output = BaseElement
type Output = BaseElement
*
operator.source§fn mul(self, rhs: BaseElement) -> BaseElement
fn mul(self, rhs: BaseElement) -> BaseElement
*
operation. Read moresource§impl MulAssign for BaseElement
impl MulAssign for BaseElement
source§fn mul_assign(&mut self, rhs: BaseElement)
fn mul_assign(&mut self, rhs: BaseElement)
*=
operation. Read moresource§impl Neg for BaseElement
impl Neg for BaseElement
source§type Output = BaseElement
type Output = BaseElement
-
operator.source§fn neg(self) -> BaseElement
fn neg(self) -> BaseElement
-
operation. Read moresource§impl PartialEq for BaseElement
impl PartialEq for BaseElement
source§impl Randomizable for BaseElement
impl Randomizable for BaseElement
source§const VALUE_SIZE: usize = 8usize
const VALUE_SIZE: usize = 8usize
Self
in bytes. Read moresource§fn from_random_bytes(bytes: &[u8]) -> Option<BaseElement>
fn from_random_bytes(bytes: &[u8]) -> Option<BaseElement>
Self
if the set of bytes forms a valid value, otherwise returns None.source§impl Serializable for BaseElement
impl Serializable for BaseElement
source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self
into bytes and writes these bytes into the target
.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
source§impl StarkField for BaseElement
impl StarkField for BaseElement
source§const MODULUS: <BaseElement as FieldElement>::PositiveInteger = {transmute(0xffffffff00000001): <winter_math::fields::f64::BaseElement as winter_math::FieldElement>::PositiveInteger}
const MODULUS: <BaseElement as FieldElement>::PositiveInteger = {transmute(0xffffffff00000001): <winter_math::fields::f64::BaseElement as winter_math::FieldElement>::PositiveInteger}
sage: MODULUS = 2^64 - 2^32 + 1
sage: GF(MODULUS).is_prime_field()
True
sage: GF(MODULUS).order()
18446744069414584321
source§const GENERATOR: BaseElement = _
const GENERATOR: BaseElement = _
sage: GF(MODULUS).primitive_element()
7
source§const TWO_ADICITY: u32 = 32u32
const TWO_ADICITY: u32 = 32u32
sage: is_odd((MODULUS - 1) / 2^32)
True
source§const TWO_ADIC_ROOT_OF_UNITY: BaseElement = _
const TWO_ADIC_ROOT_OF_UNITY: BaseElement = _
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]
source§const MODULUS_BITS: u32 = 64u32
const MODULUS_BITS: u32 = 64u32
Self::MODULUS
.source§fn get_modulus_le_bytes() -> Vec<u8> ⓘ
fn get_modulus_le_bytes() -> Vec<u8> ⓘ
source§fn as_int(&self) -> <BaseElement as FieldElement>::PositiveInteger
fn as_int(&self) -> <BaseElement as FieldElement>::PositiveInteger
source§fn get_root_of_unity(n: u32) -> Self
fn get_root_of_unity(n: u32) -> Self
n
. Read moresource§fn from_bytes_with_padding(bytes: &[u8]) -> Self
fn from_bytes_with_padding(bytes: &[u8]) -> Self
source§impl Sub for BaseElement
impl Sub for BaseElement
source§type Output = BaseElement
type Output = BaseElement
-
operator.source§fn sub(self, rhs: BaseElement) -> BaseElement
fn sub(self, rhs: BaseElement) -> BaseElement
-
operation. Read moresource§impl SubAssign for BaseElement
impl SubAssign for BaseElement
source§fn sub_assign(&mut self, rhs: BaseElement)
fn sub_assign(&mut self, rhs: BaseElement)
-=
operation. Read moresource§impl<'a> TryFrom<&'a [u8]> for BaseElement
impl<'a> TryFrom<&'a [u8]> for BaseElement
source§fn try_from(
bytes: &[u8],
) -> Result<BaseElement, <BaseElement as TryFrom<&'a [u8]>>::Error>
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.
source§type Error = DeserializationError
type Error = DeserializationError
source§impl TryFrom<u128> for BaseElement
impl TryFrom<u128> for BaseElement
source§impl TryFrom<u64> for BaseElement
impl TryFrom<u64> for BaseElement
source§impl TryFrom<usize> for BaseElement
impl TryFrom<usize> for BaseElement
impl Copy for BaseElement
impl Eq for BaseElement
Auto Trait Implementations§
impl Freeze for BaseElement
impl RefUnwindSafe for BaseElement
impl Send for BaseElement
impl Sync for BaseElement
impl Unpin for BaseElement
impl UnwindSafe for BaseElement
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)