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

Bug in proofs #279

Open
BLepers opened this issue Dec 9, 2016 · 10 comments
Open

Bug in proofs #279

BLepers opened this issue Dec 9, 2016 · 10 comments

Comments

@BLepers
Copy link

BLepers commented Dec 9, 2016

Pretty serious bug, or did I miss something?

import leon.collection._
import leon.lang._
import scala.Any

object Scheduler {
   def a(i: BigInt):BigInt = {
      i - 1;
   } ensuring(res => b(i) && res == 2)

   def b(i: BigInt): Boolean = {
      val c = a(i);
      (i == 1) ==> (c == 0)
   }.holds
}

(This code verifies on b3ad5fc, but shoudn't because a doesn't always return 2...)

@samarion
Copy link
Member

samarion commented Dec 9, 2016 via email

@larsrh
Copy link
Contributor

larsrh commented Dec 9, 2016

Strangely enough the Isabelle solver thinks a and b are terminating. Leon claims that b(0) doesn't terminate but Isabelle evaluates that to false. (I'm guessing because i == 1 evaluates to false, so the conclusion is never actually executed.)

@BLepers
Copy link
Author

BLepers commented Dec 9, 2016

Ok... Would it be possible to give an error in that case? It is a bit strange to see that this code passes verification :)

@samarion
Copy link
Member

samarion commented Dec 9, 2016 via email

@larsrh
Copy link
Contributor

larsrh commented Dec 9, 2016

It turns out my assessment was wrong. Here's what Isabelle sees:

fun a :: "int ⇒ int" and b :: "int ⇒ bool" where
"a i = i - 1" |
"b i = (i = 1 ⟶ a i = 0)"

Hence, the function definitions themselves are definitely terminating, because there is no call to b in a (the Isabelle backend will – by default – not include the pre- and postconditions in the function definition). If the functions are annotated with @isabelle.fullBody, then Isabelle sees the call to b and correctly refuses to define the function. I'm unsure what to make of all this.

@larsrh
Copy link
Contributor

larsrh commented Dec 9, 2016

In essence, the question is: How do you deal with pre- and postconditions introducing complications in the call graph?

@larsrh
Copy link
Contributor

larsrh commented Dec 9, 2016

By the way, the Isabelle backend is supposed to always give sound results even without --termination switched on. So there is definitely an issue here somewhere.

@vkuncak
Copy link
Contributor

vkuncak commented Dec 12, 2016

I think that @BLepers is not specifically talking about the Isabelle back end. Termination checker should be on by default and turning it off explicitly should be allowed but known to cause soundness issues if the functions are not terminating. @BLepers , let us know what termination checker reports and if it is too weak in some cases.

@BLepers
Copy link
Author

BLepers commented Dec 12, 2016

The termination checker says that a does not finish:

[  Info  ] ║ apply       ✓ Terminates (Non-recursive)                                           
[  Info  ] ║ apply       ✓ Terminates (Non-recursive)                                          
[  Info  ] ║ a           ✗ Non-terminating for call: a(0)                                     
[  Info  ] ║ b           ✗ Calls non-terminating functions a 

So I guess it makes sense that the verification phase is not sound for that example (even though it should probably fail by default as Viktor said because errors like that can easily be made).

What I find a bit confusing in that example is that a() never "really" calls b(). I.e., if you run the applicative code without the "ensuring", there is no infinite loop. (Basically I just tried to separate a bit the proof logic - b() - and the applicative code - a()).

@samarion
Copy link
Member

samarion commented Dec 12, 2016

The guarantee Leon is giving you when it says "valid" is that if you run the code, every time you encounter a contract, it won't evaluate to false. In this case, Leon is telling you the contract of a() (namely b()) will never evaluate to false (which is true since it won't terminate). However, you didn't guarantee that the contract would evaluate to true, which is typically what you would want when you say something is verified.

Note that with termination (and a few other checks that guarantee the program won't crash), never evaluating to false is equivalent to always evaluating to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants