MyNixOS website logo
Description

SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Express properties about Haskell programs and automatically prove them using SMT (Satisfiability Modulo Theories) solvers.

SBV: SMT Based Verification in Haskell

Build Status

On Hackage: http://hackage.haskell.org/package/sbv

Express properties about Haskell programs and automatically prove them using SMT solvers.

$ ghci
ghci> :m Data.SBV
ghci> prove $ \x -> x `shiftL` 2 .== 4 * (x::SWord8)
Q.E.D.
ghci> prove $ \x -> x `shiftL` 2 .== 2 * (x::SWord8)
Falsifiable. Counter-example:
  s0 = 32 :: Word8

The function prove establishes theorem-hood, while sat finds a satisfying model if it exists. All satisfying models can be computed using allSat. SBV can also perform static assertion checks, such as absence of division-by-0, and other user given properties. Furthermore, SBV can perform optimization, minimizing/maximizing arithmetic goals for their optimal values.

SBV also allows for an incremental mode: Users are given a handle to the SMT solver as their programs execute, and they can issue SMTLib commands programmatically, query values, and direct the interaction using a high-level typed API. The incremental mode also allows for creation of constraints based on the current model, and access to internals of SMT solvers for advanced users. See the runSMT and query commands for details.

Overview

SBV library provides support for dealing with symbolic values in Haskell. It introduces the types:

  • SBool: Symbolic Booleans (bits).
  • SWord8, SWord16, SWord32, SWord64: Symbolic Words (unsigned).
  • SInt8, SInt16, SInt32, SInt64: Symbolic Ints (signed).
  • SWord N, SInt N, for N > 0: Arbitrary sized unsigned/signed bit-vectors, parameterized by the bitsize. (Using DataKinds extension.)
  • SInteger: Symbolic unbounded integers (signed).
  • SReal: Symbolic infinite precision algebraic reals (signed).
  • SRational: Symbolic rationals, ratio of two symbolic integers. (Rational.)
  • SFloat: IEEE-754 single precision floating point number. (Float.)
  • SDouble: IEEE-754 double precision floating point number. (Double.)
  • SFloatingPoint: IEEE-754 floating point number with user specified exponent and significand sizes. (FloatingPoint)
  • SChar: Symbolic characters, supporting unicode.
  • SString: Symbolic strings.
  • SList: Symbolic lists. (Which can be nested, i.e., lists of lists.)
  • STuple: Symbolic tuples (upto 8-tuples, can be nested)
  • SEither: Symbolic sums
  • SMaybe: Symbolic optional values
  • SSet: Symbolic sets
  • Arrays of symbolic values.
  • Symbolic enumerations, for arbitrary user-defined enumerated types.
  • Symbolic polynomials over GF(2^n ), polynomial arithmetic, and CRCs.
  • Uninterpreted constants and functions over symbolic values, with user defined axioms.
  • Uninterpreted sorts, and proofs over such sorts, potentially with axioms.
  • Ability to define SMTLib functions, generated directly from Haskell versions, including support for recursive and mutually recursive functions.
  • Reasoning with universal and existential quantifiers, including alternating quantifiers.

The user can construct ordinary Haskell programs using these types, which behave like ordinary Haskell values when used concretely. However, when used with symbolic arguments, functions built out of these types can also be:

  • proven correct via an external SMT solver (the prove function),
  • checked for satisfiability (the sat, and allSat functions),
  • checked for assertion violations (the safe function with sAssert calls),
  • checked for delta-satisfiability (the dsat and dprove functions),
  • used in synthesis (the satfunction with existentials),
  • checked for machine-arithmetic overflow/underflow conditions,
  • optimized with respect to cost functions (the optimize, maximize, and minimize functions),
  • quick-checked,
  • used for generating Haskell and C test vectors (the genTest function),
  • compiled down to C, rendered as straight-line programs or libraries (compileToC and compileToCLib functions).

Picking the SMT solver to use

The SBV library uses third-party SMT solvers via the standard SMT-Lib interface. The following solvers are supported:

  • ABC from University of Berkeley
  • Boolector from Johannes Kepler University
  • Bitwuzla from Stanford University
  • CVC4 and CVC5 from Stanford University and the University of Iowa
  • DReal from CMU
  • MathSAT from FBK and DISI-University of Trento
  • OpenSMT from Università della Svizzera italiana
  • Yices from SRI
  • Z3 from Microsoft

Most functions have two variants: For instance prove/proveWith. The former uses the default solver, which is currently Z3. The latter expects you to pass it a configuration that picks the solver. The valid values are abc, boolector, bitwuzla, cvc4, cvc5, dReal, mathSAT, openSMT, yices, and z3.

See versions for a listing of the versions of these tools SBV has been tested with. Please report if you see any discrepancies!

Other SMT solvers can be used with SBV as well, with a relatively easy hook-up mechanism. Please do get in touch if you plan to use SBV with any other solver.

Using multiple solvers, simultaneously

SBV also allows for running multiple solvers at the same time, either picking the result of the first to complete, or getting results from all. See proveWithAny/proveWithAll and satWithAny/satWithAll functions. The function sbvAvailableSolvers can be used to query the available solvers at run-time.

Copyright, License

The SBV library is distributed with the BSD3 license. See COPYRIGHT for details. The LICENSE file contains the BSD3 verbiage.

Thanks

The following people made major contributions to SBV, by developing new features and contributing to the design in significant ways: Joel Burget, Brian Huffman, Brian Schroeder, and Jeffrey Young.

The following people reported bugs, provided comments/feedback, or contributed to the development of SBV in various ways: Andreas Abel, Ara Adkins, Andrew Anderson, Kanishka Azimi, Markus Barenhoff, Reid Barton, Ben Blaxill, Ian Blumenfeld, Guillaume Bouchard, Martin Brain, Ian Calvert, Oliver Charles, Christian Conkle, Matthew Danish, Iavor Diatchki, Alex Dixon, Robert Dockins, Thomas DuBuisson, Trevor Elliott, Gergő Érdi, John Erickson, Richard Fergie, Adam Foltzer, Joshua Gancher, Remy Goldschmidt, Brad Hardy, Tom Hawkins, Greg Horn, Jan Hrcek, Georges-Axel Jaloyan, Anders Kaseorg, Tom Sydney Kerckhove, Lars Kuhtz, Piërre van de Laar, Pablo Lamela, Ken Friis Larsen, Andrew Lelechenko, Joe Leslie-Hurd, Nick Lewchenko, Brett Letner, Sirui Lu, Georgy Lukyanov, Martin Lundfall, John Matthews, Curran McConnell, Philipp Meyer, Fabian Mitterwallner, Joshua Moerman, Matt Parker, Jan Path, Matt Peddie, Lucas Peña, Matthew Pickering, Lee Pike, Gleb Popov, Rohit Ramesh, Geoffrey Ramseyer, Jaro Reinders, Stephan Renatus, Dan Rosén, Ryan Scott, Eric Seidel, Austin Seipp, Andrés Sicard-Ramírez, Don Stewart, Greg Sullivan, Josef Svenningsson, George Thomas, May Torrence, Daniel Wagner, Sean Weaver, Nis Wegmann, Jared Ziegler, and Marco Zocca.

Thanks!

Metadata

Version

10.12

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows