You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Diverging modifies clauses cause unsound vacuity #2909
$ kani contract_loop.rs -Zfunction-contracts
Kani Rust Verifier 0.51.0 (standalone)
warning: unreachable expression
--> contract_loop.rs:4:5
|
3 | loop {};
| ------- any code following this expression is unreachable
4 | 2
| ^ unreachable expression
|
= note: `#[warn(unreachable_code)]` on by default
warning: 1 warning emitted
warning: unreachable expression
--> contract_loop.rs:4:5
|
3 | loop {};
| ------- any code following this expression is unreachable
4 | 2
| ^ unreachable expression
|
= note: `#[warn(unreachable_code)]` on by default
warning: Found the following unsupported constructs:
- caller_location (1)
- foreign function (2)
Verification will fail if one or more of these constructs is reachable.
See https://model-checking.github.io/kani/rust-feature-support.html for more details.
warning: 2 warnings emitted
Checking harness check_foo...
CBMC 5.95.1 (cbmc-5.95.1)
CBMC version 5.95.1 (cbmc-5.95.1) 64-bit x86_64 linux
Reading GOTO program from file /home/ubuntu/examples/contract_loop__RNvCsiqQmiVO2X69_13contract_loop9check_foo.out
...
SUMMARY:
** 0 of 1312 failed (1 unreachable)
VERIFICATION:- SUCCESSFUL
Verification Time: 1.7906353s
Complete - 1 successfully verified harnesses, 0 failures, 1 total.
And with a divergent while loop as well if loop contract synthesis is enabled:
#[kani::ensures(result == 1)]fnfoo() -> i32{let i = 0;while i < 10{}2}#[kani::proof_for_contract(foo)]fncheck_foo(){let _ = foo();}
$ kani contract_loop.rs -Zfunction-contracts --synthesize-loop-contracts --enable-unstable
Kani Rust Verifier 0.51.0 (standalone)
warning: Found the following unsupported constructs:
- caller_location (1)
- foreign function(2)
Verification will fail if one or more of these constructs is reachable.
See https://model-checking.github.io/kani/rust-feature-support.html for more details.
warning: 1 warning emitted
Running loop contract synthesizer.
warning: This process may not terminate.
warning: Loop-contracts synthesizer is not compatible with unwinding bounds. Unwind bounds will be ignored.
Checking harness check_foo...
CBMC 5.95.1 (cbmc-5.95.1)
CBMC version 5.95.1 (cbmc-5.95.1) 64-bit x86_64 linux
Reading GOTO program from file /home/ubuntu/examples/contract_loop__RNvCsiqQmiVO2X69_13contract_loop9check_foo.out
...
SUMMARY:
** 0 of 1318 failed (1 unreachable)
VERIFICATION:- SUCCESSFUL
Verification Time: 1.8091615s
Complete - 1 successfully verified harnesses, 0 failures, 1 total.
Apparently, CBMC replaces infinite loops with assume(false). This is an excerpt from the CBMC output:
Starting Bounded Model Checking
replacing self-loop at file contract_loop.rs line 5 column 5 function foo_wrapper_493980 by assume(FALSE)
no unwinding assertion will be generated for self-loop at file contract_loop.rs line 5 column 5 function foo_wrapper_493980
Apparently, CBMC replaces infinite loops with assume(false). This is an excerpt from the CBMC output:
Starting Bounded Model Checking
replacing self-loop at file contract_loop.rs line 5 column 5 function foo_wrapper_493980 by assume(FALSE)
no unwinding assertion will be generated for self-loop at file contract_loop.rs line 5 column 5 function foo_wrapper_493980
This sounds like UB. C compilers also assume that you never write infinite loops.
@JustusAdam ,
Could you provide the context in which this error can be reproduced? Building kani on your fork and then running it on this seems to fail.
Oh I made a mistake. I thought this issue was from the old assigns clause implementation, not modifies (I also observed vacuous verifications for that assigns clause though). I don't recall the example I tried this on, sorry.
I suggest that we close this issue once #3223 is merged and @qinheping could investigate the example from #2909 (comment), which it seems to be more related to loop synthesis, as a separate issue. @zhassan-aws@tautschnig any thoughts?
Activity
[-]Diverging `modifies` clauses cause vacuity[/-][+]Diverging `modifies` clauses cause unsound vacuity[/+]`modifies` Clauses for Function Contracts (#2800)
celinval commentedon Mar 25, 2024
Can you please clarify what you mean here? Maybe an example with the current output would be helpful. Will the overall verification succeed?
jsalzbergedu commentedon May 30, 2024
An example of code that verifies vacuously, found with the help of @pi314mm :
jsalzbergedu commentedon May 30, 2024
A note: Justus mentioned over email that code like this may have been the original source of the bug, but it was bugged in an earlier version.
https://github.com/JustusAdam/kani/blob/10208dc9f99e8bb5cd80d7b1bb0be69334906388/tests/expected/function-contract/fixme_vec_map_example.rs#L111
zhassan-aws commentedon May 30, 2024
This can be reproduced without
modifiesclauses as well, e.g.:zhassan-aws commentedon May 30, 2024
And with a divergent
whileloop as well if loop contract synthesis is enabled:$ kani contract_loop.rs -Zfunction-contracts --synthesize-loop-contracts --enable-unstable Kani Rust Verifier 0.51.0 (standalone) warning: Found the following unsupported constructs: - caller_location (1) - foreign function (2) Verification will fail if one or more of these constructs is reachable. See https://model-checking.github.io/kani/rust-feature-support.html for more details. warning: 1 warning emitted Running loop contract synthesizer. warning: This process may not terminate. warning: Loop-contracts synthesizer is not compatible with unwinding bounds. Unwind bounds will be ignored. Checking harness check_foo... CBMC 5.95.1 (cbmc-5.95.1) CBMC version 5.95.1 (cbmc-5.95.1) 64-bit x86_64 linux Reading GOTO program from file /home/ubuntu/examples/contract_loop__RNvCsiqQmiVO2X69_13contract_loop9check_foo.out ... SUMMARY: ** 0 of 1318 failed (1 unreachable) VERIFICATION:- SUCCESSFUL Verification Time: 1.8091615s Complete - 1 successfully verified harnesses, 0 failures, 1 total.zhassan-aws commentedon May 30, 2024
One way to fix that is to fail if the post-condition is unreachable. In the cases above, the check is indeed reported as unreachable:
celinval commentedon May 31, 2024
Why isn't the unwinding assertion failing in this case?
zhassan-aws commentedon May 31, 2024
Apparently, CBMC replaces infinite loops with assume(false). This is an excerpt from the CBMC output:
zhassan-aws commentedon May 31, 2024
But in the case of using the loop synthesizer, one has to prove that the loop terminates for the loop abstraction to be sound.
JustusAdam commentedon May 31, 2024
This sounds like UB. C compilers also assume that you never write infinite loops.
jsalzbergedu commentedon Jun 3, 2024
@JustusAdam ,
Could you provide the context in which this error can be reproduced? Building kani on your fork and then running it on this seems to fail.
tautschnig commentedon Jun 4, 2024
#3223 should address most of what is discussed here, except #2909 (comment) requires further investigation.
JustusAdam commentedon Jun 4, 2024
Oh I made a mistake. I thought this issue was from the old
assignsclause implementation, notmodifies(I also observed vacuous verifications for thatassignsclause though). I don't recall the example I tried this on, sorry.feliperodri commentedon Jun 5, 2024
I suggest that we close this issue once #3223 is merged and @qinheping could investigate the example from #2909 (comment), which it seems to be more related to loop synthesis, as a separate issue. @zhassan-aws @tautschnig any thoughts?
Do not turn trivially diverging loops into assume(false) (#3223)