Skip to content

Remove spurious comments about the need for quantifiers - #457

Merged
feliperodri merged 5 commits into
model-checking:mainfrom
tautschnig:use-quantifiers
Oct 8, 2025
Merged

Remove spurious comments about the need for quantifiers#457
feliperodri merged 5 commits into
model-checking:mainfrom
tautschnig:use-quantifiers

Conversation

@tautschnig

Copy link
Copy Markdown
Member

None of the (three) cases where we previously claimed a need for quantifiers actually require them.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

None of the (three) cases where we previously claimed a need for
quantifiers actually require them.
@tautschnig
tautschnig requested a review from a team as a code owner August 12, 2025 14:00
Comment thread library/core/src/ptr/mod.rs
@feliperodri
feliperodri enabled auto-merge October 8, 2025 15:48
@feliperodri
feliperodri added this pull request to the merge queue Oct 8, 2025
Merged via the queue into model-checking:main with commit 6be9ca4 Oct 8, 2025
27 checks passed
DiuDiu777 pushed a commit to safer-rust/rapx-verify-rust-std that referenced this pull request Aug 29, 2026
…g#622)

The `x % 2 != 0` precondition on `ptr::mod_inv`, added in
6be9ca4 (model-checking#457), is violated by
`mod_inv`'s only caller: `align_offset::<T>(p, 1)` with `size_of::<T>()
> 1` takes the GENERAL_CASE path (since `1 % stride != 0`) and computes
`s2 = (stride & 0) >> 0 = 0`, calling `mod_inv(0, 1)`. This is reachable
e.g. via `<[u16]>::align_to::<u8>()`.

The violation is currently invisible in CI because `run-kani.sh` passes
`--no-assert-contracts`; with dependency contracts asserted (the Kani
default since model-checking/kani#3802), the harnesses
`slice::verify::align_to_from_u16::align_to_u8`,
`slice::verify::align_to_mut_from_char::align_to_mut_u8`,
`slice::verify::align_to_mut_from_u32::align_to_mut_u8`, and
`ptr::verify::check_align_offset_u16` all fail on the asserted `x % 2 !=
0` clause.

The call is mathematically sound — modulo `m == 1` every value is
trivially an inverse (the unique residue is 0), and `align_offset` masks
the returned value with `a2 - 1 == 0` — so it is the precondition that
is too strict, not the caller that is wrong: an inverse of `x` modulo a
power of two `m` exists iff `gcd(x, m) == 1`, which for `m > 1` means
odd `x` but for `m == 1` holds for all `x`. This PR weakens the
precondition to `m == 1 || x % 2 != 0` and fixes the (kani-disabled)
postcondition for the same degenerate case (`% m == 1 % m` instead of `%
m == 1`, since modulo 1 the result is 0).

Verified with Kani 152c6a8c + CBMC 6.10.0: the four harnesses above now
pass with contracts asserted, and the eight
`ptr::verify::check_align_offset*` proof harnesses pass both with and
without `--no-assert-contracts`.

Found while investigating what still blocks removing
`--no-assert-contracts` from `run-kani.sh`: this is one of two genuine
latent contract violations that asserting dependency contracts surfaces
(the other: model-checking#623).

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants