Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:2akouwu Reverify Z3 Solver

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Formal_Methods, Verification
Last Updated 2026-10-24 12:00 GMT

Overview

SMT solver environment using Z3 (>= 4.12) for proof-grade bit-vector equivalence of integer expressions, enabling mathematically proven (not sampled) equivalence.

Description

This environment provides the Z3 SMT solver, required for `prove_expr_equiv` — proof-grade equivalence that proves two integer expressions equal for all inputs (not just sampled ones). Z3 compiles expressions into bit-vector formulas and checks for a distinguishing input. If none exists, the equivalence is proven; if Z3 finds a counterexample, it is refuted with a concrete witness. This is the tool behind MBA (Mixed Boolean-Arithmetic) deobfuscation: proving an obfuscated expression simplifies correctly. Without Z3 installed, `prove_expr_equiv` returns `inconclusive`.

Usage

Use this environment for proof-grade equivalence verification: proving that an obfuscated integer expression is equivalent to a simplified form for all possible inputs. This is the strongest equivalence tier — stronger than behavioral sampling (tested, not proven) because it covers the entire input space.

System Requirements

Category Requirement Notes
OS Cross-platform Z3 has prebuilt wheels for Linux/macOS/Windows
Hardware Any CPU Solver is CPU-bound but fast for small expressions
Disk Minimal No disk I/O during solving

Dependencies

System Packages

  • Python >= 3.8

Python Packages

  • `z3-solver` >= 4.12 (installed via `pip install "reverify[z3]"` or `pip install z3-solver>=4.12`)

Credentials

No credentials required.

Quick Install

# Install Z3 solver
pip install "reverify[z3]"
# or directly:
pip install z3-solver>=4.12

Code Evidence

Engine detection from `backends.py:45-51`:

try:
    import z3  # noqa: F401
    HAS_Z3 = True
    Z3_VERSION = z3.get_version_string()
except Exception:  # pragma: no cover
    HAS_Z3 = False
    Z3_VERSION = None

Fail-closed guard in `prove_expr_equiv` from `behavior.py:337-338`:

if not HAS_Z3:
    return {"status": "inconclusive", "detail": "z3 not installed (pip install z3-solver)"}

Z3 proof logic from `behavior.py:352-361`:

solver = z3.Solver()
solver.add(fa != fb)
res = solver.check()
if res == z3.unsat:
    return {"status": "proven", "detail": f"proven equivalent for all inputs (Z3, {bits}-bit)"}
if res == z3.sat:
    m = solver.model()
    ce = {f"x{i}": hex(m[variables[f'x{i}']].as_long()) for i in range(nvars)}
    return {"status": "refuted", "counterexample": ce, "detail": "not equivalent (Z3 found a distinguishing input)"}
return {"status": "inconclusive", "detail": "z3 returned unknown"}

Common Errors

Error Message Cause Solution
`inconclusive: z3 not installed (pip install z3-solver)` Z3 package missing `pip install "reverify[z3]"`
`inconclusive: z3 returned unknown` Z3 could not decide (rare for bit-vector) Simplify expressions or reduce bit width
`ExprError: operator not supported in proofs` Expression uses unsupported operator , <<, >>>(logical) supported in proofs

Compatibility Notes

  • Supported operators: Add, Sub, Mult, BitXor, BitAnd, BitOr, LShift, RShift (logical/unsigned), Invert, USub, UAdd. Division and modulo are not supported in Z3 proofs (they are in the sampling path).
  • Bit widths: Configurable via `bits` parameter (default 64). Supports 32-bit and 64-bit proofs.
  • Without Z3: `prove_expr_equiv` degrades to `inconclusive` — it never produces a false verdict.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment