Libraries and tools for the SMT-LIB-2 standard.

Related tags

Embedded smt2utils
Overview

smt2utils: Libraries and tools for the SMT-LIB-2 standard

Build Status License License

This project aims to develop Rust libraries and tools around the SMT-LIB-2 standard.

The SMT-LIB-2 format (SMT2 for short) is the reference input format for many SMT solvers such as Z3 and CVC4.

Content

  • smt2parser is generic parsing library for SMT2 commands.

  • smt2proxy is an experimental tool to intercept and pre-process SMT2 commands before they are sent to an SMT solver.

  • z3tracer is an experimental library and tool to process Z3 logs obtained by passing the options trace=true proof=true.

  • smt2patch is an experimental library and tool to modify SMT files.

The code in this repository is still under active development.

Contributing

See the CONTRIBUTING file for how to help out.

License

This project is available under the terms of either the Apache 2.0 license or the MIT license.

Comments
  • More generic versions of concrete types

    More generic versions of concrete types

    Would it be possible to add generic versions of the following concrete types to smt2parser::visitors similar to how Identifier, Index, and the *Dec types are defined?

    • SExpr (generic over Constant, Symbol, Keyword)
    • QualIdentifier (generic over Identifier, Sort)
    • Command (generic over Symbol, Sort, Keyword, Term)
    opened by max-heller 4
  • Make smt2parser::concrete types more generic and use default type parameters

    Make smt2parser::concrete types more generic and use default type parameters

    Made the following types generic over the values they contain:

    • SExpr
    • Sort
    • QualIdentifier
    • Term
    • Command

    Replaced type aliases filling in standard type parameters with default type parameters in the definitions.

    Fixes #36

    CLA Signed 
    opened by max-heller 2
  • [z3 tracer] make the demo tool create charts

    [z3 tracer] make the demo tool create charts

    • The charts are similar to Jupyter notebooks.
    • Code is (mostly) shared between the tool and the notebook(s).
    z3 trace=true proof=true path/to/file.smt2
    cargo run --release -p z3tracer -- --plot-all z3.log
    # Creates several z3.log.*.png files
    
    CLA Signed 
    opened by ma2bd 1
  • [smt2parser] add support for name randomization

    [smt2parser] add support for name randomization

    Improve renaming::SymbolNormalizer:

    • add a configuration object and support the randomization of variables (up to a maximum number of variables per kind, after which indices are just sequential).
    • expose the number of distinct variables of each kind after normalization
    • update the demo tool smt2bin
    • update the tool smt2proxy

    Examples:

    # Demo tool in this repo:
    cargo run --release -p smt2parser -- print --normalize-symbols --max-randomized-symbols 1024 --symbol-randomization-seed 5 path/to/file.smt2
    
    # Proxy in the diem repo:
    SMT2PROXY_NORMALIZE_SYMBOLS=true SMT2PROXY_LOG_PATH=logs.smt2 \
    SMT2PROXY_MAX_RANDOMIZED_SYMBOLS=1024 SMT2PROXY_SYMBOL_RANDOMIZATION_SEED=1 \
    BOOGIE_EXE=`which boogie` Z3_EXE=path/to/target/release/smt2proxy \
    cargo run --release -p move-prover -- --cores 1 -d language/diem-framework/modules -d language/move-stdlib/modules language/diem-framework/modules/DiemSystem.move
    
    CLA Signed 
    opened by ma2bd 0
  • [smt2parser] handle push, pop, reset and respect kinds while renaming symbols

    [smt2parser] handle push, pop, reset and respect kinds while renaming symbols

    This allows reusing symbol names after a (push) or a (reset) and is generally more correct in case of name clashes with globals.

    Additionally, we now use a different prefix for each symbol kind: "f" for functions, "T" for datatypes, etc.

    CLA Signed 
    opened by ma2bd 0
  • [smt2proxy] Support symbol normalization

    [smt2proxy] Support symbol normalization

    Enable normalization of symbols on the fly in the SMT2 proxy.

    Note:

    • Symbols are renamed x0, x1, etc disregarding their kind (type, function name),
    • Names are assigned in order (no random shuffle yet).

    Assuming that smt2proxy is in the PATH, the proxy can be tested from in the Diem repo like this:

    SMT2PROXY_NORMALIZE_SYMBOLS=true SMT2PROXY_LOG_PATH=logs.smt2 BOOGIE_EXE=`which boogie` Z3_EXE=`which smt2proxy` \
    cargo run --release -p move-prover -- --cores 1 -d language/diem-framework/modules -d language/move-stdlib/modules language/diem-framework/modules/DiemSystem.move
    
    # Replay logs.
    z3 logs.smt2
    

    Note that --cores 1 is important for the logs to be meaningful.

    CLA Signed 
    opened by ma2bd 0
  • [smt2parser] Add support for name resolution

    [smt2parser] Add support for name resolution

    Provide a working implementation of name resolution and name normalization for SMT2 files with the following caveats:

    • The old syntax for testers is-Foo is not compatible with name resolution. One needs to replace is-Foo into (_ is Foo) first using the given rewriter renaming::TesterModernizer (see unit tests).
    • Error handling is not fully satisfying yet: visitor APIs do not use Result yet and will panic! in case of unknown symbol. (However, this only affects people using the new name-resolution callbacks, not the parsing.)
    • The LALR parser will attempt to call some of the new callbacks but proper name resolution requires to use SyntaxBuilder first, then visit the concrete syntax again. See the unit test of the utility type renaming::SymbolNormalizer.
    CLA Signed 
    opened by ma2bd 0
  • [z3tracer] add dependency analysis for QIs and conflicts

    [z3tracer] add dependency analysis for QIs and conflicts

    This PR substantially extends the Model abstraction of z3tracer to track dependencies:

    • between conflicts and Quantifier Instantiations (QIs)
    • between QIs.

    Contrary to the algorithm suggested in the Axiom Profiler documentation:

    • We do not ignore [push] and [pop] commands and try to account for backtracking in a precise way (e.g. proofs discovered at one point may go out of scope);
    • The logs do not tell when equations were discovered (only when they are used). To allow limit backtracking, we try to reconstruct a plausible backtracking level for them using their dependencies.
    • We try to model the QI dependencies that caused a conflict. Because conflicts can be seen as progress when trying to prove UNSAT, this could be used to distinguish "useful" QIs.
    • We do not do anything special about "rewrite" and "monotonicity" proofs yet. (EDIT: This should be fine. We propagate dependencies for all proof terms already.)

    See the main notebook for new charts and some examples.

    image

    image

    CLA Signed 
    opened by ma2bd 0
  • [smt2patch] initial commit

    [smt2patch] initial commit

    Explore a new tool to make changes to an SMT2 file. Current features include:

    • tagging asserts with names and inserting a call to get-unsat-core
    • being able to remove clauses not in the unsat core
    • tagging quantified expressions with a QID
    • setting the weight of quantified expressions
    cargo run -p smt2patch -- --get-unsat-core FILE | z3 -in | tail -n 1 > unsat_core.txt
    
    cargo run -p smt2patch -- --keep-only-clauses "$(cat unsat_core.txt)" -- FILE | z3 -in
    
    cargo run -p smt2patch -- --tag-quantifiers  FILE | z3 trace=true -in  # z3.log now contains quant!N names
    
    cargo run -p smt2patch -- --set-weights quant!0=100 -- FILE
    

    Example of output using --get-unsat-core and --tag-quantifiers:

    (set-option :produce-unsat-cores true)
    (set-info :smt-lib-version  2.6)
    (set-logic ALIA)
    (set-info :source  piVC)
    (set-info :category  "industrial")
    (set-info :status  unsat)
    (declare-fun V_9 () Int)
    (declare-fun a () (Array Int Int))
    (assert (! (let ((?v_0 (and true (>= V_9 0)))) (and (and ?v_0 ?v_0) (and (forall ((?V_7 Int)) (! (=> (and (<= 0 ?V_7) (<= ?V_7 5)) (forall ((?V_8 Int)) (! (let ((?v_1 (store (store a 0 5) 5 7))) (=> (and (<= 0 ?V_8) (<= ?V_8 ?V_7)) (<= (select ?v_1 ?V_8) (select ?v_1 ?V_7)))) :qid quant!0))) :qid quant!1)) (forall ((?V_5 Int)) (! (=> (and (<= 0 ?V_5) (<= ?V_5 5)) (forall ((?V_6 Int)) (! (let ((?v_2 (store (store a 0 1) 5 3))) (=> (and (<= 0 ?V_6) (<= ?V_6 ?V_5)) (<= (select ?v_2 ?V_6) (select ?v_2 ?V_5)))) :qid quant!2))) :qid quant!3))))) :named clause!0))
    (check-sat)
    (get-unsat-core)
    (exit)
    

    Original file:

    (set-info :smt-lib-version 2.6)
    (set-logic ALIA)
    (set-info :source |piVC|)
    (set-info :category "industrial")
    (set-info :status unsat)
    (declare-fun V_9 () Int)
    (declare-fun a () (Array Int Int))
    (assert (let ((?v_0 (and true (>= V_9 0)))) (and (and ?v_0 ?v_0) (and (forall ((?V_7 Int)) (=> (and (<= 0 ?V_7) (<= ?V_7 5)) (forall ((?V_8 Int)) (let ((?v_1 (store (store a 0 5) 5 7))) (=> (and (<= 0 ?V_8) (<= ?V_8 ?V_7)) (<= (select ?v_1 ?V_8) (select ?v_1 ?V_7))))))) (forall ((?V_5 Int)) (=> (and (<= 0 ?V_5) (<= ?V_5 5)) (forall ((?V_6 Int)) (let ((?v_2 (store (store a 0 1) 5 3))) (=> (and (<= 0 ?V_6) (<= ?V_6 ?V_5)) (<= (select ?v_2 ?V_6) (select ?v_2 ?V_5)))))))))))
    (check-sat)
    (exit)
    
    CLA Signed 
    opened by ma2bd 0
  • [z3tracer] make parser options accessible

    [z3tracer] make parser options accessible

    • make parser options ParserConfig accessible from CLI tool and existing library API
    • revert to not skipping incorrect lines by default in Model::process
    • make version check the default at the parser level
    • add option to skip version check
    • fix --help: Work around annoying bug with structopt(flatten)
    • fix endless loop on truncated files when skipping incorrect lines
    CLA Signed 
    opened by ma2bd 0
  • Add instantiation timestamps and modify parser to ignore invalid lines

    Add instantiation timestamps and modify parser to ignore invalid lines

    This PR contains two commits:

    • Add a ParserConfig which currently only contains one field: ignore_invalid_lines. When this boolean is true, the parser will ignore lines which don't start with '['.
    • Replace field instantiation_data_len with instantiation_timestamps in struct TermData to store timestamps information. And the length of the instantiation_timestamps is used to sort the terms in most_instantiated_terms. The notebooks have been updated too.
    CLA Signed 
    opened by emmazzz 0
  • Parser bug in get-value

    Parser bug in get-value

    Hi,

    We've just found a bug in your parser related to the get-value command. The SMT-LIB syntax for get-value is

    (get-value ( <terms>+ ))
    

    (cf. SMT-LIB 2.6 page 45).

    Your rule in get-value in parser.rs is missing the inner parentheses:

        command ::= LeftParen GetValue terms(xs) RightParen { extra.0.visit_get_value(xs)? }
    

    It should be like this instead:

        command ::= LeftParen GetValue LeftParen terms(xs) RightParen RightParen { extra.0.visit_get_value(xs)? }
    

    Thanks (and thanks for producing this parser!).

    Bruno

    opened by BrunoDutertre 0
  • WIP: Support parsing theories

    WIP: Support parsing theories

    Hi, I wanted to take a crack at getting theory parsing working to fix https://github.com/facebookincubator/smt2utils/issues/15.

    Before I went to the trouble of implementing all the parser rules and concrete syntax types, I wanted to validate the approach I'm taking.

    Basically it amounts to:

    • Parser returns an enum ParseResult which could be either a Command or a Theory. (currently, no modesetting is done, we rely on upstream consumers like CommandStream, to provide errors if the parser returns an unexpected result)
    • Extend SmtVisitor with TheoryVisitor. I'm not sure I like this because I imagine there are a lot of tools that will only operate on Commands and not on Theorys but it seemed the least invasive choice. I would welcome some guidance on this point.
    CLA Signed 
    opened by djrenren 0
  • [smt2parser] add parsing rules for SMT2 theories and logics

    [smt2parser] add parsing rules for SMT2 theories and logics

    It should not be too hard to add support for theory and logic definitions. Two options:

    1. add callbacks for "fake" commands: (theory ..) and (logic ..)
    2. modify the Pomelo parser to be multimodal. ~~This can be done by accepting a first token Mode(m) that sets the mode.~~ (EDIT: not needed)

    https://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2017-07-18.pdf

    opened by ma2bd 0
Owner
Meta Incubator
We work hard to contribute our work back to the web, mobile, big data, & infrastructure communities. NB: members must have two-factor auth.
Meta Incubator
The sysroot manager that lets you build and customize `std`

PSA: Xargo is in maintenance mode xargo The sysroot manager that lets you build and customize std Cross compiling `std` for i686-unknown-linux-gnu Xar

Jorge Aparicio 993 Jan 2, 2023
Example of a Baremetal program written for the Rasperry Pi 1 (BCM2845). Both the UART and the Framebuffer graphics working

This repository is aimed to provide a starting point to whoever is trying to build a BCM2835 program from scratch. This repository contains linker scr

Pietro 4 Nov 10, 2022
GPIO reader, writer and listener

Unbothered gpio Everything is unwrapped under the hood for the precious prettiness of your code. It's more than a simple Rust crate, it's a philosophy

null 0 Nov 7, 2021
Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated

raslib Raspberry PI library for Rust. GPIO controller, L298N motors, sockets and "i2clib" integrated All tests are made on Raspberry PI 4B+ on Raspbia

Anтo 5 Apr 12, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Sets of libraries and tools to write applications and libraries mixing OCaml and Rust

Sets of libraries and tools to write applications and libraries mixing OCaml and Rust. These libraries will help keeping your types and data structures synchronized, and enable seamless exchange between OCaml and Rust

Meta 36 Jan 28, 2023
The axiom profiler for exploring and visualizing SMT solver quantifier instantiations (made via E-matching).

Axiom Profiler A tool for visualising, analysing and understanding quantifier instantiations made via E-matching in a run of an SMT solver (at present

Viper Project 18 Oct 18, 2022
Rust-verification-tools - RVT is a collection of tools/libraries to support both static and dynamic verification of Rust programs.

Rust verification tools This is a collection of tools/libraries to support both static and dynamic verification of Rust programs. We see static verifi

null 253 Dec 31, 2022
A fusion of OTP lib/dialyzer + lib/compiler for regular Erlang with type inference

Typed ERLC The Problem I have a dream, that one day there will be an Erlang compiler, which will generate high quality type-correct code from deduced

Dmytro Lytovchenko 35 Sep 5, 2022
Sway-lib-core - Sway standard library core primitives.

lib-core This Sway project contains core operators and extremely primitive logic for use in the standard library of the Sway programming language. Usa

Fuel Labs 8 Mar 29, 2022
Collection of immutable and persistent data structures written in Rust, inspired by the standard libraries found in Haskell, Closure and OCaml

PRust: (P)ersistent & Immutable Data Structures in (Rust) This library houses a collection of immutable and persistent data structures, inspired by th

Victor Colombo 13 Aug 13, 2023
Dfinity's fungible token standard. Any PRs and comments are welcome,collaborate with us to build this standard

Dfinity's fungible token standard. Any PRs and comments are welcome,collaborate with us to build this standard

Deland Labs 46 Nov 7, 2022
Grimsby is an Erlang Port written in Rust that can close its standard input while retaining standard output (and error)

Grimsby An Erlang Port provides the basic mechanism for communication from Erlang with the external world. From the Ports and Port Drivers: Erlang Ref

Peter Morgan 5 May 29, 2023
Porting Go standard libraries to Rust.

Crabmole Porting some Go standard libraries in Rust Note: This crate will not port all go standard libraries in Rust, but some missing libraries in Ru

Al Liu 6 Jan 2, 2023
Ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust.

Ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust.

Riccardo D'Ambrosio 2.1k Jan 5, 2023
Ecosystem of libraries and tools for writing and executing fast GPU code fully in Rust.

The Rust CUDA Project An ecosystem of libraries and tools for writing and executing extremely fast GPU code fully in Rust Guide | Getting Started | Fe

Rust GPU 2.1k Dec 30, 2022
Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.

The repository zefchain/serde-reflection is based on Facebook's repository novifinancial/serde-reflection. We are now maintaining the project here and

Zefchain Labs 46 Dec 22, 2022
Rust 核心库和标准库的源码级中文翻译,可作为 IDE 工具的智能提示 (Rust core library and standard library translation. can be used as IntelliSense for IDE tools)

Rust 标准库中文版 这是翻译 Rust 库 的地方, 相关源代码来自于 https://github.com/rust-lang/rust。 如果您不会说英语,那么拥有使用中文的文档至关重要,即使您会说英语,使用母语也仍然能让您感到愉快。Rust 标准库是高质量的,不管是新手还是老手,都可以从中

wtklbm 493 Jan 4, 2023
PartiQL libraries and tools in Rust.

This is a collection of crates to provide Rust support for the PartiQL query language.

null 54 Dec 26, 2022
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.

This repository lists static analysis tools for all programming languages, build tools, config files and more. The official website, analysis-tools.de

Analysis Tools 10.7k Jan 2, 2023