Skip to content

Commit ecab7ea

Browse files
authored
Support specifying ProofScripts during x86 verification (#753)
* Support specifying ProofScripts during x86 verification * Change .travis.yml s2n commit to HEAD of saw-travis-branch
1 parent 80fb2d0 commit ecab7ea

File tree

7 files changed

+37
-29
lines changed

7 files changed

+37
-29
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- mkdir -p s2n/test-deps/saw/bin
8585
- cp bin/saw s2n/test-deps/saw/bin
8686
- cd s2n
87-
- git checkout 28ea0fea9ab7dc710c9424d9b869b39ca3804d79
87+
- git checkout cd7282102bf5e65cc8b324c4127c7943c71c8513
8888
before_script:
8989
- export TESTS=sawHMAC
9090
script:

intTests/test_llvm_x86_01/test.saw

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let foo_setup = do {
1111
val <- crucible_fresh_var "val'" (llvm_int 64);
1212
crucible_points_to ptr (crucible_term val);
1313
};
14-
foo_method_spec <- crucible_llvm_verify_x86 m "./test" "foo" [] false foo_setup;
14+
foo_method_spec <- crucible_llvm_verify_x86 m "./test" "foo" [] false foo_setup w4;
1515

1616
let bar_setup = do {
1717
crucible_execute_func [];

intTests/test_llvm_x86_02/test.saw

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ let increment_setup = do {
1111
crucible_points_to ptr (crucible_term valprime);
1212
crucible_postcond {{ valprime == val }};
1313
};
14-
fails (crucible_llvm_verify_x86 m "./test" "increment" [] false increment_setup);
14+
fails (crucible_llvm_verify_x86 m "./test" "increment" [] false increment_setup w4);

intTests/test_llvm_x86_03/test.saw

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let test_setup = do {
66
crucible_execute_func [];
77
crucible_return (crucible_term {{ 1 : [64] }});
88
};
9-
fails (crucible_llvm_verify_x86 m "./test" "foo" [] false test_setup);
9+
fails (crucible_llvm_verify_x86 m "./test" "foo" [] false test_setup w4);

intTests/test_llvm_x86_04/test.saw

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ let addvar_setup = do {
1616
valprime <- crucible_fresh_var "_val" (llvm_int 64);
1717
crucible_points_to ptr (crucible_term valprime);
1818
};
19-
crucible_llvm_verify_x86 m "./test" "addvar" [] false addvar_setup;
19+
crucible_llvm_verify_x86 m "./test" "addvar" [] false addvar_setup w4;

src/SAWScript/Crucible/LLVM/X86.hs

+31-23
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module SAWScript.Crucible.LLVM.X86
2929
import Control.Lens.TH (makeLenses)
3030

3131
import System.IO (stdout)
32-
import Control.Exception (catch, throw)
32+
import Control.Exception (throw)
3333
import Control.Lens (view, use, (&), (^.), (.~), (.=))
3434
import Control.Monad.ST (stToIO)
3535
import Control.Monad.State
@@ -54,11 +54,12 @@ import Data.Parameterized.NatRepr
5454
import Data.Parameterized.Context hiding (view)
5555
import Data.Parameterized.Nonce
5656

57+
import Verifier.SAW.FiniteValue
5758
import Verifier.SAW.Recognizer
5859
import Verifier.SAW.Term.Functor
5960
import Verifier.SAW.TypedTerm
6061

61-
import SAWScript.Prover.SBV
62+
import SAWScript.Proof
6263
import SAWScript.Prover.SolverStats
6364
import SAWScript.TopLevel
6465
import SAWScript.Value
@@ -187,8 +188,9 @@ crucible_llvm_verify_x86 ::
187188
[(String, Integer)] {- ^ Global variable symbol names and sizes (in bytes) -} ->
188189
Bool {-^ Whether to enable path satisfiability checking (currently ignored) -} ->
189190
LLVMCrucibleSetupM () {- ^ Specification to verify against -} ->
191+
ProofScript SatResult {- ^ Tactic used to use when discharging goals -} ->
190192
TopLevel (SomeLLVM MS.CrucibleMethodSpecIR)
191-
crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x)) path nm globsyms _checkSat setup
193+
crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x)) path nm globsyms _checkSat setup tactic
192194
| Just Refl <- testEquality (C.LLVM.X86Repr $ knownNat @64) . C.LLVM.llvmArch
193195
$ modTrans llvmModule ^. C.LLVM.transContext = do
194196
let ?ptrWidth = knownNat @64
@@ -278,7 +280,7 @@ crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x)) path nm gl
278280
C.AbortedResult{} -> printOutLn opts Warn "Warning: function never returns"
279281
C.TimeoutResult{} -> fail "Execution timed out"
280282

281-
liftIO . void $ runX86Sim preState checkGoals
283+
checkGoals sym opts sc tactic
282284

283285
pure $ SomeLLVM methodSpec
284286
| otherwise = fail "LLVM module must be 64-bit"
@@ -700,29 +702,35 @@ assertPointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr texpected) = do
700702

701703
-- | Gather and run the solver on goals from the simulator.
702704
checkGoals ::
703-
X86Sim ()
704-
checkGoals = do
705-
sym <- use x86Sym
706-
opts <- use x86Options
707-
sc <- use x86SharedContext
705+
Sym ->
706+
Options ->
707+
SharedContext ->
708+
ProofScript SatResult ->
709+
TopLevel ()
710+
checkGoals sym opts sc tactic = do
708711
gs <- liftIO $ getGoals sym
709712
liftIO . printOutLn opts Info $ mconcat
710713
[ "Simulation finished, running solver on "
711714
, show $ length gs
712715
, " goals"
713716
]
714-
liftIO . forM_ gs $ \g ->
715-
do
716-
term <- gGoal sc g
717-
(mb, stats) <- proveUnintSBV z3 [] Nothing sc term
718-
printOutLn opts Info $ ppStats stats
719-
case mb of
720-
Nothing -> printOutLn opts Info "Goal succeeded"
721-
Just ex -> do
722-
fail $ mconcat
723-
["Failure (", show $ gLoc g
724-
, "): ", show $ gMessage g
725-
, "\nCounterexample: " <> show ex
726-
]
727-
`catch` \(X86Error e) -> fail $ "Failure, error: " <> e
717+
forM_ (zip [0..] gs) $ \(n, g) -> do
718+
term <- liftIO $ gGoal sc g
719+
let proofgoal = ProofGoal n "vc" (show $ gMessage g) term
720+
r <- evalStateT tactic $ startProof proofgoal
721+
case r of
722+
Unsat stats -> do
723+
liftIO . printOutLn opts Info $ ppStats stats
724+
SatMulti stats vals -> do
725+
printOutLnTop Info $ unwords ["Subgoal failed:", show $ gMessage g]
726+
printOutLnTop Info (show stats)
727+
printOutLnTop OnlyCounterExamples "----------Counterexample----------"
728+
ppOpts <- sawPPOpts . rwPPOpts <$> getTopLevelRW
729+
case vals of
730+
[] -> printOutLnTop OnlyCounterExamples "<<All settings of the symbolic variables constitute a counterexample>>"
731+
_ -> let showAssignment (name, val) =
732+
mconcat [ " ", name, ": ", show $ ppFirstOrderValue ppOpts val ]
733+
in mapM_ (printOutLnTop OnlyCounterExamples . showAssignment) vals
734+
printOutLnTop OnlyCounterExamples "----------------------------------"
735+
throwTopLevel "Proof failed."
728736
liftIO $ printOutLn opts Info "All goals succeeded"

src/SAWScript/Interpreter.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ primitives = Map.fromList
19861986
]
19871987

19881988
, prim "crucible_llvm_verify_x86"
1989-
"LLVMModule -> String -> String -> [(String, Int)] -> Bool -> CrucibleSetup () -> TopLevel CrucibleMethodSpec"
1989+
"LLVMModule -> String -> String -> [(String, Int)] -> Bool -> CrucibleSetup () -> ProofScript SatResult -> TopLevel CrucibleMethodSpec"
19901990
(bicVal crucible_llvm_verify_x86)
19911991
Experimental
19921992
[ "Verify an x86 function from an ELF file for use as an override in an"

0 commit comments

Comments
 (0)