{"id":23209844,"url":"https://github.com/saswatpadhi/loopinvgen","last_synced_at":"2025-08-19T04:32:45.728Z","repository":{"id":74716724,"uuid":"92583097","full_name":"SaswatPadhi/LoopInvGen","owner":"SaswatPadhi","description":"Generates loop invariants for program verification","archived":false,"fork":false,"pushed_at":"2021-01-22T23:31:04.000Z","size":4102,"stargazers_count":52,"open_issues_count":3,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2023-10-20T22:58:50.405Z","etag":null,"topics":["cegis","invariant-generation","invariants","loop-invariants","program-verification","sygus","sygus-solver","syntax-guided-synthesis","synthesis"],"latest_commit_sha":null,"homepage":"","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/SaswatPadhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-27T08:13:28.000Z","updated_at":"2023-10-20T22:58:52.544Z","dependencies_parsed_at":null,"dependency_job_id":"7075abb2-2f56-4d9d-b1aa-95432bf66343","html_url":"https://github.com/SaswatPadhi/LoopInvGen","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaswatPadhi%2FLoopInvGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaswatPadhi%2FLoopInvGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaswatPadhi%2FLoopInvGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaswatPadhi%2FLoopInvGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SaswatPadhi","download_url":"https://codeload.github.com/SaswatPadhi/LoopInvGen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230320874,"owners_count":18208266,"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":["cegis","invariant-generation","invariants","loop-invariants","program-verification","sygus","sygus-solver","syntax-guided-synthesis","synthesis"],"created_at":"2024-12-18T18:29:54.182Z","updated_at":"2024-12-18T18:29:54.732Z","avatar_url":"https://github.com/SaswatPadhi.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"LoopInvGen\n\u003ca href=\"https://microbadger.com/images/padhi/loopinvgen\"\u003e\u003cimg align=\"right\" src=\"https://img.shields.io/microbadger/image-size/padhi/loopinvgen.svg?style=flat\u0026label=docker\"\u003e\u003c/img\u003e\u003c/a\u003e\n==========\n\n[![](https://img.shields.io/travis/SaswatPadhi/LoopInvGen/master.svg?logo=travis\u0026style=popout\u0026label=Travis+Build)][travis]\n\u0026nbsp;\n[![](https://img.shields.io/docker/cloud/build/padhi/loopinvgen.svg?logo=docker\u0026style=popout\u0026label=Docker+Image)][docker-hub]\n\nA data-driven tool that generates provably sufficient loop invariants for program verification.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/architecture.png\" width=\"400\"/\u003e\n  \u003cbr\u003e\n  \u003csub\u003e\n    [\u0026thinsp;LoopInvGen extends our old (now deactivated) project, PIE -- the Precondition Inference Engine.\u0026thinsp;]\n  \u003c/sub\u003e\n\u003c/p\u003e\n\n\n---\n\n[**Installation**](#installation)\n\u0026nbsp; \u0026nbsp; \u0026vert; \u0026nbsp; \u0026nbsp;\n[Invariant Inference](#invariant-inference)\n\u0026nbsp;\u0026middot;\u0026nbsp;\n[Batch Verification](#batch-verification)\n\u0026nbsp; \u0026nbsp; \u0026vert; \u0026nbsp; \u0026nbsp;\n[_Use as a Library_](app/)\n\u0026nbsp; \u0026nbsp; \u0026vert; \u0026nbsp; \u0026nbsp;\n[Citing LoopInvGen](#citing-loopinvgen)\n\u0026nbsp;\u0026middot;\u0026nbsp;\n[License (MIT)](LICENSE.md)\n\n---\n\n#### :page_with_curl: Papers and Presentations\n\n- [CAV 2019](http://i-cav.org/2019) --\n  Paper on the [_Hybrid Enumeration_ (HEnum)](https://saswatpadhi.github.io/assets/pdf/cav2019_overfitting.pdf) technique used for \"feature\" synthesis within LoopInvGen\n- [PLDI 2016](http://conf.researchr.org/home/pldi-2016) --\n  Original paper on the [_Precondition Inference Engine_ (PIE)](https://saswatpadhi.github.io/assets/pdf/pldi2016_pie.pdf), the backbone of LoopInvGen\n  \u003cbr\u003e\u003cbr\u003e\n- [SyGuS-Comp 2019] (in conjunction with CAV and SYNT 2019) --\n  Solver [Presentation](docs/2019_SyGuS-Comp-Presentation.pdf) and [Description](docs/2019_SyGuS-Comp-Description.pdf)\n- [SyGuS-Comp 2018] (a satellite event of CAV and SYNT at FLoC 2018) --\n  Solver [Presentation](docs/2018_SyGuS-Comp-Presentation.pdf) and [Description](docs/2018_SyGuS-Comp-Description.pdf)\n- [SyGuS-Comp 2017] (in conjunction with CAV and SYNT 2017) --\n  Solver [Presentation](docs/2017_SyGuS-Comp-Presentation.pdf) and [Description](docs/2017_SyGuS-Comp-Description.pdf)\n\n#### :trophy: Awards and Honors\n\n- [SyGuS-Comp 2018] -- Inv Track **Winner** ([Results](https://sygus.org/comp/2018/results-slides.pdf) and [Report](https://sygus.org/comp/2018/report.pdf))\n- [SyGuS-Comp 2017] -- Inv Track **Winner** ([Results](https://sygus.org/comp/2017/results-slides.pdf) and [Report](https://sygus.org/comp/2017/report.pdf))\n\n## Installation\n\n### Using `docker` (recommended)\n\n_**Note:** The docker image may consume  ~\u0026hairsp;3\u0026hairsp;GB of disk space._\n\nWe recommend running LoopInvGen within a docker container,\nsince they have negligible performance overhead.\n(See [this report](http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195DD819C85257D2300681E7B/$File/rc25482.pdf))\n\n0. [Get `docker` for your OS](https://docs.docker.com/install).\n1. Pull our docker image\u003csup\u003e[#](#note_1)\u003c/sup\u003e: `docker pull padhi/loopinvgen`.\n2. Run a container over the image: `docker run -it padhi/loopinvgen`.\u003cbr\u003e\n   This would give you a `bash` shell within LoopInvGen directory.\n\n\u003ca name=\"note_1\"\u003e\u003csup\u003e#\u003c/sup\u003e\u003c/a\u003e Alternatively, you could also build the Docker image locally:\n\n```bash\ndocker build -t padhi/loopinvgen github.com/SaswatPadhi/LoopInvGen\n```\n\nDocker containers are isolated from the host system.\nTherefore, to run LoopInvGen on SyGuS files residing on the host system,\nyou must first [bind mount] them while running the container:\n\n```bash\ndocker run -v /host/dir:/home/opam/LoopInvGen/shared -it padhi/loopinvgen\n```\n\nThe `/host/dir` on the host system would then be accessible within the container at `~/LoopInvGen/shared` (with read+write permissions).\n\n\u003cdetails\u003e\n\n\u003csummary\u003e Docker also allows you to easily limit the container's memory and/or CPU usage.\u003c/summary\u003e\n\n```bash\n# Create a LoopInvGen container with 4GB memory, no swap and 1 CPU\n$ docker run -it --memory=4g --memory-swap=4g --cpus=1 padhi/loopinvgen\n```\n\nSee [the official Docker guide](https://docs.docker.com/config/containers/resource_constraints)\nfor more details on applying resource constraints.\n\n\u003c/details\u003e\n\n\n### Manual Installation\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003ckbd\u003eCLICK\u003c/kbd\u003e to reveal instructions\u003c/summary\u003e\n\n#### 0. Get the required packages for your OS.\n\nPlease see the [`Dockerfile`](Dockerfile#L19-L21) for the complete list of required packages\nfor building LoopInvGen and its dependencies.  \nMost of these packages are already installed on standard installations of most *nix distributions,\nexcept, may be, these: `aspcud libgmp-dev libomp-dev m4`.\n\n#### 1. Install `opam` package manager for OCaml.\n\nSee \u003chttps://opam.ocaml.org/doc/Install.html\u003e for detailed instructions.\n\n#### 2. Install `ocaml` \u003e= 4.08.0.\nWe recommend using an OCaml compiler with [`flambda`][flambda] optimizations enabled.\nFor example, with [opam](https://opam.ocaml.org/) 2.0+, you could run `opam switch create 4.10.0+flambda`.\n\n#### 3. `opam install` the dependencies.\n```bash\n$ opam install alcotest.1.1.0 core.v0.13.0 dune.2.5.1\n```\n\n#### 4. Get the [Z3 project][z3].\nWe have tested LoopInvGen with the latest stable version of Z3 (4.8.7).\nYou could either:\n- `git checkout https://github.com/Z3Prover/z3.git` for the bleeding-edge version, or\n- `wget https://github.com/Z3Prover/z3/archive/z3-4.8.7.zip \u0026\u0026 unzip z3-4.8.7.zip` for the stable version\n\n#### 5. `git clone` this project, and build everything.\n```bash\n$ ./scripts/build_all.sh -z /PATH/TO/z3_dir\n```\nThe `build_all.sh` script would build Z3, copy it to `_dep/`, and then build LoopInvGen.\nAlternatively, you can copy a precompiled version of Z3 to a `_dep` directory at the root of the repository,\nand simply run `./scripts/build_all.sh`.\n\nFor debug builds, use the `-D` or `--debug` switch when invoking `build_all.sh`.\n\nFor future builds after any changes to the source code, you only need to run `dune build`.\nYou can configure the build profile to either `debug` or `optimize` (default),\nusing: `dune build --profile \u003cprofile\u003e`.  \n\n\u003c/details\u003e\n\n## Invariant Inference\n\nInfer invariants for SyGuS-INV benchmarks by invoking LoopInvGen as:\n```bash\n$ ./loopinvgen.sh benchmarks/LIA/2016.SyGuS-Comp/array.sl\n(define-fun inv-f ((x Int) (y Int) (z Int)) Bool (not (and (\u003e= x 5) (not (\u003c= y z)))))\n```\n\n**Note:** LoopInvGen processes benchmarks in multiple stages.\nWe trap \u003ckbd\u003eCTRL\u003c/kbd\u003e+\u003ckbd\u003eC\u003c/kbd\u003e (`SIGINT` signal) to break out of the current stage,\nand \u003ckbd\u003eCTRL\u003c/kbd\u003e+\u003ckbd\u003e\\\\\u003c/kbd\u003e (`SIGQUIT` signal) to kill LoopInvGen and with its child processes.\n\n#### Inference Timeout\n\nYou may use the `-t` flag to run LoopInvGen with a maximum limit\non the number of _seconds_ (wall-clock time) for which the inference algorithm may run.\n```bash\n$ ./loopinvgen.sh -t 8 benchmarks/LIA/2016.SyGuS-Comp/array.sl\n```\n\nFor timeout based on CPU time, you may use [`ulimit`](https://ss64.com/bash/ulimit.html).\n\n#### Manually Adding Features\n\nYou may use the `-F` flag to preseed LoopInvGen's inference engine\nwith custom features (written in SMTLib format).\n```bash\n$ ./loopinvgen.sh -F benchmarks/NIA/2018.CHI_InvGame/~features/s10.some.smt2.input benchmarks/NIA/2018.CHI_InvGame/s10.desugared.sl\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003ckbd\u003eCLICK\u003c/kbd\u003e for further details\u003c/summary\u003e\n\n#### Verifying Generated Invariants\n\nThe `-v` switch makes LoopInvGen verify the benchmark with the generated invariant:\n```bash\n$ ./loopinvgen.sh -v benchmarks/LIA/2016.SyGuS-Comp/array.sl\nPASS\n```\n\nIt gives one of the following verdicts:\n```\nPASS                : The generated invariant successfully verifies the benchmark.\nPASS (NO SOLUTION)  : The benchmark is invalid (no invariant can verify it),\n                      and no invariant was generated.\nFAIL {\u003cvc1\u003e;...}    : The generated invariant fails to verify the VCs: vc1, vc2 etc.\n                      where each VC is one of {pre, post, trans}.\nFAIL (NO SOLUTION)  : The benchmark is invalid (no invariant can verify it),\n                      but an invariant (that is not empty/false) was generated.\n[TIMEOUT] \u003cverdict\u003e : Invariant inference timed out.\n                      With an empty (false) invariant, \u003cverdict\u003e is one of the verdicts above.\n```\n\nTry `./loopinvgen.sh -h` for other options that allow more control over the inference process.\n\n\u003c/details\u003e\n\n\n## Batch Verification\n\nExecute `./scripts/test_all.sh -b benchmarks/LIA` to run LoopInvGen on all benchmarks in [benchmarks/LIA].\nThe `test_all.sh` script invokes LoopInvGen for invariant inference,\nand then verifies that the generated invariant is sufficient to prove correctness of the SyGuS benchmark.\n\n**Note:** Within `test_all.sh`,\nwe trap \u003ckbd\u003eCTRL\u003c/kbd\u003e+\u003ckbd\u003eC\u003c/kbd\u003e (`SIGINT` signal) to kill the currently running benchmark,\nand \u003ckbd\u003eCTRL\u003c/kbd\u003e+\u003ckbd\u003e\\\\\u003c/kbd\u003e (`SIGQUIT` signal) to kill the `test_all.sh` script with its child processes.\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003ckbd\u003eCLICK\u003c/kbd\u003e for further details\u003c/summary\u003e\n\nFor each benchmark, the `test_all.sh` script generates one of the verdicts mentioned [above](#verifying-generated-invariants), or:\n```\n[SKIPPED] \u003cverdict\u003e : Invariant inference was skipped for an already passing benchmark.\n                      \u003cverdict\u003e is one of the PASS verdicts above.\n```\n\n#### Rerunning Failed Benchmarks\n\nThe `test_all.sh` script creates a new log directory and tests all benchmarks each time it is run.\nHowever, one may want to rerun only the previously failed benchmarks, for example with a different timeout,\nfrom a previously failing run.\nThis can be achieved by forcing `test_all.sh` to use a previous log directory, using `-l \u003cold_log_dir\u003e`.\n\n#### Benchmarking with Other Inference Tools\n\n`test_all.sh` is a generic benchmarking script that may run any invariant inference tool\nwhich accepts the SyGuS format. This makes it easier for us to compare various tools easily.  \nTo use an invariant inference tool other than LoopInvGen, invoke it as:\n```bash\n$ ./scripts/test_all.sh -b \u003cpath/to/benchmarks\u003e -T \u003cpath/to/tool\u003e [-- [-tool] [-specific] [-options]]\n```\n\n#### Limiting Execution Time\n\nJust like `loopinvgen.sh`, the `test_all.sh` script allows users to limit the\nexecution time for the invariant inference tools using the `-t` flag.\n```bash\n$ ./scripts/test_all.sh -b benchmarks/LIA -t 10\n```\n\nTry `./scripts/test_all.sh -h` for more options.\n\n\u003c/details\u003e\n\n## Citing LoopInvGen\n\n```\n@inproceedings{pldi/2016/PadhiSM,\n  author    = {Saswat Padhi and Rahul Sharma and Todd D. Millstein},\n  title     = {Data-Driven Precondition Inference with Learned Features},\n  booktitle = {Proceedings of the 37th {ACM} {SIGPLAN} Conference on Programming\n               Language Design and Implementation, {PLDI} 2016, Santa Barbara, CA,\n               USA, June 13-17, 2016},\n  pages     = {42--56},\n  year      = {2016},\n  url       = {http://doi.acm.org/10.1145/2908080.2908099},\n  doi       = {10.1145/2908080.2908099}\n}\n```\n\n[benchmarks/LIA]:     benchmarks/LIA\n\n[flambda]:            https://caml.inria.fr/pub/docs/manual-ocaml/flambda.html\n[bind mount]:         https://docs.docker.com/storage/bind-mounts\n\n[SyGuS-Comp 2017]:    https://sygus.org/comp/2017\n[SyGuS-Comp 2018]:    https://sygus.org/comp/2018\n[SyGuS-Comp 2019]:    https://sygus.org/comp/2019\n\n[docker-hub]:         https://hub.docker.com/r/padhi/loopinvgen\n[travis]:             https://travis-ci.org/SaswatPadhi/LoopInvGen\n[z3]:                 https://github.com/Z3Prover/z3","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaswatpadhi%2Floopinvgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaswatpadhi%2Floopinvgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaswatpadhi%2Floopinvgen/lists"}