openvm_algebra_guest

Trait IntMod

Source
pub trait IntMod:
    Sized
    + Eq
    + Clone
    + Debug
    + Neg<Output = Self>
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + DivUnsafe<Output = Self>
    + Sum
    + Product
    + for<'a> Add<&'a Self, Output = Self>
    + for<'a> Sub<&'a Self, Output = Self>
    + for<'a> Mul<&'a Self, Output = Self>
    + for<'a> DivUnsafe<&'a Self, Output = Self>
    + for<'a> Sum<&'a Self>
    + for<'a> Product<&'a Self>
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssignUnsafe
    + for<'a> AddAssign<&'a Self>
    + for<'a> SubAssign<&'a Self>
    + for<'a> MulAssign<&'a Self>
    + for<'a> DivAssignUnsafe<&'a Self> {
    type Repr: AsRef<[u8]> + AsMut<[u8]>;
    type SelfRef<'a>: Add<&'a Self, Output = Self> + Sub<&'a Self, Output = Self> + Neg<Output = Self> + Mul<&'a Self, Output = Self> + DivUnsafe<&'a Self, Output = Self>
       where Self: 'a;

    const MODULUS: Self::Repr;
    const NUM_LIMBS: usize;
    const ZERO: Self;
    const ONE: Self;
Show 19 methods // Required methods fn from_repr(repr: Self::Repr) -> Self; fn from_le_bytes(bytes: &[u8]) -> Self; fn from_be_bytes(bytes: &[u8]) -> Self; fn from_u8(val: u8) -> Self; fn from_u32(val: u32) -> Self; fn from_u64(val: u64) -> Self; fn as_le_bytes(&self) -> &[u8] ; fn to_be_bytes(&self) -> Self::Repr; fn modulus_biguint() -> BigUint; fn from_biguint(biguint: BigUint) -> Self; fn as_biguint(&self) -> BigUint; fn neg_assign(&mut self); fn double_assign(&mut self); fn square_assign(&mut self); // Provided methods fn double(&self) -> Self { ... } fn square(&self) -> Self { ... } fn cube(&self) -> Self { ... } fn assert_unique(&self) { ... } fn reduce(&mut self) { ... }
}
Expand description

Trait definition for OpenVM modular integers, where each operation is done modulo MODULUS.

Division is only defined over the group of units in the ring of integers modulo MODULUS. It is undefined behavior outside of this group.

Required Associated Constants§

Source

const MODULUS: Self::Repr

Modulus as a Repr.

Source

const NUM_LIMBS: usize

Number of limbs used to internally represent an element of Self.

Source

const ZERO: Self

The zero element (i.e. the additive identity).

Source

const ONE: Self

The one element (i.e. the multiplicative identity).

Required Associated Types§

Source

type Repr: AsRef<[u8]> + AsMut<[u8]>

Underlying representation of IntMod. Usually of the form [u8; NUM_LIMBS].

Source

type SelfRef<'a>: Add<&'a Self, Output = Self> + Sub<&'a Self, Output = Self> + Neg<Output = Self> + Mul<&'a Self, Output = Self> + DivUnsafe<&'a Self, Output = Self> where Self: 'a

SelfRef<'a> should almost always be &'a Self. This is a way to include implementations of binary operations where both sides are &'a Self.

Required Methods§

Source

fn from_repr(repr: Self::Repr) -> Self

Creates a new IntMod from an instance of Repr.

Source

fn from_le_bytes(bytes: &[u8]) -> Self

Creates a new IntMod from an array of bytes, little endian.

Source

fn from_be_bytes(bytes: &[u8]) -> Self

Creates a new IntMod from an array of bytes, big endian.

Source

fn from_u8(val: u8) -> Self

Creates a new IntMod from a u8.

Source

fn from_u32(val: u32) -> Self

Creates a new IntMod from a u32.

Source

fn from_u64(val: u64) -> Self

Creates a new IntMod from a u64.

Source

fn as_le_bytes(&self) -> &[u8]

Value of this IntMod as an array of bytes, little endian.

Source

fn to_be_bytes(&self) -> Self::Repr

Value of this IntMod as an array of bytes, big endian.

Source

fn modulus_biguint() -> BigUint

Modulus N as a BigUint.

Source

fn from_biguint(biguint: BigUint) -> Self

Creates a new IntMod from a BigUint.

Source

fn as_biguint(&self) -> BigUint

Value of this IntMod as a BigUint.

Source

fn neg_assign(&mut self)

Source

fn double_assign(&mut self)

Doubles self in-place.

Source

fn square_assign(&mut self)

Squares self in-place.

Provided Methods§

Source

fn double(&self) -> Self

Doubles this IntMod.

Source

fn square(&self) -> Self

Squares this IntMod.

Source

fn cube(&self) -> Self

Cubes this IntMod.

Source

fn assert_unique(&self)

zkVM specific concept: the in-memory values of Self will normally be in their canonical unique form (e.g., less than modulus) but the zkVM circuit does not constrain it. In cases where uniqueness is essential for security, this function should be called to constrain uniqueness.

Note that this is done automatically in PartialEq and Eq implementations.

§Panics

If assertion fails.

Source

fn reduce(&mut self)

This function is mostly for internal use in other internal implemntations. Normal users are not advised to use it.

If self was directly constructed from a raw representation and not in its canonical unique form (e.g., less than the modulus), this function will “reduce” self to its canonical form and also call assert_unique.

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§