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

Reintroduce ":safe"/"assert" #284

Closed
LeventErkok opened this issue Nov 8, 2015 · 8 comments
Closed

Reintroduce ":safe"/"assert" #284

LeventErkok opened this issue Nov 8, 2015 · 8 comments
Assignees
Labels
feature request Asking for new or improved functionality
Milestone

Comments

@LeventErkok
Copy link
Contributor

@acfoltzer @brianhuffman

In the good old days of Cryptol 1, there was the :safe command, which checked whether there's div-by-0, index-out-of-bounds, log-of-0, etc,; and violations of any user given asserts. This functionality seems to have evaporated in Cryptol 2: I can neither find the :safe command, nor the assert expression.

The latest github version of SBV comes with sAssert and safe functions, which can be directly used to introduce similar functionality in Cryptol. See here: http://github.com/LeventErkok/sbv/blob/master/Data/SBV/Provers/Prover.hs#L350
and here: http://github.com/LeventErkok/sbv/blob/master/Data/SBV/BitVectors/Model.hs#L1106

An example use case is here: http://github.com/LeventErkok/sbv/blob/master/Data/SBV/Examples/Misc/NoDiv0.hs

I'm intending to do a new SBV release on Hackage soon, containing this functionality. I understand that you guys probably don't have the bandwidth right now to look at this and give me an OK on the API; but we can always make a new SBV release to fit Cryptol's needs when/if you implement the :safe command and its assert counterpart. As usual, send a pull request with the mods you need!

@LeventErkok LeventErkok changed the title Reintroduce ":safe" Reintroduce ":safe"/"assert" Nov 8, 2015
@LeventErkok
Copy link
Contributor Author

SBV 5.4 is now out on hackage, with sAssert and safe

@acfoltzer
Copy link
Contributor

Thanks! We might not be able to take advantage of the new features for a while, but I've got a PR incoming to keep 7.8 on life support

@dylanmc dylanmc added this to the Cryptol 2.4 milestone Mar 9, 2016
@acfoltzer acfoltzer modified the milestones: Cryptol 2.5, Cryptol 2.4 Jun 29, 2016
@robdockins
Copy link
Contributor

With the new evaluator in the IO monad, it probably makes sense to revisit this soon.

@robdockins robdockins marked this as a duplicate of #70 Jul 27, 2017
@atomb atomb modified the milestones: Cryptol 2.5, Cryptol 2.6 Feb 5, 2018
@atomb atomb removed this from the Cryptol 2.6 milestone Apr 16, 2018
@atomb atomb added this to the 2.7.0 milestone Apr 1, 2019
@atomb atomb modified the milestones: 2.7.0, 2.8.0 Apr 16, 2019
@brianhuffman brianhuffman added the feature request Asking for new or improved functionality label Jun 27, 2019
@atomb atomb modified the milestones: 2.8.0, 2.9.0 Aug 28, 2019
@atomb atomb removed this from the 3.0.0 milestone Oct 8, 2019
@robdockins
Copy link
Contributor

As part of the refactoring I'm doing in #684, I'm making the internal changes necessary to compute safety conditions during symbolic evaluation. The result of a symbolic evaluation will either be an error (if all inputs obviously cause an error) or a pair of a safety predicate and a value.

At this point, the slightly tricky bit is to figure out what to do with them, from a UI perspective. How should safety predicates interact with :sat and :prove? Should the behavior be configurable? Do we want a separate :safe command, as suggested originally? etc.

@robdockins
Copy link
Contributor

After thinking about this for a bit, here's my proposal. Let's add a new :set option (name suggestions?) that controls if we pay attention to safety conditions. If set, we add the safety conditions as assumptions for :sat queries and add them to the goal for :prove queries. If unset, they are ignored (the current behavior). I think the default should be for this option to be on.

We can also add a separate :safe query which just attempts to prove the safety condition associated with a term.

We can also add to the Prelude:

assert : {a, n} Bit -> [n][8] -> a -> a
assert pred msg x = if pred then x else error msg

Alternately, make assert a primitive with essentially the same semantics.

@atomb atomb assigned robdockins and unassigned atomb May 4, 2020
@atomb atomb added this to the 2.9.0 milestone May 4, 2020
@brianhuffman
Copy link
Contributor

When printing a counterexample from :check or :prove, we should not display it as foo <args> = False if the counterexample is instead a violation of the safety predicate. Rather, we should display something like foo <args> = <run-time error>.

@robdockins
Copy link
Contributor

As of 60dcbd1 both SBV and What4 backends automatically include safety predicates as part of :prove and :sat statements.

We still need to implement the user-configurable settings that control this behavior, and improve the output generated when displaying counterexamples.

@robdockins robdockins mentioned this issue Jun 18, 2020
@robdockins
Copy link
Contributor

Fixed via #770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Asking for new or improved functionality
Projects
None yet
Development

No branches or pull requests

6 participants