Skip to content

Commit

Permalink
Remove inverse_mod method
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Nov 10, 2023
1 parent 8476f50 commit fa541cc
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions crates/starknet-types-core/src/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,11 @@ impl Felt {
Self(self.0.pow(exponent.0.representative()))
}

/// Modular multiplication between `self` and `rhs` modulo `p`.
/// Field multiplication between `self` and `rhs`, then apply modulo `p`.
pub fn mul_mod(&self, rhs: &Self, p: &NonZeroFelt) -> Self {
(self * rhs).div_rem(p).1
}

/// Modular inverse of `self` modulo `p`.
pub fn inverse_mod(&self, p: &NonZeroFelt) -> Option<Self> {
self.inverse().map(|x| x.div_rem(p).1)
}

/// Remainder of dividing `self` by `n` as integers.
pub fn mod_floor(&self, n: &NonZeroFelt) -> Self {
self.div_rem(n).1
Expand Down Expand Up @@ -1027,19 +1022,6 @@ mod test {
prop_assert_eq!(x * x.inverse().unwrap(), Felt::ONE )
}

#[test]
fn inverse_mod_of_zero_is_none(p in nonzero_felt()) {
let nzp = NonZeroFelt(p.0);
prop_assert!(Felt::ZERO.inverse_mod(&nzp).is_none());
}

#[test]
fn inverse_mod_in_range(x in nonzero_felt(), p in nonzero_felt()) {
let nzp = NonZeroFelt(p.0);
prop_assert!(x.inverse_mod(&nzp) <= Some(Felt::MAX));
prop_assert!(x.inverse_mod(&nzp) < Some(p));
}

#[test]
fn mul_mod_in_range(x in any::<Felt>(), y in any::<Felt>(), p in nonzero_felt()) {
let nzp = NonZeroFelt(p.0);
Expand Down

0 comments on commit fa541cc

Please sign in to comment.