Skip to content

Contract & Harnesses for byte_sub, offset, map_addr and with_addr #107

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

Merged
merged 52 commits into from
Dec 11, 2024

Conversation

Dhvani-Kapadia
Copy link

@Dhvani-Kapadia Dhvani-Kapadia commented Oct 8, 2024

Description

This PR includes contracts and proof harnesses for the four APIs, offset , byte_sub, map_addr, and with_addr which are part of the NonNull library in Rust.

Changes Overview:

Covered APIs:
NonNull::offset: Adds an offset to a pointer
NonNull::byte_sub: Calculates an offset from a pointer in bytes.
NonNull:: map_addr: Creates a new pointer by mapping self's address to a new one
NonNull::with_addr: Creates a new pointer with the given address

Proof harness:
non_null_check_offset
non_null_check_byte_sub
non_null_check_map_addr
non_null_check_with_addr

Revalidation

To revalidate the verification results, run kani verify-std -Z unstable-options "path/to/library" -Z function-contracts -Z mem-predicates --harness ptr::non_null::verify. This will run all four harnesses in the module. All default checks should pass:


VERIFICATION:- SUCCESSFUL
Verification Time: 0.57787573s

Complete - 6 successfully verified harnesses, 0 failures, 6 total.

Towards issue #53

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

@Dhvani-Kapadia Dhvani-Kapadia requested a review from a team as a code owner October 8, 2024 00:18
@carolynzech
Copy link

Also, re your PR description: it seems like the issue you mention for #91 was resolved by building Kani from source. Can you update your PR description if that is the case? Please also add "Towards #ISSUE-NUMBER" with the appropriate issue link for your challenge.

Copy link

@QinyuanWu QinyuanWu left a comment

Choose a reason for hiding this comment

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

Please make sure to remove all other edits that are not in non_null.rs.

@Dhvani-Kapadia Dhvani-Kapadia changed the title Contract & Harnesses for byte_sub and offset Contract & Harnesses for byte_su, offset, map_addr and with_addr Oct 13, 2024
@Dhvani-Kapadia Dhvani-Kapadia changed the title Contract & Harnesses for byte_su, offset, map_addr and with_addr Contract & Harnesses for byte_sub, offset, map_addr and with_addr Oct 13, 2024
@Dhvani-Kapadia
Copy link
Author

I wanted to use can_dereference for map_addr but got multiple compilation errors.
#[ensures(|result: &Self| kani::mem::can_dereference(result.as_ptr()))] . So ended up not including it in the contract. Could you please let me know if my usage of it is correct or provide examples?

@carolynzech
Copy link

carolynzech commented Oct 14, 2024

I wanted to use can_dereference for map_addr but got multiple compilation errors. #[ensures(|result: &Self| kani::mem::can_dereference(result.as_ptr()))] . So ended up not including it in the contract. Could you please let me know if my usage of it is correct or provide examples?

@Dhvani-Kapadia I suspect this is another import error--you should be importing crate::ub_checks::can_dereference. Please include the text of your errors in the future--they are very helpful for debugging! As for examples, I would recommend searching for usages of this function elsewhere in this repository (intrinsics.rs has some).

@carolynzech carolynzech self-assigned this Nov 13, 2024
@Dhvani-Kapadia
Copy link
Author

@carolynzech , @zhassan-aws , @feliperodri could you please review it.

Copy link

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link

@feliperodri feliperodri left a comment

Choose a reason for hiding this comment

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

trigger review

github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2024
Improve the logging in our PR approvals workflow. This is a good thing
to do generally, but we're specifically trying to debug why the script
is failing in #107.

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: Michael Tautschnig <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Dec 11, 2024
The `check_approvals` workflow in #107 fails because by default Github
[only returns the first 30
results](https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28#about-pagination)
for GET requests to their API. #107 has more review activity than that,
so the approvals are all on the second or third pages, hence why the
workflow says zero approvals.

So, this PR updates the script to fetch 100 responses per page, up to
100 pages. These are arbitrary values, but I didn't want to have any
infinite loops, and I can't imagine a realistic PR ever going above
these numbers (and I put a warning in the script if they do).

I checked that this new workflow runs without error [on my
fork](https://github.com/carolynzech/verify-rust-std/actions/runs/12267930897/job/34228889979?pr=20).
I also did some experimentation in my local bash with the branch from
#107 and verified that upping the pagination limits like this does
indeed return the approvals on the later pages.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
@tautschnig tautschnig enabled auto-merge December 11, 2024 12:52
@tautschnig tautschnig added this pull request to the merge queue Dec 11, 2024
Merged via the queue into model-checking:main with commit 9083ec2 Dec 11, 2024
8 checks passed
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.

7 participants