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

Strengthen Symbolic Execution of % #133

Closed
weaversa opened this issue Oct 23, 2014 · 4 comments
Closed

Strengthen Symbolic Execution of % #133

weaversa opened this issue Oct 23, 2014 · 4 comments
Assignees
Labels
bug Something not working correctly
Milestone

Comments

@weaversa
Copy link
Collaborator

Consider gcd:

gcd : [8] -> [8] -> [8]
gcd a b = if(b == 0) then a
          else gcd b (a%b)

We can use :exhaust to prove the following property about gcd, but :prove never returns.

Main> :exhaust \x -> gcd 0 x == x
Using exhaustive testing.
passed 256 tests.
Q.E.D.
Main> :prove \x -> gcd 0 x == x
<break>

The termination condition of gcd is that b = 0. Since, for the above proof, b is symbolic, both branches of the if statement are followed because we can't determine whether or not b is 0. The second time through the recursion, a takes on the symbolic value of b, and now b takes on 0%b, which (as seen below) is 0, so the recursion should terminate.

Main> :prove \x -> 0%(x:[8]) == 0
Q.E.D.

I figure that the implementation of % in the symbolic execution engine could to be strengthened by ensuring that constant values are propagated when available, helping avoid symbolic termination problems.

@brianhuffman
Copy link
Contributor

Note that this example works fine with :set iteSolver=on.

The SBV library implements various optimizations of this kind, e.g. 0 * x = 0, 0 + x = x. It should be a simple matter to add a special-case rule for sRem 0 x = 0 to the SBV library, and contribute the patch upstream.

@weaversa
Copy link
Collaborator Author

I don't know the list of rules SBV maintains, but it's also the case that sRem x 1 = 0.

@brianhuffman brianhuffman self-assigned this Oct 24, 2014
@LeventErkok
Copy link
Contributor

Added a few rules to SBV that should address these cases: LeventErkok/sbv@f2bb5a6

In reality, I find such "optimizations" to hardly ever pay off. As Brian mentioned, using 'iteSolver' (or sBranch in SBV parlance) is probably the right thing to do in such cases.

brianhuffman pushed a commit that referenced this issue Nov 5, 2014
Renamed old "issue133" to "trac133", indicating that it uses a different
numbering system.
@brianhuffman
Copy link
Contributor

Fixed in 80ec38f, which included SBV changes from LeventErkok/sbv@f2bb5a6.

@kiniry kiniry added the bug Something not working correctly label Dec 3, 2014
@kiniry kiniry added this to the Cryptol 2.2 milestone Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something not working correctly
Projects
None yet
Development

No branches or pull requests

4 participants