Repository navigation
[kani] Prove utility memory operations #3648
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
base: Gcmpgic3rdonowgrcxzylfnswfrlxt6lm
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,3 +397,29 @@ pub(crate) fn nonzero_u16_from_ne_bytes(bytes: [u8; 2]) -> Option<core::num::Non | |
| pub(crate) fn copy_snapshot<T: Copy>(value: &T) -> T { | ||
| *value | ||
| } | ||
|
|
||
| // Compare ordered byte values without treating slice or array `PartialEq` as | ||
| // an implicit oracle. `slice::len` returns each slice's element count, | ||
| // while the factored `assert_same_usize` supplies the documented equality | ||
| // observation above. The first assertion therefore requires equal element | ||
| // counts. `slice::iter` yields every item from start to end [1], | ||
| // `Iterator::copied` copies those items and `Iterator::eq` compares the two | ||
| // sequences [2], and `u8::eq` supplies element equality [3]. Rust specifies | ||
| // that the final `assert!` panics when that equality expression | ||
| // is false and cannot be disabled [4], so—under Kani's assertion/panic | ||
| // translation—an ordered-value mismatch cannot silently pass the harness. | ||
| // These safe operations call no zerocopy target, so they are | ||
| // independent of that target implementation, but not of the compiler, | ||
| // standard library, or Kani model. They establish values only, not storage | ||
| // identity or provenance. | ||
| // | ||
| // [1] https://doc.rust-lang.org/1.93.0/std/primitive.slice.html#method.len | ||
| // https://doc.rust-lang.org/1.93.0/std/primitive.slice.html#method.iter | ||
| // [2] https://doc.rust-lang.org/1.93.0/std/iter/trait.Iterator.html#method.copied | ||
| // https://doc.rust-lang.org/1.93.0/std/iter/trait.Iterator.html#method.eq | ||
| // [3] https://doc.rust-lang.org/1.93.0/std/primitive.u8.html#impl-PartialEq-for-u8 | ||
| // [4] https://doc.rust-lang.org/1.93.0/std/macro.assert.html | ||
| pub(crate) fn assert_same_u8_elements(actual: &[u8], expected: &[u8]) { | ||
| assert_same_usize(actual.len(), expected.len()); | ||
| assert!(actual.iter().copied().eq(expected.iter().copied())); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every new byte and AGENTS.md reference: zerocopy/AGENTS.md:L67-L71 Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in the current revision. The shared ordered-byte observer now cites Rust 1.93’s Authored by an AI agent acting on Josh Liebow-Feeser's behalf.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in Authored by an AI agent acting on Josh Liebow-Feeser's behalf. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the copy proof uses this helper to establish the pre-call source and destination values, the cited moved/copied-place rule explains what happens after a place has been selected, but it does not establish that
*valuedenotes the referent supplied by the caller. Add the versioned dereference-result contract (and retain the explanation that this safe helper is independent of the target); otherwise the frame oracle's claimed snapshot semantics lack the complete normative basis required byagent_docs/validation.md.AGENTS.md reference: zerocopy/AGENTS.md:L67-L71
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in the current revision.
copy_snapshotnow cites the full Rust 1.93 language chain: the dereference-result rule establishes that*valuedenotes the referent; the block rule establishes that the function-body block evaluates its final operand in value context; and the moved/copied-place rule establishes that this copies theT: Copyvalue. The comment explicitly identifies the helper as safe and independent of zerocopy, and limits its observation to value rather than allocation identity or independent storage.Authored by an AI agent acting on Josh Liebow-Feeser's behalf.