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

Simple automation for signed inequalities. #1836

Open
scuellar opened this issue Mar 7, 2023 · 4 comments
Open

Simple automation for signed inequalities. #1836

scuellar opened this issue Mar 7, 2023 · 4 comments
Labels
subsystem: heapster Issues specifically related to memory verification using Heapster type: enhancement Issues describing an improvement to an existing feature or capability
Milestone

Comments

@scuellar
Copy link
Collaborator

scuellar commented Mar 7, 2023

In array_inequlities I propose a strategy to solve signed inequalities without overflow. Luckily, there should not be any overflow in any signed arithmetic generated by LLVM. The idea is straight forward:

  1. Translate the signed bit vector inequalities into Z inequalities, using modulo arithmetic.
  2. Remove the module (with the subgoal that there is no overflow)
  3. Solve the inequality in the Z world
  4. Your subgoals are signed bit vector inequalities, rinse and repeat.

The current file shows just a prototype of what can be achieved, but it does remove a lot of the burden from the prover. I leave it to discussion if this is a worthwhile direction.

The benefits of this strategy are as follows:

  • If the tactic fails, the unproven goal will be a proof that something doesn't overflow. You probably forgot to add that invariant!
  • This can easily be extended to support unsigned bit vectors, for cases without overflow. You can further support overflow if you do some magic with the modulo arithmetic, but this part will be trickier.
  • It is relatively simple, and only relies on the well supported lia for Zs.
  • It should support all vector lengths (e.g. 64, 32, 16, etc...) at the same time.

Cons:

  • It has many inefficiencies although most can be overcome with some engineering. Ultimately, the most efficient approach is to do the rewrite during code generation.
  • Runs on Ltac which is notoriously difficult to debug.
@scuellar scuellar added type: enhancement Issues describing an improvement to an existing feature or capability subsystem: heapster Issues specifically related to memory verification using Heapster labels Mar 7, 2023
@RyanGlScott
Copy link
Contributor

Can you elaborate on what you mean by "the most efficient approach is to do the rewrite during code generation"?

@scuellar
Copy link
Collaborator Author

scuellar commented Mar 7, 2023

Can you elaborate on what you mean by "the most efficient approach is to do the rewrite during code generation"?

Suppose you have a program P, with a variety of Bvs arithmetic equations (perhaps for different lengths).

The current semantics allows for signed overflow, which is a valid refinement of LLVM semantics, but not the only one. If you instead interpret signed overflow as undefined, then you can always refine P by a program P_Z which only does arithmetic on Z. Ideally the refinement P ~ P_Z can be discharged by saw. Then the coq proofs are only dealing with Z which is easier, with the support of the standard library. On the other hand, bit operations (e.g. shr, bitwise and) are a bit harder, so it's a tradeoff.

@RyanGlScott
Copy link
Contributor

RyanGlScott commented Mar 7, 2023

Just to make this a bit more concrete, are you saying that you would want to change Heapster's code generation such that all of the functions take proof arguments of, say, type (x < y)%Z instead of isBvult w x y? (atBVVec is a function of this shape that comes to mind.)

@eddywestbrook
Copy link
Contributor

I'm not quite sure we would want to change the Heapster specification extraction in this way. Given that, it sounds like the approach described above could be a good way to go, at least as far as I understand it. Maybe we could discuss in more detail at some point in person, @scuellar?

@sauclovian-g sauclovian-g added this to the Someday milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subsystem: heapster Issues specifically related to memory verification using Heapster type: enhancement Issues describing an improvement to an existing feature or capability
Projects
None yet
Development

No branches or pull requests

4 participants