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 24 methods
// Required methods
fn from_repr(repr: Self::Repr) -> Self;
fn from_le_bytes(bytes: &[u8]) -> Option<Self>;
fn from_be_bytes(bytes: &[u8]) -> Option<Self>;
fn from_le_bytes_unchecked(bytes: &[u8]) -> Self;
fn from_be_bytes_unchecked(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);
fn assert_reduced(&self);
fn is_reduced(&self) -> bool;
fn set_up_once();
unsafe fn eq_impl<const CHECK_SETUP: bool>(&self, other: &Self) -> bool;
unsafe fn add_ref<const CHECK_SETUP: bool>(&self, other: &Self) -> Self;
// Provided methods
fn double(&self) -> Self { ... }
fn square(&self) -> Self { ... }
fn cube(&self) -> 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_repr(repr: Self::Repr) -> Self
fn from_repr(repr: Self::Repr) -> Self
Creates a new IntMod from an instance of Repr.
Does not enforce the integer value of bytes
must be less than the modulus.
Sourcefn from_le_bytes(bytes: &[u8]) -> Option<Self>
fn from_le_bytes(bytes: &[u8]) -> Option<Self>
Creates a new IntMod from an array of bytes, little endian.
Returns None
if the integer value of bytes
is greater than or equal to the modulus.
Sourcefn from_be_bytes(bytes: &[u8]) -> Option<Self>
fn from_be_bytes(bytes: &[u8]) -> Option<Self>
Creates a new IntMod from an array of bytes, big endian.
Returns None
if the integer value of bytes
is greater than or equal to the modulus.
Sourcefn from_le_bytes_unchecked(bytes: &[u8]) -> Self
fn from_le_bytes_unchecked(bytes: &[u8]) -> Self
Creates a new IntMod from an array of bytes, little endian.
Does not enforce the integer value of bytes
must be less than the modulus.
Sourcefn from_be_bytes_unchecked(bytes: &[u8]) -> Self
fn from_be_bytes_unchecked(bytes: &[u8]) -> Self
Creates a new IntMod from an array of bytes, big endian.
Does not enforce the integer value of bytes
must be less than the modulus.
Sourcefn from_u8(val: u8) -> Self
fn from_u8(val: u8) -> Self
Creates a new IntMod from a u8.
Does not enforce the integer value of bytes
must be less than the modulus.
Sourcefn from_u32(val: u32) -> Self
fn from_u32(val: u32) -> Self
Creates a new IntMod from a u32.
Does not enforce the integer value of bytes
must be less than the modulus.
Sourcefn from_u64(val: u64) -> Self
fn from_u64(val: u64) -> Self
Creates a new IntMod from a u64.
Does not enforce the integer value of bytes
must be less than the modulus.
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.
Sourcefn assert_reduced(&self)
fn assert_reduced(&self)
VM specific concept: during guest execution, it is not enforced that the representation
of Self
must be the unique integer less than the modulus. The guest code may sometimes
want to enforce that the representation is the canonical one less than the modulus.
the host to an honest host to provide the canonical representation less than the modulus.
This function should enforce that guest execution proceeds if and only if self
is in the unique representation less than the modulus.
Sourcefn is_reduced(&self) -> bool
fn is_reduced(&self) -> bool
Is the integer representation of self
less than the modulus?
Sourcefn set_up_once()
fn set_up_once()
Calls any setup required for this modulus. The implementation should internally use
OnceBool
to ensure that setup is only called once.
Sourceunsafe fn eq_impl<const CHECK_SETUP: bool>(&self, other: &Self) -> bool
unsafe fn eq_impl<const CHECK_SETUP: bool>(&self, other: &Self) -> bool
Returns whether the two integers are congrument modulo the modulus.
§Safety
- If
CHECK_SETUP
is true, checks if setup has been called for this curve and if not, callsSelf::set_up_once()
. Only setCHECK_SETUP
tofalse
if you are sure that setup has been called already.
Provided Methods§
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.