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

Function Contracts: Modifies for str #3349

Open
pi314mm opened this issue Jul 16, 2024 · 0 comments
Open

Function Contracts: Modifies for str #3349

pi314mm opened this issue Jul 16, 2024 · 0 comments
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. Z-Contracts Issue related to code contracts

Comments

@pi314mm
Copy link
Contributor

pi314mm commented Jul 16, 2024

We would like to be able to verify mutable string references in kani contracts. In particular, the following test case should pass:

// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts

// Test that modifies a string

#[kani::requires(x == "aaa")]
#[kani::modifies(x)]
#[kani::ensures(|_| x == "AAA")]
fn to_upper(x: &mut str) {
    x.make_ascii_uppercase();
}

#[kani::proof_for_contract(to_upper)]
fn harness() {
    let mut s = String::from("aaa");
    let x: &mut str = s.as_mut_str();
    to_upper(x);
}

There seems to be an issue with the current compilation strategy for str within the modifies clause which should be properly investigated (#3295). The current test case (tests/expected/function-contract/modifies_fat_pointer/string_rewrite_ignore.rs in the PR) should be changed from being ignored to having a valid output.

In addition, we would like to test the kani::internal::write_any_str function. We want to create a friendly user experience that tells the user that this functionality doesn't exist due to utf8 verification issues. The test case for this would look like the one above, but additionally uses a stub_for_contract macro to force usage of the kani::internal::write_any_str function.

If possible, we should add utf8 verification to allow for the kani::internal::write_any_str function to work properly. The concerns are not of whether this is possible, but whether this is fast enough to reasonably verify in cbmc.

@pi314mm pi314mm added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Jul 16, 2024
@pi314mm pi314mm added this to the Function Contracts milestone Jul 16, 2024
@tautschnig tautschnig added the Z-Contracts Issue related to code contracts label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. Z-Contracts Issue related to code contracts
Projects
None yet
Development

No branches or pull requests

2 participants