Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental API to generate arbitrary pointers #3538

Merged
merged 12 commits into from
Oct 5, 2024

Conversation

celinval
Copy link
Contributor

@celinval celinval commented Sep 23, 2024

This change adds a pointer generator that can non-deterministically generate a pointer with different properties.

This generator allows users to build pointers with different allocation status, initialization and alignment.
It contains an internal buffer that it uses to generate InBounds and OutOfBounds pointers.
In those cases, the pointers will have the same provenance as the generator, and the same lifetime.

This approach is different than generating a pointer from an arbitrary usize. Kani uses demonic non-determinism to track
allocation lifetimes, which makes hard to reason about during verification. I.e., one cannot assume a pointer is valid, and initialized, and this can only be accomplished by manually tracking the pointer status.

I added the new API under -Z mem-predicates since it allows reasoning about memory, and I was hoping this wouldn't need another unstable flag. 😄

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

Pointer generator that can be used to generate an arbitrary pointer.

This generator allows users to build pointers with different allocation
status, initialization and alignemnt.
It contains an internal buffer that it uses to generate `InBounds` and
`OutBounds` pointers.
In those cases, the pointers will have the same provenance
as the generator, and the same lifetime.
@celinval celinval requested a review from a team as a code owner September 23, 2024 11:43
@github-actions github-actions bot added the Z-BenchCI Tag a PR to run benchmark CI label Sep 23, 2024
@tautschnig
Copy link
Member

Appears to break std verification:

error[E0433]: failed to resolve: use of undeclared crate or module `kani`
   --> /home/runner/work/kani/kani/verify-rust-std/library/core/src/lib.rs:426:1
    |
426 | kani_core::kani_lib!(core);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `kani`
    |
    = note: this error originates in the macro `kani_core::generate_arbitrary` which comes from the expansion of the macro `kani_core::kani_lib` (in Nightly builds, run with -Z macro-backtrace for more info)

Copy link
Member

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this, but I think we really need more documentation to enable safe and sound use of this capability in any proofs that users may be constructing.

library/kani_core/src/arbitrary.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary.rs Outdated Show resolved Hide resolved
tests/expected/arbitrary/ptrs/pointer_inbounds.rs Outdated Show resolved Hide resolved
@celinval
Copy link
Contributor Author

@tautschnig, hopefully I addressed all your comments. I also moved the pointer type to be an argument of the methods instead of the generator type.

Copy link
Contributor

@zhassan-aws zhassan-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Show resolved Hide resolved
@celinval celinval assigned zhassan-aws and tautschnig and unassigned celinval Oct 4, 2024
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
library/kani_core/src/arbitrary/pointer.rs Outdated Show resolved Hide resolved
@celinval celinval enabled auto-merge October 4, 2024 23:08
@celinval celinval added this pull request to the merge queue Oct 5, 2024
Merged via the queue into model-checking:main with commit d2f5dbe Oct 5, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-BenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants