Skip to content

Commit

Permalink
Z3 default tactic (#1527)
Browse files Browse the repository at this point in the history
* Use scVectorReduced in reconstructArgTerm.

* Add support for user-provided Z3 tactics.

* Bump What4.

* Bump What4.

* Update src/SAWScript/Prover/What4.hs

Co-authored-by: Ryan Scott <[email protected]>

* Add test.

* Fix documentation.

Co-authored-by: Ryan Scott <[email protected]>
  • Loading branch information
andreistefanescu and RyanGlScott authored Dec 2, 2021
1 parent a87ed23 commit 6bb79b6
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
during the LLVM and X86 Crucible symbolic execution. This is used for
path-sat checks, and sat checks when applying overrides.

* New command `w4_unint_z3_using` like `w4_unint_z3`, but use the given Z3
tactic.


# Version 0.9

## New Features
Expand Down
2 changes: 1 addition & 1 deletion deps/what4
13 changes: 13 additions & 0 deletions intTests/test0071_w4_unint_z3_using/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enable_experimental;

let {{
bvToInteger : [1024] -> Integer
bvToInteger = toInteger
bvFromInteger : Integer -> [1024]
bvFromInteger = fromInteger
}};

prove_print
(w4_unint_z3_using "qfnia" ["bvToInteger", "bvFromInteger"])
{{ \(x : [1024]) -> bvFromInteger ((if (bvToInteger x) <= (bvToInteger (x * x)) then 1 else (bvToInteger x)) * (bvToInteger x)) == bvFromInteger ((if (bvToInteger x) <= (bvToInteger (x * x)) then (bvToInteger x) else (bvToInteger x) * (bvToInteger x))) }};

3 changes: 3 additions & 0 deletions intTests/test0071_w4_unint_z3_using/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -e

$SAW test.saw
2 changes: 1 addition & 1 deletion saw-core-what4/src/Verifier/SAW/Simulator/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ reconstructArgTerm atrm sc ts =
pure (x, ts1)
ArgTermVector ty ats ->
do (xs, ts1) <- parseList ats ts0
x <- scVector sc ty xs
x <- scVectorReduced sc ty xs
return (x, ts1)
ArgTermUnit ->
do x <- scUnitValue sc
Expand Down
3 changes: 3 additions & 0 deletions src/SAWScript/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ w4_unint_boolector = wrapW4Prover Prover.proveWhat4_boolector
w4_unint_z3 :: [String] -> ProofScript ()
w4_unint_z3 = wrapW4Prover Prover.proveWhat4_z3

w4_unint_z3_using :: String -> [String] -> ProofScript ()
w4_unint_z3_using tactic = wrapW4Prover (Prover.proveWhat4_z3_using tactic)

w4_unint_cvc4 :: [String] -> ProofScript ()
w4_unint_cvc4 = wrapW4Prover Prover.proveWhat4_cvc4

Expand Down
36 changes: 20 additions & 16 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ primitives = Map.fromList
(pureVal goal_eval)
Current
[ "Evaluate the proof goal to a first-order combination of primitives."
, "Leave the given names, as defined with 'define', as uninterpreted." ]
, "Leave the given names as uninterpreted." ]

