halo2_axiom::arithmetic

Trait Field

Source
pub trait Field:
    Sized
    + Eq
    + Copy
    + Clone
    + Default
    + Send
    + Sync
    + Debug
    + 'static
    + ConditionallySelectable
    + ConstantTimeEq
    + Neg<Output = Self>
    + Add<Output = Self, Output = Self>
    + Sub<Output = Self, Output = Self>
    + Mul<Output = Self, Output = Self>
    + Sum
    + Product
    + for<'a> Add<&'a Self>
    + for<'a> Sub<&'a Self>
    + for<'a> Mul<&'a Self>
    + for<'a> Sum<&'a Self>
    + for<'a> Product<&'a Self>
    + AddAssign
    + SubAssign
    + MulAssign
    + for<'a> AddAssign<&'a Self>
    + for<'a> SubAssign<&'a Self>
    + for<'a> MulAssign<&'a Self> {
    const ZERO: Self;
    const ONE: Self;

    // Required methods
    fn random(rng: impl RngCore) -> Self;
    fn square(&self) -> Self;
    fn double(&self) -> Self;
    fn invert(&self) -> CtOption<Self>;
    fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self);

    // Provided methods
    fn is_zero(&self) -> Choice { ... }
    fn is_zero_vartime(&self) -> bool { ... }
    fn cube(&self) -> Self { ... }
    fn sqrt_alt(&self) -> (Choice, Self) { ... }
    fn sqrt(&self) -> CtOption<Self> { ... }
    fn pow<S>(&self, exp: S) -> Self
       where S: AsRef<[u64]> { ... }
    fn pow_vartime<S>(&self, exp: S) -> Self
       where S: AsRef<[u64]> { ... }
}
Expand description

This trait represents an element of a field.

Required Associated Constants§

Source

const ZERO: Self

The zero element of the field, the additive identity.

Source

const ONE: Self

The one element of the field, the multiplicative identity.

Required Methods§

Source

fn random(rng: impl RngCore) -> Self

Returns an element chosen uniformly at random using a user-provided RNG.

Source

fn square(&self) -> Self

Squares this element.

Source

fn double(&self) -> Self

Doubles this element.

Source

fn invert(&self) -> CtOption<Self>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source

fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)

Computes:

  • $(\textsf{true}, \sqrt{\textsf{num}/\textsf{div}})$, if $\textsf{num}$ and $\textsf{div}$ are nonzero and $\textsf{num}/\textsf{div}$ is a square in the field;
  • $(\textsf{true}, 0)$, if $\textsf{num}$ is zero;
  • $(\textsf{false}, 0)$, if $\textsf{num}$ is nonzero and $\textsf{div}$ is zero;
  • $(\textsf{false}, \sqrt{G_S \cdot \textsf{num}/\textsf{div}})$, if $\textsf{num}$ and $\textsf{div}$ are nonzero and $\textsf{num}/\textsf{div}$ is a nonsquare in the field;

where $G_S$ is a non-square.

§Warnings
  • The choice of root from sqrt is unspecified.
  • The value of $G_S$ is unspecified, and cannot be assumed to have any specific value in a generic context.

Provided Methods§

Source

fn is_zero(&self) -> Choice

Returns true iff this element is zero.

Source

fn is_zero_vartime(&self) -> bool

Returns true iff this element is zero.

§Security

This method provides no constant-time guarantees. Implementors of the Field trait may optimise this method using non-constant-time logic.

Source

fn cube(&self) -> Self

Cubes this element.

Source

fn sqrt_alt(&self) -> (Choice, Self)

Equivalent to Self::sqrt_ratio(self, one()).

The provided method is implemented in terms of Self::sqrt_ratio.

Source

fn sqrt(&self) -> CtOption<Self>

Returns the square root of the field element, if it is quadratic residue.

The provided method is implemented in terms of Self::sqrt_ratio.

Source

fn pow<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent.

§Guarantees

This operation is constant time with respect to self, for all exponents with the same number of digits (exp.as_ref().len()). It is variable time with respect to the number of digits in the exponent.

