Skip to content

Commit

Permalink
add TODO comment for mod_inv postcondition
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynzech committed Aug 29, 2024
1 parent 0177d4f commit 501ee0a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,12 @@ mod verify {
// This function lives inside align_offset, so it is not publicly accessible (hence this copy).
#[safety::requires(m.is_power_of_two())]
#[safety::requires(x < m)]
// TODO: add ensures contract to check that the answer is indeed correct
// This will require quantifiers (https://model-checking.github.io/kani/rfc/rfcs/0010-quantifiers.html)
// so that we can add a precondition that gcd(x, m) = 1 like so:
// ∀d, d > 0 ∧ x % d = 0 ∧ m % d = 0 → d = 1
// With this precondition, we can then write this postcondition to check the correctness of the answer:
// #[safety::ensures(|result| wrapping_mul(*result, x) % m == 1)]
const unsafe fn mod_inv_copy(x: usize, m: usize) -> usize {
/// Multiplicative modular inverse table modulo 2⁴ = 16.
///
Expand Down

0 comments on commit 501ee0a

Please sign in to comment.