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§
Required Associated Types§
Sourcetype Repr: AsRef<[u8]> + AsMut<[u8]>
type Repr: AsRef<[u8]> + AsMut<[u8]>
Underlying representation of IntMod. Usually of the form [u8; NUM_LIMBS]
.
Sourcetype 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
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§
Sourcefn from_le_bytes(bytes: &[u8]) -> Self
fn from_le_bytes(bytes: &[u8]) -> Self
Creates a new IntMod from an array of bytes, little endian.
Sourcefn from_be_bytes(bytes: &[u8]) -> Self
fn from_be_bytes(bytes: &[u8]) -> Self
Creates a new IntMod from an array of bytes, big endian.
Sourcefn as_le_bytes(&self) -> &[u8] ⓘ
fn as_le_bytes(&self) -> &[u8] ⓘ
Value of this IntMod as an array of bytes, little endian.
Sourcefn to_be_bytes(&self) -> Self::Repr
fn to_be_bytes(&self) -> Self::Repr
Value of this IntMod as an array of bytes, big endian.
Sourcefn modulus_biguint() -> BigUint
fn modulus_biguint() -> BigUint
Modulus N as a BigUint.
Sourcefn from_biguint(biguint: BigUint) -> Self
fn from_biguint(biguint: BigUint) -> Self
Creates a new IntMod from a BigUint.
Sourcefn as_biguint(&self) -> BigUint
fn as_biguint(&self) -> BigUint
Value of this IntMod as a BigUint.
fn neg_assign(&mut self)
Sourcefn double_assign(&mut self)
fn double_assign(&mut self)
Doubles self
in-place.
Sourcefn square_assign(&mut self)
fn square_assign(&mut self)
Squares self
in-place.
Provided Methods§
Sourcefn assert_unique(&self)
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.
Sourcefn reduce(&mut self)
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.