Skip to content

Commit 737c6af

Browse files
authored
Merge pull request #80 from Copilot-Language/T78-configure-smt-solver
Add `smtSolver` option to `VerifierOptions`. Refs #78.
2 parents 93d09ce + e25c954 commit 737c6af

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ prerequisites:
3838
* Ensure that you have the `z3` SMT solver in your `PATH`. `z3` binaries are
3939
available at https://github.com/Z3Prover/z3/releases.
4040

41+
Alternatively, the verifier can be configured to use one of the following
42+
SMT solvers instead:
43+
44+
* `cvc4`: https://cvc4.github.io/downloads.html
45+
* `cvc5`: https://github.com/cvc5/cvc5/releases/
46+
* `yices`: https://yices.csl.sri.com
47+
4148
Then, clone the repo and run:
4249

4350
```

copilot-verifier/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2025-01-31
2+
* Add `smtSolver` option to `VerifierOptions`. (#78)
3+
14
2025-01-20
25
* Version bump (4.2). (#76)
36
* Reject specs that use multiple triggers with the same name. (#74)

copilot-verifier/copilot-verifier.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ library
7171
exposed-modules:
7272
Copilot.Verifier
7373
Copilot.Verifier.Log
74+
Copilot.Verifier.Solver
7475

7576
library copilot-verifier-examples
7677
import: bldflags

copilot-verifier/src/Copilot/Verifier.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import qualified Copilot.Core.Type as CT
5050
import qualified Copilot.Theorem.What4 as CW4
5151

5252
import qualified Copilot.Verifier.Log as Log
53+
import qualified Copilot.Verifier.Solver as Solver
5354

5455
import Data.Parameterized.Ctx (EmptyCtx)
5556
import Data.Parameterized.Context (pattern Empty)
@@ -160,7 +161,6 @@ import What4.InterpretedFloatingPoint
160161
)
161162
import What4.ProgramLoc (ProgramLoc, mkProgramLoc, plFunction, Position(..))
162163
import What4.Solver.Adapter (SolverAdapter(..))
163-
import What4.Solver.Z3 (z3Adapter)
164164
import What4.Symbol (safeSymbol)
165165

166166
-- | @'verify' csettings props prefix spec@ verifies the Copilot specification
@@ -202,6 +202,8 @@ data VerifierOptions = VerifierOptions
202202
-- * @<solver>@ is the name of the SMT solver used to discharge the proof
203203
-- goal. Currently, this will always be @z3@, although we might make this
204204
-- configurable in the future.
205+
, smtSolver :: Solver.Solver
206+
-- ^ Which SMT solver to use when solving proof goals.
205207
} deriving stock Show
206208

207209
-- | The default 'VerifierOptions':
@@ -212,11 +214,14 @@ data VerifierOptions = VerifierOptions
212214
-- * Do not assume any side conditions related to partial operations.
213215
--
214216
-- * Do not log any SMT solver interactions.
217+
--
218+
-- * Use the Z3 SMT solver.
215219
defaultVerifierOptions :: VerifierOptions
216220
defaultVerifierOptions = VerifierOptions
217221
{ verbosity = Default
218222
, assumePartialSideConds = False
219223
, logSmtInteractions = False
224+
, smtSolver = Solver.Z3
220225
}
221226

222227
-- | Like 'defaultVerifierOptions', except that the verifier will assume side
@@ -332,7 +337,8 @@ verifyBitcode ::
332337
verifyBitcode opts csettings properties spec cruxOpts llvmOpts cFile bcFile =
333338
do -- Set up the expression builder and symbolic backend
334339
halloc <- newHandleAllocator
335-
sym <- newExprBuilder FloatUninterpretedRepr CopilotVerifierData globalNonceGenerator
340+
(sym :: ExprBuilder t st fs) <-
341+
newExprBuilder FloatUninterpretedRepr CopilotVerifierData globalNonceGenerator
336342
bak <- newSimpleBackend sym
337343
-- turn on hash-consing
338344
startCaching sym
@@ -341,9 +347,10 @@ verifyBitcode opts csettings properties spec cruxOpts llvmOpts cFile bcFile =
341347
clRefs <- newCopilotLogRefs
342348
let ?recordLLVMAnnotation = recordLLVMAnnotation clRefs
343349

344-
-- Set up the solver to use for verification. Right now we hard-code this to Z3.
345-
let adapters = [z3Adapter] -- TODO? configurable
346-
extendConfig (solver_adapter_config_options z3Adapter) (getConfiguration sym)
350+
-- Set up the solver to use for verification.
351+
let adapter :: SolverAdapter st
352+
adapter = Solver.solverAdapter (smtSolver opts)
353+
extendConfig (solver_adapter_config_options adapter) (getConfiguration sym)
347354

348355
-- Set up the Crucible/LLVM simulation context
349356
memVar <- mkMemVar "llvm_memory" halloc
@@ -386,13 +393,13 @@ verifyBitcode opts csettings properties spec cruxOpts llvmOpts cFile bcFile =
386393
-- segment of the associated Copilot streams.
387394
let cruxOptsInit = setCruxOfflineSolverOutput "initial-step" cruxOpts
388395
initGoals <-
389-
verifyInitialState cruxOptsInit adapters clRefs simctx initialMem
396+
verifyInitialState cruxOptsInit [adapter] clRefs simctx initialMem
390397
(CW4.initialStreamState proofStateBundle)
391398

392399
-- Now, the real meat. Carry out the bisimulation step of the proof.
393400
let cruxOptsTrans = setCruxOfflineSolverOutput "transition-step" cruxOpts
394401
bisimGoals <-
395-
verifyStepBisimulation opts cruxOptsTrans adapters csettings
402+
verifyStepBisimulation opts cruxOptsTrans [adapter] csettings
396403
clRefs simctx llvmMod trans memVar initialMem proofStateBundle
397404

398405
Log.sayCopilot $ Log.SuccessfulProofSummary cFile initGoals bisimGoals
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Copilot.Verifier.Solver
2+
( Solver(..)
3+
, solverAdapter
4+
) where
5+
6+
import qualified What4.Solver.Adapter as W4
7+
import qualified What4.Solver.CVC4 as W4.CVC4
8+
import qualified What4.Solver.CVC5 as W4.CVC5
9+
import qualified What4.Solver.Yices as W4.Yices
10+
import qualified What4.Solver.Z3 as W4.Z3
11+
12+
-- | General-purpose SMT solvers that @copilot-verifier@ supports.
13+
data Solver
14+
= CVC4
15+
| CVC5
16+
| Yices
17+
| Z3
18+
deriving Show
19+
20+
-- | Return the @what4@ 'W4.SolverAdapter' corresponding to a given 'Solver'.
21+
solverAdapter :: Solver -> W4.SolverAdapter st
22+
solverAdapter CVC4 = W4.CVC4.cvc4Adapter
23+
solverAdapter CVC5 = W4.CVC5.cvc5Adapter
24+
solverAdapter Yices = W4.Yices.yicesAdapter
25+
solverAdapter Z3 = W4.Z3.z3Adapter

0 commit comments

Comments
 (0)