Source

fn pow_vartime<S>(&self, exp: S) -> Self
where S: AsRef<[u64]>,

Exponentiates self by exp, where exp is a little-endian order integer exponent.

§Guarantees

This operation is variable time with respect to self, for all exponent. If the exponent is fixed, this operation is effectively constant time. However, for stronger constant-time guarantees, Field::pow should be used.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Field for Fp2

Source§

const ZERO: Fp2 = _

Source§

const ONE: Fp2 = _

Source§

fn random(rng: impl RngCore) -> Fp2

Source§

fn is_zero(&self) -> Choice

Source§

fn square(&self) -> Fp2

Source§

fn double(&self) -> Fp2

Source§

fn sqrt(&self) -> CtOption<Fp2>

Source§

fn invert(&self) -> CtOption<Fp2>

Source§

fn sqrt_ratio(num: &Fp2, div: &Fp2) -> (Choice, Fp2)

Source§

impl Field for Fp12

Source§

const ZERO: Fp12 = _

Source§

const ONE: Fp12 = _

Source§

fn random(rng: impl RngCore) -> Fp12

Source§

fn is_zero(&self) -> Choice

Source§

fn square(&self) -> Fp12

Source§

fn double(&self) -> Fp12

Source§

fn sqrt(&self) -> CtOption<Fp12>

Source§

fn invert(&self) -> CtOption<Fp12>

Source§

fn sqrt_ratio(_num: &Fp12, _div: &Fp12) -> (Choice, Fp12)

Source§

impl Field for Fp

Source§

const ZERO: Fp = _

Source§

const ONE: Fp = _

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn double(&self) -> Fp

Source§

fn invert(&self) -> CtOption<Fp>

Source§

fn sqrt_ratio(num: &Fp, div: &Fp) -> (Choice, Fp)

Source§

fn sqrt(&self) -> CtOption<Fp>

Source§

impl Field for Scalar

Source§

impl Field for Fq2

Source§

const ZERO: Fq2 = _

Source§

const ONE: Fq2 = _

Source§

fn random(rng: impl RngCore) -> Fq2

Source§

fn is_zero(&self) -> Choice

Source§

fn square(&self) -> Fq2

Source§

fn double(&self) -> Fq2

Source§

fn sqrt(&self) -> CtOption<Fq2>

Source§

fn sqrt_ratio(num: &Fq2, div: &Fq2) -> (Choice, Fq2)

Source§

fn invert(&self) -> CtOption<Fq2>

Source§

impl Field for Fq6

Source§

const ZERO: Fq6 = _

Source§

const ONE: Fq6 = _

Source§

fn random(rng: impl RngCore) -> Fq6

Source§

fn is_zero(&self) -> Choice

Source§

fn square(&self) -> Fq6

Source§

fn double(&self) -> Fq6

Source§

fn sqrt(&self) -> CtOption<Fq6>

Source§

fn sqrt_ratio(_num: &Fq6, _div: &Fq6) -> (Choice, Fq6)

Source§

fn invert(&self) -> CtOption<Fq6>

Source§

impl Field for Fq12

Source§

const ZERO: Fq12 = _

Source§

const ONE: Fq12 = _

Source§

fn random(rng: impl RngCore) -> Fq12

Source§

fn is_zero(&self) -> Choice

Source§

fn square(&self) -> Fq12

Source§

fn double(&self) -> Fq12

Source§

fn sqrt(&self) -> CtOption<Fq12>

Source§

fn sqrt_ratio(_num: &Fq12, _div: &Fq12) -> (Choice, Fq12)

Source§

fn invert(&self) -> CtOption<Fq12>

Source§

impl Field for Fq

Source§

fn sqrt(&self) -> CtOption<Fq>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fq>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

impl Field for Fr

Source§

fn invert(&self) -> CtOption<Fr>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fr = _

Source§

const ONE: Fr = _

Source§

fn random(rng: impl RngCore) -> Fr

Source§

fn double(&self) -> Fr

Source§

fn square(&self) -> Fr

Source§

fn sqrt(&self) -> CtOption<Fr>

