../../.cargo/katex-header.html

Trait winter_math::FieldElement

source ·
pub trait FieldElement: Copy + Clone + Debug + Display + Default + Send + Sync + Eq + PartialEq + Sized + Add<Self, Output = Self> + Sub<Self, Output = Self> + Mul<Self, Output = Self> + Div<Self, Output = Self> + AddAssign<Self> + SubAssign<Self> + MulAssign<Self> + DivAssign<Self> + Neg<Output = Self> + From<u32> + From<u16> + From<u8> + TryFrom<u64> + TryFrom<u128> + for<'a> TryFrom<&'a [u8]> + ExtensionOf<Self::BaseField> + AsBytes + Randomizable + Serializable + Deserializable {
    type PositiveInteger: Debug + Copy + PartialEq + PartialOrd + ShrAssign + Shl<u32, Output = Self::PositiveInteger> + Shr<u32, Output = Self::PositiveInteger> + BitAnd<Output = Self::PositiveInteger> + From<u32> + From<u64>;
    type BaseField: StarkField;

    const EXTENSION_DEGREE: usize;
    const ELEMENT_BYTES: usize;
    const IS_CANONICAL: bool;
    const ZERO: Self;
    const ONE: Self;

    // Required methods
    fn inv(self) -> Self;
    fn conjugate(&self) -> Self;
    fn base_element(&self, i: usize) -> Self::BaseField;
    fn slice_as_base_elements(elements: &[Self]) -> &[Self::BaseField];
    fn slice_from_base_elements(elements: &[Self::BaseField]) -> &[Self];
    fn elements_as_bytes(elements: &[Self]) -> &[u8] ;
    unsafe fn bytes_as_elements(
        bytes: &[u8]
    ) -> Result<&[Self], DeserializationError>;

    // Provided methods
    fn double(self) -> Self { ... }
    fn square(self) -> Self { ... }
    fn cube(self) -> Self { ... }
    fn exp(self, power: Self::PositiveInteger) -> Self { ... }
    fn exp_vartime(self, power: Self::PositiveInteger) -> Self { ... }
}
Expand description

Defines an element in a finite field.

This trait defines basic arithmetic operations for elements in finite fields (e.g. addition subtraction, multiplication, division) as well as several convenience functions (e.g. double, square cube). Moreover, it defines interfaces for serializing and deserializing field elements.

The elements could be in a prime field or an extension of a prime field. Currently, only quadratic and cubic field extensions are supported.

Required Associated Types§

source

type PositiveInteger: Debug + Copy + PartialEq + PartialOrd + ShrAssign + Shl<u32, Output = Self::PositiveInteger> + Shr<u32, Output = Self::PositiveInteger> + BitAnd<Output = Self::PositiveInteger> + From<u32> + From<u64>

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

source

type BaseField: StarkField

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

Required Associated Constants§

source

const EXTENSION_DEGREE: usize

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

source

const ELEMENT_BYTES: usize

Number of bytes needed to encode an element

source

const IS_CANONICAL: bool

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

source

const ZERO: Self

The additive identity.

source

const ONE: Self

The multiplicative identity.

Required Methods§

source

fn inv(self) -> Self

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

source

fn conjugate(&self) -> Self

Returns a conjugate of this field element.

source

fn base_element(&self, i: usize) -> Self::BaseField

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

§Panics

Panics if the specified index is greater than or equal to Self::EXTENSION_DEGREE.

source

fn slice_as_base_elements(elements: &[Self]) -> &[Self::BaseField]

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

For base STARK fields, the input and output slices are the same. For extension fields, the output slice will contain decompositions of each extension element into underlying base field elements.

source

fn slice_from_base_elements(elements: &[Self::BaseField]) -> &[Self]

Convert a slice of base field elements into a slice of field elements.

For base STARK fields, the input and output slices are the same. For extension fields, the output slice will contain a composition of base field elements into extension field elements.

§Panics

Panics if the the length of the provided slice is not divisible by Self::EXTENSION_DEGREE.

source

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

Converts a list of elements into a list of bytes.

The elements may be in the internal representation rather than in the canonical representation. This conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).

source

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

Converts a list of bytes into a list of field elements.

The elements are assumed to encoded in the internal representation rather than in the canonical representation. The conversion is intended to be zero-copy (i.e. by re-interpreting the underlying memory).

§Errors

An error is returned if:

  • Memory alignment of bytes does not match memory alignment of field element data.
  • Length of bytes does not divide into whole number of elements.
§Safety

This function is unsafe because it does not check whether underlying bytes represent valid field elements according to their internal representation.

Provided Methods§

source

fn double(self) -> Self

Returns this field element added to itself.

source

fn square(self) -> Self

Returns this field element raised to power 2.

source

fn cube(self) -> Self

Returns this field element raised to power 3.

source

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

Exponentiates this field element by power parameter.

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl FieldElement for winter_math::fields::f62::BaseElement

§

type PositiveInteger = u64

§

type BaseField = BaseElement

source§

const EXTENSION_DEGREE: usize = 1usize

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const ELEMENT_BYTES: usize = 8usize

source§

const IS_CANONICAL: bool = false

source§

impl FieldElement for winter_math::fields::f64::BaseElement

§

type PositiveInteger = u64

§

type BaseField = BaseElement

source§

const EXTENSION_DEGREE: usize = 1usize

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const ELEMENT_BYTES: usize = 8usize

source§

const IS_CANONICAL: bool = false

source§

impl FieldElement for winter_math::fields::f128::BaseElement

§

type PositiveInteger = u128

§

type BaseField = BaseElement

source§

const EXTENSION_DEGREE: usize = 1usize

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const ELEMENT_BYTES: usize = 16usize

source§

const IS_CANONICAL: bool = true

source§

impl<B: ExtensibleField<2>> FieldElement for QuadExtension<B>

§

type PositiveInteger = <B as FieldElement>::PositiveInteger

§

type BaseField = B

source§

const EXTENSION_DEGREE: usize = 2usize

source§

const ELEMENT_BYTES: usize = _

source§

const IS_CANONICAL: bool = B::IS_CANONICAL

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

impl<B: ExtensibleField<3>> FieldElement for CubeExtension<B>

§

type PositiveInteger = <B as FieldElement>::PositiveInteger

§

type BaseField = B

source§

const EXTENSION_DEGREE: usize = 3usize

source§

const ELEMENT_BYTES: usize = _

source§

const IS_CANONICAL: bool = B::IS_CANONICAL

source§

const ZERO: Self = _

source§

const ONE: Self = _