CryptoMiniSat

repository·master·Indexed 21 days ago

https://github.com/msoos/cryptominisat

An advanced incremental SAT solver supporting XOR clauses and Gauss-Jordan elimination. It provides high-performance solving via a command-line interface and bindings for C++, Python (pycryptosat), and Rust.

Tokens
7.5K
Snippets
25
Records
34
Agent score
76%

What's inside CryptoMiniSat

  1. License information for CryptoMiniSat

    master

    By default, all components required to build CryptoMiniSat are licensed under the MIT License.

    If you explicitly configure the build system to include Bliss, those components are licensed under the GPL. CryptoMiniSat does not include Bliss by default.

  2. How the Oracle Solver handles persistent assumptions

    master

    The Oracle solver (derived from SharpSAT-TD) optimizes assumption handling by avoiding the standard CDCL approach of backtracking to level 0 and replaying assumptions sequentially. Instead, it uses a Three-Tier Level Scheme to partition assignments by decision level, allowing assumptions to persist across multiple Solve() calls without being undone by standard backtracking.

    Three-Tier Level Scheme

    LevelMeaningUndone by UnDecide?
    1Permanently frozen unitsNever
    2Working assumption shell (pre-set + propagated)Only entries that are in decided[]
    3+Regular CDCL search decisions during HardSolveYes

    By recording an assignment in lit_val[] and vs[v].level without pushing it onto the decided[] trail, the assignment becomes invisible to UnDecide(k), effectively making it a persistent state that survives the rollback of the main CDCL search.

  3. Optimize solving with the Oracle `Solve()` pattern

    master

    When using the Oracle solver, the Solve() method is designed to benefit from pre-set assumptions.

    1. Pre-set assumptions: Any literals pre-set via SetAssumpLit are already assigned (LitVal == 1), so the solver skips them at zero cost during the assumption loop.
    2. Dynamic assumptions: Any remaining dynamic assumptions are queued at level 2.
    3. Single propagation wave: Instead of $N$ waves, a single Propagate(2) call handles all level 2 consequences simultaneously.
    4. Persistent state: UnDecide(2) at the end of the call rolls back the CDCL search (levels $\ge 2$) but does not touch the watch-free, trail-free pre-set assumptions. This allows assumptions to persist into the next Solve() call.
    TriState Oracle::Solve(const vector<Lit>& assumps, ...) {
        for (const auto& lit : assumps) {
            if (LitVal(lit) == -1) { UnDecide(2); return false; }
            else if (LitVal(lit) == 0) { Decide(lit, 2); }
            // LitVal(lit) == 1: pre-set by SetAssumpLit, skip entirely
        }
        Propagate(2);        // one single propagation wave for all assumptions
        HardSolve(...);
        UnDecide(2);         // rolls back CDCD search, not the pre-set assumptions
    }
  4. Understand the Solver output format

    master

    The solve() method returns a tuple: (is_satisfiable, solution).

    1. is_satisfiable: A boolean indicating if a solution exists. If the solver hits a time_limit or confl_limit, this may be None.
    2. solution: A tuple containing the truth values. The first element is always None. Subsequent elements correspond to variable indices.
      • solution[i] returns the value for variable i.
      • Example: (None, True, False, True) means variable 1 is True, variable 2 is False, and variable 3 is True.

    If the solver hits a budget limit, it returns (None, None).

    >>> from pycryptosat import Solver
    >>> s = Solver()
    >>> s.add_clause([1, 2])
    >>> sat, solution = s.solve()
    >>> print(sat)
    True
    >>> print(solution)
    (None, True, True)
  5. Verify CryptoMiniSat XOR/FRAT proofs

    master

    CryptoMiniSat can generate proofs in the FRAT format. To verify these proofs, you must follow a pipeline that converts the FRAT file into an XLRUP format, which is then checked by cake_xlrup.

    The Verification Pipeline: CryptoMiniSat $\rightarrow$ .frat file $\rightarrow$ frat-xor (elaboration) $\rightarrow$ .xlrup file $\rightarrow$ cake_xlrup (verification)

    Prerequisites: You must build and have access to frat-xor and cake_xlrup from the meelgroup/frat-xor repository.

    # Full verification example
    CNF=out/fuzzTest_40.cnf
    FRAT=/tmp/proof.frat
    CLEAN=/tmp/proof_clean.frat
    XLRUP=/tmp/proof.xlrup
    
    cryptominisat5 --zero-exit-status [options] "$CNF" "$FRAT"
    grep -v "^c" "$FRAT" > "$CLEAN"
    ./frat-xor elab "$CLEAN" "$CNF" "$XLRUP"
    ./cake_xlrup "$CNF" "$XLRUP"
  6. Use Rust bindings for CryptoMiniSat

    master

    To use CryptoMiniSat in a Rust project, add the following dependency to your Cargo.toml:

    cryptominisat = { git = "https://github.com/msoos/cryptominisat-rs", branch= "master" }

    To build the bindings manually for testing:

    git clone https://github.com/msoos/cryptominisat-rs/
    cd cryptominisat-rs
    cargo build --release
    cargo test
  7. Install CryptoMiniSat via Nix

    master

    The fastest way to get the cryptominisat binary without manual compilation is using Nix. After installing Nix, run the following command to enter a shell with the binary ready to use:

    nix shell github:msoos/cryptominisat
  8. Build frat-xor and cake_xlrup tools

    master

    The verification tools frat-xor and cake_xlrup are located in the main branch of the https://github.com/meelgroup/frat-xor repository.

    Follow these steps to build them:

    1. Clone the repository.
    2. Build frat-xor using cargo.
    3. Build cake_xlrup using make.
    4. Symlink the resulting binaries to your working directory.
    git clone https://github.com/meelgroup/frat-xor
    cd frat-xor
    # build frat-xor
    cargo build --release
    cp target/release/frat-xor .
    
    # build cake_xlrup
    cd cake_xlrup
    make
    
    # Symlink binaries to your working directory
    ln -s /path/to/frat-xor/frat-xor        ./frat-xor
    ln -s /path/to/frat-xor/cake_xlrup/cake_xlrup  ./cake_xlrup
  9. Build CryptoMiniSat from source

    master

    CryptoMiniSat uses CMake and automatically fetches cadical and cadiback dependencies. You only need to install gmp and zlib on your system.

    1. Install System Dependencies

    Debian/Ubuntu:

    sudo apt-get install build-essential cmake ninja-build git libgmp-dev zlib1g-dev

    macOS (Homebrew):

    brew install cmake ninja gmp

    Windows (MSYS2/MINGW64):

    pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja \
              mingw-w64-x86_64-gmp mingw-w64-x86_64-zlib git

    2. Compile

    Run these commands in your terminal:

    git clone https://github.com/msoos/cryptominisat
    cd cryptominisat
    mkdir build && cd build
    cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
    cmake --build .

    To build a fully static binary (no shared-library dependencies at runtime), use the -DBUILD_SHARED_LIBS=OFF flag.

    cd cryptominisat
    mkdir build && cd build
    cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF ..
    cmake --build .
  10. Build pycryptosat from source

    master

    The build process uses scikit-build-core and CMake. CMake automatically handles cadical and cadiback dependencies. The only manual dependency required is GMP.

    Linux Setup

    Requires libgmp-dev (Debian/Ubuntu) or gmp-devel (RHEL/CentOS).

    sudo apt-get install libgmp-dev   # or: yum install gmp-devel
    python -m venv venv
    source venv/bin/activate
    pip install scikit-build-core cmake ninja build
    pip install . --no-build-isolation

    macOS Setup

    Requires gmp via Homebrew.

    brew install gmp
    python -m venv venv
    source venv/bin/activate
    pip install scikit-build-core cmake ninja build
    pip install . --no-build-isolation

    Build a wheel without installing

    To generate a standalone wheel in the dist/ directory:

    python -m venv venv
    source venv/bin/activate
    pip install scikit-build-core cmake ninja build
    python -m build --wheel --no-isolation

    Note on Portability:

    • macOS: Wheels are fully self-contained (GMP is bundled via delocate).
    • Linux: Wheels depend on libgmp.so.10 (part of the manylinux ABI).
    sudo apt-get install libgmp-dev
    python -m venv venv
    source venv/bin/activate
    pip install scikit-build-core cmake ninja build
    pip install . --no-build-isolation
  11. Verify CryptoMiniSat proofs

    master

    CryptoMiniSat can emit FRAT proofs. To verify them, follow these steps:

    1. Generate the proof:

      ./cryptominisat5 input.cnf proof.frat
    2. Clean the proof file (remove comments):

      grep -v "^c" proof.frat > proof_clean.frat
    3. Elaborate and check using frat-xor and cake_xlrup:

      ./frat-xor elab proof_clean.frat input.cnf proof.xlrup
      ./cake_xlrup input.cnf proof.xlrup

    If successful, cake_xlrup will print s VERIFIED.

    ./cryptominisat5 input.cnf proof.frat