Source§

fn sqrt_ratio(num: &Fr, div: &Fr) -> (Choice, Fr)

Source§

impl Field for Fq

Source§

fn sqrt(&self) -> CtOption<Fq>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fq>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

fn pow_vartime<S>(&self, exp: S) -> Fq
where S: AsRef<[u64]>,

Source§

impl Field for Fr

Source§

fn sqrt(&self) -> CtOption<Fr>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fr>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fr = _

Source§

const ONE: Fr = _

Source§

fn random(rng: impl RngCore) -> Fr

Source§

fn double(&self) -> Fr

Source§

fn square(&self) -> Fr

Source§

fn sqrt_ratio(num: &Fr, div: &Fr) -> (Choice, Fr)

Source§

fn pow_vartime<S>(&self, exp: S) -> Fr
where S: AsRef<[u64]>,

Source§

impl Field for Fp

Source§

fn invert(&self) -> CtOption<Fp>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fp = _

Source§

const ONE: Fp = _

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn double(&self) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn sqrt(&self) -> CtOption<Fp>

Source§

fn sqrt_ratio(num: &Fp, div: &Fp) -> (Choice, Fp)

Source§

impl Field for Fq

Source§

fn invert(&self) -> CtOption<Fq>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn sqrt(&self) -> CtOption<Fq>

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

impl Field for Fp

Source§

fn sqrt(&self) -> CtOption<Fp>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fp>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fp = _

Source§

const ONE: Fp = _

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn double(&self) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn pow_vartime<S>(&self, exp: S) -> Fp
where S: AsRef<[u64]>,

Source§

fn sqrt_ratio(num: &Fp, div: &Fp) -> (Choice, Fp)

Source§

impl Field for Fq

Source§

fn invert(&self) -> CtOption<Fq>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn pow_vartime<S>(&self, exp: S) -> Fq
where S: AsRef<[u64]>,

Source§

fn sqrt(&self) -> CtOption<Fq>

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

impl Field for Fp

Source§

fn sqrt(&self) -> CtOption<Fp>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fp>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fp = _

Source§

const ONE: Fp = _

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn double(&self) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn pow_vartime<S>(&self, exp: S) -> Fp
where S: AsRef<[u64]>,

Source§

fn sqrt_ratio(num: &Fp, div: &Fp) -> (Choice, Fp)

Source§

impl Field for Fq

Source§

fn invert(&self) -> CtOption<Fq>

Returns the multiplicative inverse of the element. If it is zero, the method fails.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn pow_vartime<S>(&self, exp: S) -> Fq
where S: AsRef<[u64]>,

Source§

fn sqrt(&self) -> CtOption<Fq>

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

impl Field for Fp

Source§

fn sqrt(&self) -> CtOption<Fp>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fp>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fp = _

Source§

const ONE: Fp = _

Source§

fn random(rng: impl RngCore) -> Fp

Source§

fn double(&self) -> Fp

Source§

fn square(&self) -> Fp

Source§

fn sqrt_ratio(num: &Fp, div: &Fp) -> (Choice, Fp)

Source§

fn sqrt_alt(&self) -> (Choice, Fp)

Source§

fn pow_vartime<S>(&self, exp: S) -> Fp
where S: AsRef<[u64]>,

Source§

impl Field for Fq

Source§

fn sqrt(&self) -> CtOption<Fq>

Computes the square root of this element, if it exists.

Source§

fn invert(&self) -> CtOption<Fq>

Computes the multiplicative inverse of this element, failing if the element is zero.

Source§

const ZERO: Fq = _

Source§

const ONE: Fq = _

Source§

fn random(rng: impl RngCore) -> Fq

Source§

fn double(&self) -> Fq

Source§

fn square(&self) -> Fq

Source§

fn sqrt_ratio(num: &Fq, div: &Fq) -> (Choice, Fq)

Source§

fn sqrt_alt(&self) -> (Choice, Fq)

Source§

fn pow_vartime<S>(&self, exp: S) -> Fq
where S: AsRef<[u64]>,

Implementors§