Skip to content

Write contracts + pre/post conditions for all unsafe methods in duration - #136

Merged
tautschnig merged 22 commits into
model-checking:mainfrom
sgpthomas:verify_duration_challenge9
Dec 11, 2024
Merged

Write contracts + pre/post conditions for all unsafe methods in duration#136
tautschnig merged 22 commits into
model-checking:mainfrom
sgpthomas:verify_duration_challenge9

Conversation

@sgpthomas

Copy link
Copy Markdown

Resolves#72

We added invariants for Nanoseconds and Duration to match the safety conditions for those types.

We add safety requirements to the following methods:

  • new, from_secs, from_millis, from_micros, from_nanos, as_secs, as_millis, as_micros, as_nanos, subsec_millis, subsec_micros, subsec_nanos, checked_add, checked_sub, checked_mul, checked_div

We additionally add correctness conditions to the following methods:

  • from_secs, as_secs, subsec_millis, subsec_micros, subsec_nanos, as_millis, as_micros

Support for kani::Invariant depends on #87. For the interim we implemented a proxy trait TempInvariant that exposes the same is_safe method. We will update this once #87 is merged.

While the safety check for Duration::as_nanos() succeeds, we ran into timeouts for Duration::as_nanos() when we tried to use a correctness contract and we're looking for advice on how to speed up that verification time. We were able to prove it for u16::MAX, but hit timeouts for larger numbers.

We are unsure if the pre-conditions for Duration::new() are acceptable because they limit the range of values that you can call Duration::new() with. However, we think it's reasonable since we limit the values to values that don't panic. Let us know if this is a thing that we should change.

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

@sgpthomas
sgpthomas requested a review from a team as a code ownerOctober 24, 2024 21:32

@celinvalcelinval left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's awesome! Thank you

Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/Cargo.lock
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated

@celinvalcelinval left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Awesome! Thanks

Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
sgpthomasand others added 3 commits November 25, 2024 14:13
Co-authored-by: Celina G. Val <celinval@amazon.com>
Co-authored-by: Celina G. Val <celinval@amazon.com>

@tautschnigtautschnig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we should have anything other than true as a requires clause on safe functions.

Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs
Comment threadlibrary/core/src/time.rs
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs Outdated
Comment threadlibrary/core/src/time.rs
Comment threadlibrary/core/src/time.rs
@tautschnig
tautschnig added this pull request to the merge queueDec 10, 2024
Merged via the queue into model-checking:main with commit 8a248d9Dec 11, 2024
@sgpthomas
sgpthomas deleted the verify_duration_challenge9 branch December 14, 2024 21:45
Sign up for freeto 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.

Challenge 9: Safe abstractions for core::time::Duration

5 participants

@sgpthomas@tautschnig@feliperodri@cvick32@celinval