, prim "beta_reduce_goal" "ProofScript ()"
(pureVal beta_reduce_goal)
Expand Down Expand Up @@ -1495,21 +1495,21 @@ primitives = Map.fromList
(pureVal proveUnintZ3)
Current
[ "Use the Z3 theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "unint_cvc4" "[String] -> ProofScript ()"
(pureVal proveUnintCVC4)
Current
[ "Use the CVC4 theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "unint_yices" "[String] -> ProofScript ()"
(pureVal proveUnintYices)
Current
[ "Use the Yices theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "sbv_boolector" "ProofScript ()"
Expand Down Expand Up @@ -1541,21 +1541,21 @@ primitives = Map.fromList
(pureVal proveUnintZ3)
Current
[ "Use the Z3 theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "sbv_unint_cvc4" "[String] -> ProofScript ()"
(pureVal proveUnintCVC4)
Current
[ "Use the CVC4 theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "sbv_unint_yices" "[String] -> ProofScript ()"
(pureVal proveUnintYices)
Current
[ "Use the Yices theorem prover to prove the current goal. Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "offline_aig" "String -> ProofScript ()"
Expand Down Expand Up @@ -1646,21 +1646,28 @@ primitives = Map.fromList
(pureVal w4_unint_z3)
Current
[ "Prove the current goal using What4 (Z3 backend). Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "w4_unint_z3_using" "String -> [String] -> ProofScript ()"
(pureVal w4_unint_z3_using)
Current
[ "Prove the current goal using What4 (Z3 backend) using the given"
, "Z3 tactic. Leave the given list of names as uninterpreted."
]

, prim "w4_unint_yices" "[String] -> ProofScript ()"
(pureVal w4_unint_yices)
Current
[ "Prove the current goal using What4 (Yices backend). Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "w4_unint_cvc4" "[String] -> ProofScript ()"
(pureVal w4_unint_cvc4)
Current
[ "Prove the current goal using What4 (CVC4 backend). Leave the"
, "given list of names, as defined with 'define', as uninterpreted."
, "given list of names as uninterpreted."
]

, prim "w4_abc_aiger" "ProofScript ()"
Expand Down Expand Up @@ -1691,24 +1698,21 @@ primitives = Map.fromList
(pureVal offline_w4_unint_z3)
Current
[ "Write the current goal to the given file using What4 (Z3 backend) in"
," SMT-Lib2 format. Leave the given list of names, as defined with"
, "'define', as uninterpreted."
," SMT-Lib2 format. Leave the given list of names as uninterpreted."
]

, prim "offline_w4_unint_yices" "[String] -> String -> ProofScript ()"
(pureVal offline_w4_unint_yices)
Current
[ "Write the current goal to the given file using What4 (Yices backend) in"
," SMT-Lib2 format. Leave the given list of names, as defined with"
, "'define', as uninterpreted."
," SMT-Lib2 format. Leave the given list of names as uninterpreted."
]

, prim "offline_w4_unint_cvc4" "[String] -> String -> ProofScript ()"
(pureVal offline_w4_unint_cvc4)
Current
[ "Write the current goal to the given file using What4 (CVC4 backend) in"
," SMT-Lib2 format. Leave the given list of names, as defined with"
, "'define', as uninterpreted."
," SMT-Lib2 format. Leave the given list of names as uninterpreted."
]

, prim "split_goal" "ProofScript ()"
Expand Down
21 changes: 19 additions & 2 deletions src/SAWScript/Prover/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module SAWScript.Prover.What4 where
import Control.Lens ((^.))
import Data.Set (Set)
import qualified Data.Map as Map
import qualified Data.Text as Text
import System.IO

import Verifier.SAW.SharedTerm
Expand Down Expand Up @@ -88,7 +89,7 @@ proveWhat4_sym ::
proveWhat4_sym solver un hashConsing t =
getSharedContext >>= \sc -> io $
do sym <- setupWhat4_sym hashConsing
proveWhat4_solver solver sym un sc t
proveWhat4_solver solver sym un sc t (return ())

proveExportWhat4_sym ::
SolverAdapter St ->
Expand Down Expand Up @@ -125,6 +126,20 @@ proveWhat4_stp = proveWhat4_sym stpAdapter
proveWhat4_yices = proveWhat4_sym yicesAdapter
proveWhat4_abc = proveWhat4_sym externalABCAdapter

proveWhat4_z3_using ::
String {- ^ Solver tactic -} ->
Set VarIndex {- ^ Uninterpreted functions -} ->
Bool {- ^ Hash-consing of What4 terms -}->
Prop {- ^ A proposition to be proved -} ->
TopLevel (Maybe CEX, SolverStats)
proveWhat4_z3_using tactic un hashConsing t =
getSharedContext >>= \sc -> io $
do sym <- setupWhat4_sym hashConsing
proveWhat4_solver z3Adapter sym un sc t $
do z3TacticSetting <- getOptionSetting z3Tactic $ getConfiguration sym
_ <- setOpt z3TacticSetting $ Text.pack tactic
return ()

proveExportWhat4_z3, proveExportWhat4_boolector, proveExportWhat4_cvc4,
proveExportWhat4_dreal, proveExportWhat4_stp, proveExportWhat4_yices ::
Set VarIndex {- ^ Uninterpreted functions -} ->
Expand Down Expand Up @@ -176,11 +191,13 @@ proveWhat4_solver :: forall st t ff.
Set VarIndex {- ^ Uninterpreted functions -} ->
SharedContext {- ^ Context for working with terms -} ->
Prop {- ^ A proposition to be proved/checked. -} ->
IO () {- ^ Extra setup actions -} ->
IO (Maybe CEX, SolverStats)
-- ^ (example/counter-example, solver statistics)
proveWhat4_solver solver sym unintSet sc goal =
proveWhat4_solver solver sym unintSet sc goal extraSetup =
do
(argNames, bvs, lit, stats) <- setupWhat4_solver solver sym unintSet sc goal
extraSetup

-- log to stdout
let logger _ str = putStrLn str
Expand Down

0 comments on commit 6bb79b6

Please sign in to comment.