-
Notifications
You must be signed in to change notification settings - Fork 263
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
Unsoundness with Arrays in JBMC #8428
Comments
By chance, I finally found out what is the problem. Simplified test file: public class Unsound {
public static void foo(int[] a) {
if (a != null && a.length > 5) {
assert false;
}
}
} Then: javac -g Unsound.java
jbmc "Unsound.foo:([I)V" Result:
But with jbmc "Unsound.foo:([I)V" --max-nondet-array-length 30 Apparently, I would suggest to fix the unsoundness or give a proper warning in the verification result, that array length <= 5 is assumed. For soundness, one could add some |
Correct. This is currently quite intransparent. It would be better to clearly display the configured bound in the output to avoid such surprises.
Yes the choice has been made to have bounds by default because JBMC is not going to terminate on almost any program otherwise.
What specifically do you have in mind how this should work? |
I was thinking to leave the length unconstrained until the first access of an array element. Only then, the assumption length <= 5 is needed. For my In some cases, it already follows from the path condition that length <= 5, so we could also prove the assumption at that state. Example: public class ArrayLengthExample {
public static int bar(int[] a, int i) {
if (a.length == 4 && 0 <= i && i < 4) {
return a[i];
}
return -1;
}
} Here the verification with But I could imagine that this would be hard to implement. |
After sleeping over this, I realized that there is a better solution. For any nondet array, JBMC just creates New suggestion:
Insertion sort example: public void sort (int[] a, right) {
for (int i = 0; i < right; i++) {
// access only a[0],...,a[i]
}
} For any unwind bound smaller This would also make a modified public class Unsound {
public static void foo(int[] a) {
if (a != null && a.length > 5) {
a[0] = 3;
assert false;
}
}
} For the access There is also the option to completely change how arrays are modeled to achieve soundness without a |
diffblue#8428" This reverts commit c974324.
With 511be72 I found out that completely resolving the unsoundness issue is actually not so complicated:
Apparently, the trace output makes use of For my examples, the run-time was not much affected. I called it quickfix, because it completely ignores |
add documentation of default for --max-nondet-array-length, see #8428
Closed with #8432 |
Environment
CBMC version: 6.1.1 (cbmc-6.1.1-34-gc193c276ab)
Operating system: Linux 5.15.0-119-generic #129~20.04.1-Ubuntu SMP x86_64
Explanation
In ExampleTraceAssertion.zip, I have two files
Example.java
andexample.c
. I am checkingexample()
in both versions.Both versions should lead to
VERIFICATION FAILED
because the assertion in line 14 (reached fromexample()
) is counter satisfiable. However the jbmc version reportsSUCCESS
.Exact command line resulting in the issue:
Expected (JBMC version)
The assertion verification should fail:
What happened instead (JBMC version)
But instead jbmc reports false success:
Variation I as expected
cbmc with
example.c
gives the expected result:Variation II as expected
jbmc with a concrete array
int[] a = { 413, 134, 1, 41, -32, 0, -500, 413, 1 };
gives the expected result. Just comment out that line and comment inint[] a = a2;
.Variation III as expected
Change
assert(index != 18)
toassert(index != 17)
in line 14 ofExample.java
.Further remarks
This is a simplified excerpt of one of my retracing examples, DualPivotQuicksort from https://github.com/ProRunVis/ProRunVis-examples. I can show you the full example if needed.
The text was updated successfully, but these errors were encountered: