Skip to main content

EDUCATIONAL PURPOSES ONLY: A symbolic execution engine for studying formal verification concepts. Not for production use.

Project description

pysymex

Python Symbolic Execution Engine powered by Z3 Theorem Prover Mathematically prove your Python code won't crash.

╔══════════════════════════════════════════════════════════════════════════════╗
                                                                              
   p y s y m e x                                                              
   ─────────────────────────────────────────────────────────────────────────  
   Symbolic Execution · Formal Verification · Z3-Powered                      
                                                                              
╚══════════════════════════════════════════════════════════════════════════════╝

Python 3.11+ License: AGPL-3.0 Status: Alpha-5.0 Z3 Solver


EDUCATIONAL PURPOSES ONLY

This project is a research prototype designed for studying symbolic execution and formal verification concepts. It is NOT intended for production use, security auditing, or critical systems verification. Use at your own risk.


Table of Contents

  1. Overview
  2. Installation
  3. Quick Start
  4. Bug Types Detected
  5. Architecture
  6. Development
  7. Requirements
  8. Contributing
  9. License
  10. Documentation

1. Overview

pysymex (Python Symbolic Execution) is a bytecode-level symbolic execution engine that uses the Z3 SMT solver to formally verify Python programs. It explores all possible execution paths through your code, building mathematical constraints at each decision point, then uses Z3 to find concrete inputs that trigger bugs — or prove no such inputs exist.

What It Does

  • Disassembles Python bytecode (CPython 3.11–3.13)
  • Symbolically executes every reachable path
  • Reports bugs with counterexamples (concrete crashing inputs)
  • Interprocedural Analysis — crosses function boundaries via call graphs and summaries
  • Asynchronous Execution — high-throughput scanning with asyncio and process pools

Features

Category Features
Engine Bytecode-level symbolic execution, CPython 3.13 opcode support, Z3 SMT integration
Optimization CHTD path explosion mitigation, constraint independence (KLEE-style), adaptive path selection
Analysis Interprocedural analysis, abstract interpretation, loop handling
Output Text, JSON, HTML, SARIF 2.1.0 (GitHub Security tab compatible), Rich (colored panels)
Safety 20+ bug types, 40+ detectors, sandbox isolation

2. Installation

From PyPI

pip install pysymex

From Source (Development)

git clone https://github.com/darkoss1/pysymex.git
cd pysymex
pip install -e ".[dev]"

3. Quick Start

Command Line

# Scan a file
pysymex scan mycode.py

# Scan a directory recursively
pysymex scan src/ -r

# Generate SARIF report for CI/CD
pysymex scan src/ --format sarif -o report.sarif

# Analyze a specific function
pysymex analyze mycode.py -f risky_func --args x:int y:str

# Run built-in benchmarks
pysymex benchmark --format markdown

Examples

The examples/ directory contains numbered scenarios for the current tree:

  • 01_basic_safety_guards.py
  • 02_common_runtime_bugs.py
  • 03_concolic_exploration.py
  • 04_contract_verification.py
  • 05_deep_path_loops.py
  • 06_sandbox_security.py
  • 07_symbolic_containers.py
  • 08_exception_handling.py

Python API

from pysymex import analyze

def risky_divide(x: int, y: int) -> int:
    return x // y

# Analyze for potential crashes
result = analyze(risky_divide, {"x": "int", "y": "int"})

for issue in result.issues:
    print(f"Bug: {issue.message}")
    print(f"Counterexample: {issue.counterexample}")

Example Output

╭──────────────────────────────────────────────────────────────────────────────╮
│ pysymex - formal verification report                                         │
╰──────────────────────────────────────────────────────────────────────────────╯

ISSUES FOUND (1)
────────────────────────────────────────────────────────────
╭─ [ DIVISION_BY_ZERO ] ───────────────────────────────────────────────────────╮
│  Location: mycode.py:12 in unsafe_divide()                                   │
│  Type:    DIVISION_BY_ZERO                                                   │
│  Error:    Division by zero: y can be 0                                      │
│  Trigger:  y = 0                                                             │
╰──────────────────────────────────────────────────────────────────────────────╯

SUMMARY
────────────────────────────────────────────────────────────
Paths explored:         1
Paths completed:        1
Instructions:           4
Execution time:     0.018s

Proven safe:            0
Issues found:           1

4. Bug Types Detected

