{"id":18620701,"url":"https://github.com/formalsec/smtml","last_synced_at":"2025-07-31T05:04:32.843Z","repository":{"id":155340360,"uuid":"618050885","full_name":"formalsec/smtml","owner":"formalsec","description":"An SMT solver frontend for OCaml","archived":false,"fork":false,"pushed_at":"2025-04-09T13:03:50.000Z","size":2792,"stargazers_count":34,"open_issues_count":18,"forks_count":8,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-09T14:26:49.264Z","etag":null,"topics":["alt-ergo","bitwuzla","colibri2","cvc5","ocaml","smt","smt-lib","symbolic-execution","webassembly","z3"],"latest_commit_sha":null,"homepage":"https://formalsec.github.io/smtml/smtml/","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formalsec.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-23T16:44:49.000Z","updated_at":"2025-04-09T13:03:52.000Z","dependencies_parsed_at":"2023-10-02T23:25:43.834Z","dependency_job_id":"13190f7e-5388-4734-bd53-76f1f41235f3","html_url":"https://github.com/formalsec/smtml","commit_stats":null,"previous_names":["formalsec/encoding","formalsec/smtml"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formalsec%2Fsmtml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formalsec%2Fsmtml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formalsec%2Fsmtml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formalsec%2Fsmtml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formalsec","download_url":"https://codeload.github.com/formalsec/smtml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248329573,"owners_count":21085560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alt-ergo","bitwuzla","colibri2","cvc5","ocaml","smt","smt-lib","symbolic-execution","webassembly","z3"],"created_at":"2024-11-07T04:07:30.760Z","updated_at":"2025-07-31T05:04:32.826Z","avatar_url":"https://github.com/formalsec.png","language":"OCaml","funding_links":[],"categories":["Program analysis"],"sub_categories":[],"readme":"# Smt.ml [![Build badge](https://github.com/formalsec/smtml/actions/workflows/build.yml/badge.svg)](https://github.com/formalsec/smtml/actions) [![Coverage Status](https://coveralls.io/repos/github/formalsec/smtml/badge.svg)](https://coveralls.io/github/formalsec/smtml) [![MIT](https://img.shields.io/github/license/formalsec/smtml)](LICENSE) ![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macos-lightgrey)\n\nSmt.ml is an SMT solver frontend for OCaml that simplifies integration\nwith various solvers through a consistent interface. Its parametric\nencoding facilitates the easy addition of new solver backends, while\noptimisations like formula simplification, result caching, and detailed\nerror feedback enhance performance and usability.\n\n## Installation\n\n### OPAM\n\nInstall [opam](https://opam.ocaml.org/doc/Install.html) and bootstrap the OCaml compiler:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ opam init\n$ opam switch create 5.3.0 5.3.0\n```\n\nThen install encoding:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ opam install smtml\n```\n\n### Installing a Solver\n\nSmt.ml uses optional dependencies (known as `depopts` in opam) to integrate\nwith different SMT solvers. By default, Smt.ml installs without a solver, but\nyou can enable support for a specific solver by installing it with opam.\nFor example, to install smtml with Z3:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ opam install smtml z3\n```\n\nAlternatively, if you've already installed Smt.ml through opam, you can simply\ninstall the solver of your choice and opam will recompile smtml for you.\nFor example, to install Z3 after installing smtml:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ opam install z3\n```\n\nSee the [Supported Solvers](#supported-solvers) section below for a complete\nlist of available solvers.\n\n### Build from source\n\nClone the repo and install the dependencies:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ git clone https://github.com/formalsec/smtml.git\n$ cd smtml\n$ opam install . --deps-only --with-test\n```\n\nBuild and test:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ dune build @install\n$ dune runtest\n```\n\nInstall `smtml` on your path by running:\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ dune install\n```\n\n### Code Coverage Reports\n\n\u003c!-- $MDX skip --\u003e\n```sh\n$ BISECT_FILE=`pwd`/bisect dune runtest --force --instrument-with bisect_ppx\n$ bisect-ppx-report summary # Shell summary\n$ bisect-ppx-report html    # Detailed Report in _coverage/index.html\n```\n\n## Quick Start\n\n```ocaml\n# #require \"smtml\";;\n# open Smtml;;\n# #install_printer Expr.pp;;\n# #install_printer Value.pp\n# #install_printer Symbol.pp\n# #install_printer Statistics.pp;;\n# let pp_model = Model.pp ~no_values:false;;\nval pp_model : Model.t Fmt.t = \u003cfun\u003e\n# #install_printer pp_model;;\n\n# module Z3 = Solver.Batch (Z3_mappings);;\nmodule Z3 :\n  sig\n    type t = Smtml.Solver.Batch(Smtml.Z3_mappings).t\n    type solver = Smtml.Solver.Batch(Smtml.Z3_mappings).solver\n    val solver_time : float ref\n    val solver_count : int ref\n    val pp_statistics : t Fmt.t\n    val create : ?params:Smtml.Params.t -\u003e ?logic:Smtml.Logic.t -\u003e unit -\u003e t\n    val interrupt : t -\u003e unit\n    val clone : t -\u003e t\n    val push : t -\u003e unit\n    val pop : t -\u003e int -\u003e unit\n    val reset : t -\u003e unit\n    val add : t -\u003e Expr.t list -\u003e unit\n    val add_set : t -\u003e Expr.Set.t -\u003e unit\n    val get_assertions : t -\u003e Expr.t list\n    val get_statistics : t -\u003e Statistics.t\n    val check : t -\u003e Expr.t list -\u003e [ `Sat | `Unknown | `Unsat ]\n    val check_set : t -\u003e Expr.Set.t -\u003e [ `Sat | `Unknown | `Unsat ]\n    val get_value : t -\u003e Expr.t -\u003e Expr.t\n    val model : ?symbols:Symbol.t list -\u003e t -\u003e Model.t option\n    val get_sat_model :\n      ?symbols:Symbol.t list -\u003e\n      t -\u003e Expr.Set.t -\u003e [ `Model of Model.t | `Unknown | `Unsat ]\n  end\n# let solver = Z3.create ();;\nval solver : Z3.t = \u003cabstr\u003e\n\n# let cond =\n    let a = Expr.symbol (Symbol.make Ty.Ty_bool \"a\") in\n    let b = Expr.symbol (Symbol.make Ty.Ty_bool \"b\") in\n    Expr.(binop Ty_bool And a (unop Ty_bool Not b));;\nval cond : Expr.t = (bool.and a (bool.not b))\n\n# match Z3.check solver [ cond ] with\n    | `Sat -\u003e \"Satisfiable\"\n    | `Unsat -\u003e \"Unsatisfiable\"\n    | `Unknown -\u003e \"Unknown\";;\n- : string = \"Satisfiable\"\n```\n\n## Features \u0026 Usage\n\n### Multi-Solver Support\n\n```ocaml\n# module Z3 = Solver.Batch (Z3_mappings);;\n...\n# module Bzla = Solver.Batch (Bitwuzla_mappings);;\n...\n```\n\n### Bitvector Arithmetic\n\n```ocaml\n# let cond =\n    let x = Expr.Bitv.I32.sym \"x\" in\n    let y = Expr.Bitv.I32.v 0xdeadbeefl in\n    let sum = Expr.(binop (Ty_bitv 32) Add x y) in\n    Expr.(relop Ty_bool Eq sum (Expr.Bitv.I32.v 0xffffffffl));;\nval cond : Expr.t = (bool.eq (i32.add x -559038737) -1)\n\n# let model =\n    let () = Z3.add solver [ cond ] in\n    let _ = Z3.check solver [] in\n    Z3.model solver\nval model : Model.t option = Some (model\n                                (x i32 559038736))\n```\n\n### Model Inspection\n\n```ocaml\n# match model with\n    | Some model -\u003e Model.get_bindings model\n    | None -\u003e []\n- : (Symbol.t * Value.t) list = [(x, 559038736)]\n```\n\n### Solver Statistics\n\n\u003c!-- $MDX non-deterministic --\u003e\n```ocaml\n# let stats = Z3.get_statistics solver;;\nval stats : Statistics.t =\n  ((added eqs 4)\n   (arith-make-feasible 2)\n   (arith-max-columns 4)\n   (bv bit2core 32)\n   (del clause 2)\n   (final checks 2)\n   (max memory 17.15)\n   (memory 17.15)\n   (mk bool var 38)\n   (mk clause 3)\n   (num allocs 11363)\n   (num checks 2)\n   (propagations 3)\n   (rlimit count 262))\n```\n\n## Supported Solvers\n\n| Solver     | Status  | Opam Package |\n|------------|:-------:|--------------|\n| [Z3]       | ☑️ | [z3](https://opam.ocaml.org/packages/z3/) |\n| [Colibri2] | ☑️ | [colibri2](https://opam.ocaml.org/packages/colibri2/) |\n| [Bitwuzla] | ☑️ | [bitwuzla-cxx](https://opam.ocaml.org/packages/bitwuzla-cxx/) |\n| [Alt-Ergo] | ☑️ | [alt-ergo](https://opam.ocaml.org/packages/alt-ergo/) |\n| [cvc5]     | ☑️ | [cvc5](https://opam.ocaml.org/packages/cvc5/) |\n| [Minisat]  | 📆 | [minisat](https://opam.ocaml.org/packages/minisat/) |\n\n#### Legend\n\n- ☑️ Solver is currently supported\n- 🔄 Ongoing work to support solver\n- 📆 Planned to support in the future\n\n## About\n\n### Project Name\n\nThe name `Smt.ml` is a portmanteau of the terms `SMT` and `OCaml`. The `.ml`\nextension is a common file extension for OCaml source files. The library itself\nis named `smtml` and can be imported into OCaml projects by:\n\n```dune\n(library\n  (name client_library)\n  (libraries smtml))\n```\n\n### Changelog\n\nSee [CHANGES]\n\n### Copyright\n\n    MIT License\n\n    Copyright (c) 2024 formalsec\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n    SOFTWARE.\n\n[Z3]: https://github.com/Z3Prover/z3\n[Colibri2]: https://git.frama-c.com/pub/colibrics\n[Bitwuzla]: https://github.com/bitwuzla/ocaml-bitwuzla\n[Alt-Ergo]: https://github.com/OCamlPro/alt-ergo\n[CVC5]: https://github.com/cvc5/cvc5\n[Minisat]: https://github.com/c-cube/ocaml-minisat\n\n[CHANGES]: /CHANGES.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformalsec%2Fsmtml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformalsec%2Fsmtml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformalsec%2Fsmtml/lists"}