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

added harnesses for c_str: is_empty #195

Closed
wants to merge 93 commits into from
Closed
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
1ae4c6d
Add Kani proofs of unchecked_add for all integer types
Sep 11, 2024
b553678
Format proof files & Add verification function templates
Sep 11, 2024
4db34e4
feat: add i8 uncheck shl verification
MWDZ Sep 11, 2024
54f5507
feat: add i16 and i32 uncheck shl verification
MWDZ Sep 11, 2024
472da0e
added unsafe integer i8 unchecked sub following the template
lanfeima Sep 12, 2024
daaaf7e
Experiment with two verification approaches in mod.rs of core::num
Sep 16, 2024
7bd0e3c
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-unsa…
Yenyun035 Sep 18, 2024
1c9dbde
Add contracts to unchecked_add && Add i8::unchecked_add proof
Sep 18, 2024
894231f
Format core::num mod.rs
Sep 18, 2024
2bc4faf
Add comment for unchecked_add proofs
Sep 18, 2024
d9d4b5f
Add harnesses for i16,i32,i64,i128 unchecked_add
Sep 19, 2024
07c8b4a
Add harnesses for u8,u16,u32,u64,u128 unchecked_add
Sep 19, 2024
1fd4c6a
Cleanup misplaced proofs
Sep 19, 2024
b360311
Clean up comment
Sep 20, 2024
8cbca87
Format comment
Sep 20, 2024
0eef858
Remove before contracts. Fix import in
Sep 20, 2024
4858a53
Fix comment
Sep 20, 2024
8ce3381
Merge remote-tracking branch 'origin/c-0011-core-nums-yenyunw-unsafe-…
MWDZ Sep 23, 2024
bbd75f7
unchecked multiplication and shift right
rajathkotyal Sep 23, 2024
483bdf5
Merge branch 'main' into c-0011-core-nums-yenyunw-unsafe-ints
Yenyun035 Sep 23, 2024
71ffd37
Merge branch 'c-0011-core-nums-yenyunw-unsafe-ints' into c-0011-core-…
lanfeima Sep 23, 2024
a7d3cc2
feat: add contract and test case for unchecked_shl in type int and unit
MWDZ Sep 24, 2024
271afad
added preconditions and postconditions
lanfeima Sep 24, 2024
c7762c2
add proof functions for unchecked_sub
lanfeima Sep 24, 2024
ce35002
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-unsa…
Yenyun035 Sep 24, 2024
d99844d
Remove ensures contracts && Undo formatting on existing code
Sep 24, 2024
fbcf49e
Add {isize, usize}::unchecked_add harnesses
Sep 24, 2024
864afa6
Small fix typo
rajathkotyal Sep 25, 2024
457a2b5
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-unsa…
Yenyun035 Sep 27, 2024
54a03ef
Add harness generation macros for unchecked methods && Update uncheck…
Sep 27, 2024
ae678de
added limits to multiplication proofs, reduced duplicacy in code by u…
rajathkotyal Sep 29, 2024
af6942e
Merge branch 'c-0011-core-nums-yenyunw-unsafe-ints' into c-0011-core-…
rajathkotyal Sep 29, 2024
8ee5682
Remove unused import safety::ensures
Sep 30, 2024
02d706a
unchecked_mul and unchecked_shr proofs (#7)
rajathkotyal Sep 30, 2024
dce9e83
Add comments. Fix spacing
Sep 30, 2024
3880fc7
Revert "Add comments. Fix spacing"
rajathkotyal Oct 2, 2024
781cb87
Revert "unchecked_mul and unchecked_shr proofs (#7)"
rajathkotyal Oct 2, 2024
500e8db
Add comments. Fix spacing
rajathkotyal Oct 2, 2024
1c97825
cleaned up code: deleted the previous attempted proofs
lanfeima Oct 2, 2024
4572831
Merge branch 'c-0011-core-nums-yenyunw-unsafe-ints' into c-0011-core-…
lanfeima Oct 3, 2024
e3eb365
feat: merge the latest version
MWDZ Oct 3, 2024
2b3771f
feat: use macro rules for unchecked_shl harness
MWDZ Oct 3, 2024
1a3bf40
Merge branch 'c-0011-core-nums-junfengj-unchecked-shl' into c-0011-co…
MWDZ Oct 3, 2024
49b0a6b
add interval checks to unchecked_mul
rajathkotyal Oct 5, 2024
7118fa4
Merge branch 'main' into c-0011-core-nums-rajathm-unsafe-ints
rajathkotyal Oct 5, 2024
bbb9656
unchecked neg fix
rajathkotyal Oct 5, 2024
cafeea6
add missing i8, i16 unchecked_mul
rajathkotyal Oct 5, 2024
51745e0
Merge branch 'c-0011-core-nums-rajathm-unsafe-ints' into c-0011-core-…
lanfeima Oct 6, 2024
7f4421c
deleted the postconditions of unchecked_sub
lanfeima Oct 6, 2024
1331a77
deleted the postconditions for the unchecked_sub in uint_macros
lanfeima Oct 6, 2024
c413cac
refacted uncheck_sub harnesses
lanfeima Oct 6, 2024
8ce4a40
updated the branch with the main repository
lanfeima Oct 11, 2024
059dc02
Add carrying_mul verification harnesses for u8, u16, u32, and u64
lanfeima Oct 11, 2024
29ea0ce
updated the macro args for carrying_mult with initial carrying value
lanfeima Oct 11, 2024
6f7deae
resolved the compile error for carrying_mul
lanfeima Oct 15, 2024
ad031a1
deleted the kani submodule for merge
lanfeima Oct 15, 2024
ddabe95
formatted the style
lanfeima Oct 15, 2024
27522b4
Added documentation for generate_carrying_mul_intervals macro
lanfeima Oct 18, 2024
604d746
added full range interval for u8 and u16
lanfeima Oct 19, 2024
71399d8
reduced the interval for carrying_mul u32,u64
lanfeima Oct 20, 2024
95d11f3
f32 test harness & contracts
Yenyun035 Oct 22, 2024
88f7363
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-f32-…
Yenyun035 Oct 23, 2024
227d9ac
Fix contracts && Initial draft of macro and harnesses
Yenyun035 Oct 24, 2024
b875696
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-f32-…
Yenyun035 Oct 24, 2024
1253264
Merge branch 'main' into c-0011-core-nums-lanfeim-carrying-mul
rajathkotyal Oct 25, 2024
70fe5d9
Merge main
Yenyun035 Oct 26, 2024
5742a89
Merge branch 'main' of github.com:rajathkotyal/verify-rust-std into c…
Yenyun035 Oct 28, 2024
082ea5a
f128_float_to_int proofs
rajathkotyal Oct 30, 2024
bb00a72
Fix comment
Yenyun035 Oct 30, 2024
88c3411
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-f32-…
Yenyun035 Oct 30, 2024
a661c16
Merge branch 'main' into c-0011-core-nums-yenyunw-f32-to-int-unchecked
Yenyun035 Oct 30, 2024
c85ce2a
Merge branch 'model-checking:main' into c-0011-core-nums-yenyunw-f32-…
Yenyun035 Oct 31, 2024
02a8b0c
Merge remote-tracking branch 'origin/c-0011-core-nums-yenyunw-f32-to-…
lanfeima Nov 2, 2024
3e9613b
added the contracts and harnesses for f16-int_unchecked
lanfeima Nov 2, 2024
bf613a0
Test CStr safety invariant
Yenyun035 Nov 22, 2024
cf6aab1
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
63d53fb
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
90ae7a5
Add CStr safety invariant && from_bytes_until_null harnesses
Yenyun035 Nov 22, 2024
e111145
Merge branch 'model-checking:main' into c-0013-yenyunw-cstr
Yenyun035 Nov 22, 2024
55dfaaf
Add comments
Yenyun035 Nov 22, 2024
3b01c6b
Merge remote-tracking branch 'origin/c-0013-yenyunw-cstr' into c-0013…
lanfeima Nov 23, 2024
b49f4ee
merge recent cstr
lanfeima Nov 23, 2024
f03b418
added harnesses for is_empty
lanfeima Nov 23, 2024
64ddbff
Add to_bytes and to_bytes_with_nul harnesses
Yenyun035 Nov 27, 2024
90865ea
Merge remote-tracking branch 'origin/c-0013-yenyunw-cstr-to-bytes' in…
lanfeima Nov 27, 2024
1fc9540
combined the is_empty with the latest repo
lanfeima Nov 27, 2024
7e75de1
finished testing for is_empty
lanfeima Nov 28, 2024
ae7af7c
used kani_anywhere to generate the values
lanfeima Nov 28, 2024
43e588c
edited the documentation
lanfeima Nov 28, 2024
fdefcc0
remove the irrelevant kani folder and cargo file
lanfeima Nov 28, 2024
1f5e28a
reverted Cargo.lock to the stable one
lanfeima Nov 28, 2024
8cc0b12
Reset stdarch submodule to commit ff9a444
lanfeima Nov 28, 2024
41ddead
revised is_empty harness without using arbitrary_cstr
lanfeima Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,50 @@ mod verify {
assert!(c_str.is_safe());
}
}

#[kani::proof]
#[kani::unwind(32)]
fn check_count_bytes() {
const MAX_SIZE: usize = 32;
let mut bytes: [u8; MAX_SIZE] = kani::any();

// Non-deterministically generate a length within the valid range [0, MAX_SIZE]
let mut len: usize = kani::any_where(|&x| x < MAX_SIZE);

// If a null byte exists before the generated length
// adjust len to its position
if let Some(pos) = bytes[..len].iter().position(|&x| x == 0) {
len = pos;
} else {
// If no null byte, insert one at the chosen length
bytes[len] = 0;
}

let c_str = CStr::from_bytes_until_nul(&bytes).unwrap();
// Verify that count_bytes matches the adjusted length
assert_eq!(c_str.count_bytes(), len);
}

/// Verifies the `CStr::is_empty` method.
#[kani::proof]
#[kani::unwind(33)]
fn check_is_empty() {
const MAX_SIZE: usize = 32;
let string: [u8; MAX_SIZE] = kani::any();
let slice = kani::slice::any_slice_of_array(&string);

// Attempt to create a CStr and handle possible failure
if let Ok(c_str) = CStr::from_bytes_with_nul(slice) {
// Validate the safety of the constructed CStr
assert!(c_str.is_safe(), "Constructed CStr failed the safety invariant.");

// Test the is_empty method
let bytes = c_str.to_bytes(); // Excludes the null terminator
let expected_is_empty = bytes.len() == 0;
assert_eq!(expected_is_empty, c_str.is_empty());
} else {
// If the slice is invalid, confirm that constructing CStr fails
assert!(slice.last() != Some(&0) || slice[..slice.len() - 1].contains(&0));
}
}
}