Bug Type Description Example
Division by Zero Division where denominator can be 0 x / y where y=0
Modulo by Zero Modulo where divisor can be 0 x % y where y=0
Index Error Array access beyond bounds arr[i] where i >= len(arr)
Key Error Dictionary key not found d[key] where key missing
Attribute Error Missing attribute access obj.missing_attr
None Dereference Accessing attributes on None obj.method() where obj=None
Type Error Type mismatch in operations str + int
Value Error Invalid value for operation int("abc")
Assertion Error Assertions that can fail assert x > 0
Overflow Error Arithmetic overflow x + 1 where x = MAX_INT
Unbound Local Using unbound local variable print(x) before assignment
Name Error Using undefined name print(undefined_var)
Resource Leak Unclosed files or connections f = open(p); return
Dead Code Code that never executes Code after absolute return
Unreachable Code Code that cannot be reached Code after raise Exception
Infinite Loop Loop that never terminates while True: pass
Injection Code injection vulnerabilities SQL injection, command injection
Syntax Error Invalid syntax patterns Malformed code constructs
Logical Contradiction Impossible logical conditions if x > 10 and x < 5
Contract Violation Violated function contracts Pre/post condition failures

5. Architecture

pysymex/
├── analysis/              # Analysis engines
   ├── solver/            # Z3 verification core
   ├── abstract/          # Abstract interpretation
   ├── detectors/         # Bug detectors (40+)
   └── path_manager.py    # Path selection
├── core/                  # Engine foundation
   ├── types/             # Symbolic primitives
   ├── state.py           # VM state management
   └── solver.py          # Z3 wrapper
├── execution/             # Bytecode VM
   ├── dispatcher.py      # Opcode dispatch
   └── opcodes/           # Handlers (3.11-3.13)
├── accel/                 # Hardware acceleration
   └── backends/          # CPU backends
├── models/                # Stdlib models
├── reporting/             # Output formatters
└── scanner/               # Static scanner

6. Development

Setup

# Format code
ruff format pysymex tests

# Type checking
pyright pysymex

# Run tests
pytest tests/ -v

# Run with coverage
pytest --cov=pysymex tests/ -v

7. Requirements

  • Python 3.11+ (tested on 3.11, 3.12, 3.13)
  • z3-solver == 4.15.3.0
  • pydantic >= 2.12.0
  • immutables == 0.21
  • rich >= 13.0.0

Note: Dependency versions are carefully constrained to verified compatible versions.


8. Contributing

pysymex is currently an "Open Source, but Closed Contribution" project.

While the source code is available under the AGPLv3 license, we are not currently accepting external Pull Requests. This ensures the engine's architectural and mathematical integrity during its initial alpha phase.

If you find a bug or have a feature request, please open an issue.

See CONTRIBUTING.md for more details.


9. License

AGPL-3.0 License — see LICENSE.


10. Documentation

[!NOTE] Temporary Automated Documentation An automatically generated Code Wiki providing an architectural deep-dive and component reference is available at: https://codewiki.google/github.com/darkoss1/pysymex

Important Notices:

  • The Wiki is generated automatically but may take time to refresh; please verify the generation and commit dates on the page.
  • It may be slightly outdated compared to the latest main branch.
  • This is NOT official documentation and is provided for research and architectural exploration purposes only. Do not fully rely on it for production implementation details.

Built for Formal Verification

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysymex-0.1.0a5.tar.gz (801.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysymex-0.1.0a5-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file pysymex-0.1.0a5.tar.gz.

File metadata

  • Download URL: pysymex-0.1.0a5.tar.gz
  • Upload date:
  • Size: 801.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysymex-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 b183ad6dec414d2947d524e7298693a145376af777c04f2e05cd48ceafeb8be4
MD5 8e987d0c482fae8a3fedb2b929546caa
BLAKE2b-256 79bc40d5d6eb8d85745477f8fca32b0f9342c72aaeb40372dbce2add38b27b0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysymex-0.1.0a5.tar.gz:

Publisher: publish.yml on darkoss1/pysymex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysymex-0.1.0a5-py3-none-any.whl.

File metadata

  • Download URL: pysymex-0.1.0a5-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pysymex-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 c47b343a95aa8d0ab583695f692e5e50257f159c766ef9b211ab989e6c67c22e
MD5 ee8044540b8a8e35285f3337f5e71306
BLAKE2b-256 42a40b7f84bab58b725de19d627f0c66659e05c3ff5f89091cb43b1b64c5d63a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysymex-0.1.0a5-py3-none-any.whl:

Publisher: publish.yml on darkoss1/pysymex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page