Skip to main content

PrimeField

Trait PrimeField 

Source
pub trait PrimeField:
    Copy
    + Clone
    + Eq
    + PartialEq
    + Ord
    + PartialOrd
    + Debug {
    const MODULUS: u128;
    const BITS: u32;
    const ZERO: Self;
    const ONE: Self;

    // Required methods
    fn from_u64(v: u64) -> Self;
    fn to_u64(self) -> u64;
    fn add(self, rhs: Self) -> Self;
    fn sub(self, rhs: Self) -> Self;
    fn mul(self, rhs: Self) -> Self;
    fn neg(self) -> Self;

    // Provided methods
    fn inv(self) -> Option<Self> { ... }
    fn pow(self, exp: u64) -> Self { ... }
    fn pow_u128(self, exp: u128) -> Self { ... }
}
Expand description

Trait for prime field arithmetic.

Warriors use this for field-generic hash functions, proof estimation, and verification. Trident provides concrete implementations; warriors call them without reimplementing the math.

Required Associated Constants§

Source

const MODULUS: u128

The field modulus as u128 (fits all supported primes).

Source

const BITS: u32

Number of bits in the modulus.

Source

const ZERO: Self

Additive identity.

Source

const ONE: Self

Multiplicative identity.

Required Methods§

Source

fn from_u64(v: u64) -> Self

Construct from a u64 value (reduced mod p).

Source

fn to_u64(self) -> u64

Extract the canonical u64 representative.

Source

fn add(self, rhs: Self) -> Self

Field addition: (a + b) mod p.

Source

fn sub(self, rhs: Self) -> Self

Field subtraction: (a - b) mod p.

Source

fn mul(self, rhs: Self) -> Self

Field multiplication: (a * b) mod p.

Source

fn neg(self) -> Self

Additive inverse: (-a) mod p.

Provided Methods§

Source

fn inv(self) -> Option<Self>

Multiplicative inverse via Fermat: a^(p-2) mod p. Returns None for zero.

Source

fn pow(self, exp: u64) -> Self

Exponentiation: a^exp mod p (square-and-multiply, u64 exponent).

Source

fn pow_u128(self, exp: u128) -> Self

Exponentiation with u128 exponent (for Fermat inversion).

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.

Implementors§