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

Type limits for unsigned integer missing when using check_overflows = false #1215

Open
Patrick-6 opened this issue Oct 25, 2022 · 3 comments · Fixed by #1281
Open

Type limits for unsigned integer missing when using check_overflows = false #1215

Patrick-6 opened this issue Oct 25, 2022 · 3 comments · Fixed by #1281
Labels
enhancement New feature or request error-reporting Something needs to be fixed in the error reporting

Comments

@Patrick-6
Copy link
Contributor

#[requires(0 <= i)] generates a warning: [unused_comparisons] comparison is useless due to type limits., but removing it with check_overflows = false will cause the verification to fail:
[Prusti internal error] Prusti encountered an unexpected internal error
Details: unregistered verification error: [application.precondition:assertion.false; 0] Precondition of function lookup_pure__$TY$__Slice$i64$i64$Slice$i64$$int$$$int$ might not hold. Assertion 0 <= _3 might not hold. (@0.0).

Additionally, the error appears on line 1 column 1 in the lib.rs file, not in the file where the error happened.

use prusti_contracts::*;

// #[requires(0 <= i)]
#[requires(i < s.len())]
fn test(s: &[i64], i: usize) -> i64 {
    s[i]
}
@fpoli fpoli added error-reporting Something needs to be fixed in the error reporting enhancement New feature or request labels Oct 28, 2022
@fpoli
Copy link
Member

fpoli commented Oct 28, 2022

The [unused_comparisons] warning is wrong and should be suppressed in the macro expansion of prusti_contracts::requires.

The [Prusti internal error] is a bug in the backtranslation of verification errors. Either the expected error should be something like [Prusti verification error] Index of array access might be negative, or we should assume the type bounds of usize so that no error is reported. (Prusti was doing the latter at some point in the past, but we apparently lost that feature in a refactoring.)

@Patrick-6
Copy link
Contributor Author

This might also be related to the backtranslation of verification errors:

#[ensures(s[s.len()] == 5)]
fn test_1(s: &[i64]) {}

This results in [Prusti: verification error] postcondition might not hold. on s[s.len()].
If you put the same code in the body of a function you get the correct error message:

fn test_2(s: &[i64]) -> i64 {
    s[s.len()]
}

[Prusti: verification error] the array or slice index may be out of bounds.

Patrick-6 added a commit to Patrick-6/prusti-dev that referenced this issue Jan 17, 2023
Aurel300 pushed a commit that referenced this issue Jan 26, 2023
* Addresses #1215

* Skip memchr crate

* Add more tests

* Removed unneeded environment variable

* Skip failing crates

* Fix typo

* Skip failing crates

* Temporarily disable fail_fast

* Switch from native-tls to rustls

* Re-enable skipped crates

* Skip failing crates

* Skip failing crates

* disable failing crate

* Re-enable fail_fast

* Print errors with Display

* Disable encode_unsigned_num_constraints

* Fix typo in environment variable

* Remove unnecessairy compile flags
@Patrick-6
Copy link
Contributor Author

I don't think this issue is completely resolved, if a user sets encode_unsigned_num_constraint = false, they will still get the unregistered verification error from the example code, or the unused comparisons warning after manually adding 0 <= i.

@Aurel300 Aurel300 reopened this Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request error-reporting Something needs to be fixed in the error reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants