rotalabs-verity 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rotalabs_verity-0.1.0/.github/workflows/docs.yml +59 -0
- rotalabs_verity-0.1.0/.gitignore +19 -0
- rotalabs_verity-0.1.0/PKG-INFO +312 -0
- rotalabs_verity-0.1.0/README.md +262 -0
- rotalabs_verity-0.1.0/docs/api/ce2p.md +7 -0
- rotalabs_verity-0.1.0/docs/api/core.md +35 -0
- rotalabs_verity-0.1.0/docs/api/encoder.md +23 -0
- rotalabs_verity-0.1.0/docs/api/llm.md +11 -0
- rotalabs_verity-0.1.0/docs/api/problem.md +33 -0
- rotalabs_verity-0.1.0/docs/api/synthesis.md +19 -0
- rotalabs_verity-0.1.0/docs/api/verifier.md +11 -0
- rotalabs_verity-0.1.0/docs/assets/logo-icon-light.png +0 -0
- rotalabs_verity-0.1.0/docs/assets/logo-light-full.png +0 -0
- rotalabs_verity-0.1.0/docs/getting-started.md +140 -0
- rotalabs_verity-0.1.0/docs/index.md +95 -0
- rotalabs_verity-0.1.0/docs/problems/circuit-breakers.md +48 -0
- rotalabs_verity-0.1.0/docs/problems/consensus.md +53 -0
- rotalabs_verity-0.1.0/docs/problems/coordination.md +48 -0
- rotalabs_verity-0.1.0/docs/problems/index.md +38 -0
- rotalabs_verity-0.1.0/docs/problems/rate-limiting.md +48 -0
- rotalabs_verity-0.1.0/docs/problems/replication.md +53 -0
- rotalabs_verity-0.1.0/docs/problems/transactions.md +48 -0
- rotalabs_verity-0.1.0/mkdocs.yml +92 -0
- rotalabs_verity-0.1.0/pyproject.toml +149 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/__init__.py +114 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/_version.py +1 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/ce2p/__init__.py +35 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/ce2p/abducer.py +379 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/ce2p/executor.py +337 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/ce2p/feedback.py +138 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/ce2p/localizer.py +111 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/cli.py +113 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/core/__init__.py +39 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/core/problem.py +138 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/core/python_subset.py +402 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/core/types.py +118 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/encoder/__init__.py +34 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/encoder/parser.py +111 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/encoder/symbolic.py +506 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/encoder/z3_encoder.py +123 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/llm/__init__.py +36 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/llm/client.py +140 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/llm/prompts.py +324 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/__init__.py +183 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/__init__.py +1 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb001_circuit_breaker.py +201 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb002_bulkhead.py +154 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb003_retry_backoff.py +185 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb004_timeout_handler.py +175 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb005_health_check.py +175 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb006_load_shedder.py +167 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb007_fallback_handler.py +178 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cb/cb008_graceful_degradation.py +178 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/__init__.py +0 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn001_leader_election.py +152 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn002_bully_election.py +143 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn003_ring_election.py +146 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn004_raft_election.py +153 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn005_paxos_proposer.py +149 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn006_paxos_acceptor.py +142 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn007_view_change.py +149 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn008_membership.py +140 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/cn/cn009_lease_manager.py +151 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/__init__.py +1 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co001_distributed_lock.py +150 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co002_semaphore.py +152 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co003_rwlock.py +145 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co004_barrier.py +131 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co005_countdown_latch.py +119 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co006_phaser.py +144 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co007_event_flag.py +140 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/co/co008_future.py +146 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/registry.py +36 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/__init__.py +1 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl001_token_bucket.py +177 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl002_sliding_window.py +190 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl003_leaky_bucket.py +175 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl004_fixed_window.py +178 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl005_concurrent_limiter.py +157 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl006_adaptive_limiter.py +187 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl007_burst_limiter.py +136 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rl/rl008_quota_limiter.py +175 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/__init__.py +0 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp001_primary_backup.py +156 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp002_chain_replication.py +157 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp003_quorum_read.py +160 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp004_quorum_write.py +142 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp005_anti_entropy.py +142 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp006_gossip.py +163 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp007_vector_clock.py +159 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp008_version_vector.py +146 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/rp/rp009_read_repair.py +152 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/__init__.py +1 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx001_two_phase_commit.py +160 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx002_saga.py +170 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx003_outbox.py +140 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx004_tcc.py +165 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx005_idempotent.py +185 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx006_wal.py +144 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx007_compensating.py +140 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/problems/tx/tx008_event_sourcing.py +174 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/synthesis/__init__.py +15 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/synthesis/cegis.py +222 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/verifier/__init__.py +11 -0
- rotalabs_verity-0.1.0/src/rotalabs_verity/verifier/verifier.py +276 -0
- rotalabs_verity-0.1.0/tests/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/conftest.py +161 -0
- rotalabs_verity-0.1.0/tests/test_ce2p/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_ce2p/test_abducer.py +163 -0
- rotalabs_verity-0.1.0/tests/test_ce2p/test_executor.py +147 -0
- rotalabs_verity-0.1.0/tests/test_ce2p/test_feedback.py +197 -0
- rotalabs_verity-0.1.0/tests/test_ce2p/test_localizer.py +148 -0
- rotalabs_verity-0.1.0/tests/test_core/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_core/test_problem.py +137 -0
- rotalabs_verity-0.1.0/tests/test_core/test_python_subset.py +244 -0
- rotalabs_verity-0.1.0/tests/test_core/test_types.py +109 -0
- rotalabs_verity-0.1.0/tests/test_encoder/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_encoder/test_parser.py +72 -0
- rotalabs_verity-0.1.0/tests/test_encoder/test_symbolic.py +195 -0
- rotalabs_verity-0.1.0/tests/test_encoder/test_z3_encoder.py +216 -0
- rotalabs_verity-0.1.0/tests/test_integration/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_integration/test_end_to_end.py +117 -0
- rotalabs_verity-0.1.0/tests/test_integration/test_generalization.py +218 -0
- rotalabs_verity-0.1.0/tests/test_llm/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_llm/test_client.py +145 -0
- rotalabs_verity-0.1.0/tests/test_llm/test_prompts.py +261 -0
- rotalabs_verity-0.1.0/tests/test_problems/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_problems/test_problems.py +155 -0
- rotalabs_verity-0.1.0/tests/test_synthesis/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_synthesis/test_cegis.py +252 -0
- rotalabs_verity-0.1.0/tests/test_verifier/__init__.py +1 -0
- rotalabs_verity-0.1.0/tests/test_verifier/test_verifier.py +340 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
name: Deploy Documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'docs/**'
|
|
9
|
+
- 'src/**'
|
|
10
|
+
- 'mkdocs.yml'
|
|
11
|
+
- '.github/workflows/docs.yml'
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
pages: write
|
|
17
|
+
id-token: write
|
|
18
|
+
|
|
19
|
+
concurrency:
|
|
20
|
+
group: "pages"
|
|
21
|
+
cancel-in-progress: false
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
build:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
steps:
|
|
27
|
+
- name: Checkout
|
|
28
|
+
uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- name: Setup Python
|
|
31
|
+
uses: actions/setup-python@v5
|
|
32
|
+
with:
|
|
33
|
+
python-version: '3.11'
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: |
|
|
37
|
+
pip install -e ".[docs]"
|
|
38
|
+
|
|
39
|
+
- name: Build documentation
|
|
40
|
+
run: mkdocs build
|
|
41
|
+
|
|
42
|
+
- name: Setup Pages
|
|
43
|
+
uses: actions/configure-pages@v4
|
|
44
|
+
|
|
45
|
+
- name: Upload artifact
|
|
46
|
+
uses: actions/upload-pages-artifact@v3
|
|
47
|
+
with:
|
|
48
|
+
path: site
|
|
49
|
+
|
|
50
|
+
deploy:
|
|
51
|
+
environment:
|
|
52
|
+
name: github-pages
|
|
53
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
needs: build
|
|
56
|
+
steps:
|
|
57
|
+
- name: Deploy to GitHub Pages
|
|
58
|
+
id: deployment
|
|
59
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rotalabs-verity
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Verity: Neuro-symbolic synthesis of verified code using Z3 and LLMs with CE2P feedback
|
|
5
|
+
Project-URL: Homepage, https://rotalabs.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/rotalabs/rotalabs-verity
|
|
7
|
+
Project-URL: Documentation, https://rotalabs.github.io/rotalabs-verity/
|
|
8
|
+
Author-email: Subhadip Mitra <subhadip@rotalabs.ai>, Rotalabs Research <research@rotalabs.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Keywords: ce2p,cegis,code-synthesis,formal-methods,llm,neuro-symbolic,smt,verification,z3
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: requests>=2.31.0
|
|
25
|
+
Requires-Dist: z3-solver>=4.12.0
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Requires-Dist: anthropic>=0.18.0; extra == 'all'
|
|
28
|
+
Requires-Dist: ollama>=0.1.0; extra == 'all'
|
|
29
|
+
Requires-Dist: openai>=1.0.0; extra == 'all'
|
|
30
|
+
Provides-Extra: anthropic
|
|
31
|
+
Requires-Dist: anthropic>=0.18.0; extra == 'anthropic'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: mypy>=1.5.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
38
|
+
Provides-Extra: docs
|
|
39
|
+
Requires-Dist: mkdocs-material>=9.4.0; extra == 'docs'
|
|
40
|
+
Requires-Dist: mkdocs>=1.5.0; extra == 'docs'
|
|
41
|
+
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'docs'
|
|
42
|
+
Provides-Extra: llm
|
|
43
|
+
Requires-Dist: anthropic>=0.18.0; extra == 'llm'
|
|
44
|
+
Requires-Dist: openai>=1.0.0; extra == 'llm'
|
|
45
|
+
Provides-Extra: ollama
|
|
46
|
+
Requires-Dist: ollama>=0.1.0; extra == 'ollama'
|
|
47
|
+
Provides-Extra: openai
|
|
48
|
+
Requires-Dist: openai>=1.0.0; extra == 'openai'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# rotalabs-verity
|
|
52
|
+
|
|
53
|
+
Verified code synthesis with Z3. Formally verify LLM-generated code using neuro-symbolic synthesis.
|
|
54
|
+
|
|
55
|
+
## Overview
|
|
56
|
+
|
|
57
|
+
`rotalabs-verity` is a neuro-symbolic synthesis framework that uses Z3 SMT solver to formally verify LLM-generated code. It implements CEGIS (Counterexample-Guided Inductive Synthesis) with CE2P (Counterexample-to-Program) feedback for structured repair suggestions.
|
|
58
|
+
|
|
59
|
+
### Key Features
|
|
60
|
+
|
|
61
|
+
- **Formal Verification**: Verify Python code against temporal properties using Z3
|
|
62
|
+
- **CEGIS Loop**: Iterative synthesis with LLM generation and Z3 verification
|
|
63
|
+
- **CE2P Feedback**: Structured counterexample analysis with fault localization and abductive repair
|
|
64
|
+
- **Multi-LLM Support**: OpenAI, Anthropic Claude, and local Ollama models
|
|
65
|
+
- **50 Benchmark Problems**: Rate limiting, circuit breakers, concurrency, consensus, replication, transactions
|
|
66
|
+
- **Python-to-Z3 Encoder**: Automatic translation of Python code to Z3 constraints
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
### Basic Installation
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install rotalabs-verity
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### With LLM Providers
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# OpenAI (GPT-4)
|
|
80
|
+
pip install rotalabs-verity[openai]
|
|
81
|
+
|
|
82
|
+
# Anthropic (Claude)
|
|
83
|
+
pip install rotalabs-verity[anthropic]
|
|
84
|
+
|
|
85
|
+
# Local Ollama
|
|
86
|
+
pip install rotalabs-verity[ollama]
|
|
87
|
+
|
|
88
|
+
# All LLM providers
|
|
89
|
+
pip install rotalabs-verity[llm]
|
|
90
|
+
|
|
91
|
+
# All optional dependencies
|
|
92
|
+
pip install rotalabs-verity[all]
|
|
93
|
+
|
|
94
|
+
# Development dependencies
|
|
95
|
+
pip install rotalabs-verity[dev]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Quick Start
|
|
99
|
+
|
|
100
|
+
### Verify Code Against Properties
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from rotalabs_verity import verify, VerificationStatus
|
|
104
|
+
from rotalabs_verity.problems import get_problem
|
|
105
|
+
|
|
106
|
+
# Load a benchmark problem
|
|
107
|
+
spec = get_problem("RL-001") # Token bucket rate limiter
|
|
108
|
+
|
|
109
|
+
# Code to verify
|
|
110
|
+
code = """
|
|
111
|
+
def allow(self, timestamp: float) -> bool:
|
|
112
|
+
if self.tokens >= 1:
|
|
113
|
+
self.tokens -= 1
|
|
114
|
+
return True
|
|
115
|
+
return False
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
# Verify
|
|
119
|
+
result = verify(code, spec)
|
|
120
|
+
|
|
121
|
+
if result.status == VerificationStatus.VERIFIED:
|
|
122
|
+
print("Code is correct!")
|
|
123
|
+
elif result.status == VerificationStatus.COUNTEREXAMPLE:
|
|
124
|
+
print(f"Bug found: {result.counterexample}")
|
|
125
|
+
print(f"Property violated: {result.property_violated.property_name}")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Synthesize Verified Code with LLM
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from rotalabs_verity import synthesize, SynthesisStatus
|
|
132
|
+
from rotalabs_verity.llm import OpenAIClient
|
|
133
|
+
from rotalabs_verity.problems import get_problem
|
|
134
|
+
|
|
135
|
+
# Load problem
|
|
136
|
+
spec = get_problem("RL-001")
|
|
137
|
+
|
|
138
|
+
# Create LLM client
|
|
139
|
+
llm = OpenAIClient(model="gpt-4")
|
|
140
|
+
|
|
141
|
+
# Synthesize with CEGIS loop
|
|
142
|
+
result = synthesize(spec, llm, max_iterations=10)
|
|
143
|
+
|
|
144
|
+
if result.status == SynthesisStatus.SUCCESS:
|
|
145
|
+
print(f"Synthesized verified code in {result.iterations} iterations:")
|
|
146
|
+
print(result.code)
|
|
147
|
+
else:
|
|
148
|
+
print(f"Synthesis failed: {result.error_message}")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Use CE2P Feedback
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from rotalabs_verity import verify, generate_feedback
|
|
155
|
+
from rotalabs_verity.problems import get_problem
|
|
156
|
+
|
|
157
|
+
spec = get_problem("RL-001")
|
|
158
|
+
|
|
159
|
+
buggy_code = """
|
|
160
|
+
def allow(self, timestamp: float) -> bool:
|
|
161
|
+
self.tokens -= 1 # Bug: doesn't check if tokens available
|
|
162
|
+
return True
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
result = verify(buggy_code, spec)
|
|
166
|
+
feedback = generate_feedback(buggy_code, result, spec=spec)
|
|
167
|
+
|
|
168
|
+
print(f"Property violated: {feedback.property_violated.property_name}")
|
|
169
|
+
print(f"Fault at line {feedback.fault_line}: {feedback.root_cause}")
|
|
170
|
+
print(f"Suggested fix: {feedback.suggested_fix}")
|
|
171
|
+
print(f"Guard condition: {feedback.repair_guard}")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### CLI Usage
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# List available problems
|
|
178
|
+
rotalabs-verity --list
|
|
179
|
+
|
|
180
|
+
# Synthesize solution for a problem
|
|
181
|
+
rotalabs-verity RL-001
|
|
182
|
+
|
|
183
|
+
# Use different LLM provider
|
|
184
|
+
rotalabs-verity RL-001 --provider anthropic
|
|
185
|
+
|
|
186
|
+
# Disable CE2P feedback
|
|
187
|
+
rotalabs-verity RL-001 --no-ce2p
|
|
188
|
+
|
|
189
|
+
# Save results to file
|
|
190
|
+
rotalabs-verity RL-001 --output results.json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Benchmark Problems
|
|
194
|
+
|
|
195
|
+
50 problems across 6 categories:
|
|
196
|
+
|
|
197
|
+
| Category | Problems | Description |
|
|
198
|
+
|----------|----------|-------------|
|
|
199
|
+
| **RL** (Rate Limiting) | 8 | Token bucket, sliding window, leaky bucket, etc. |
|
|
200
|
+
| **CB** (Circuit Breaker) | 8 | Circuit breaker, bulkhead, retry, timeout, etc. |
|
|
201
|
+
| **CO** (Concurrency) | 8 | Distributed lock, semaphore, barrier, latch, etc. |
|
|
202
|
+
| **CN** (Consensus) | 9 | Leader election, Paxos, Raft, view change, etc. |
|
|
203
|
+
| **RP** (Replication) | 9 | Primary-backup, chain replication, quorum, etc. |
|
|
204
|
+
| **TX** (Transactions) | 8 | 2PC, saga, outbox, TCC, WAL, etc. |
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from rotalabs_verity.problems import list_problems, list_by_category, get_problem
|
|
208
|
+
|
|
209
|
+
# List all problems
|
|
210
|
+
print(list_problems()) # ['CB-001', 'CB-002', ..., 'TX-008']
|
|
211
|
+
|
|
212
|
+
# List by category
|
|
213
|
+
print(list_by_category("rate_limiting")) # ['RL-001', ..., 'RL-008']
|
|
214
|
+
|
|
215
|
+
# Get problem spec
|
|
216
|
+
spec = get_problem("RL-001")
|
|
217
|
+
print(spec.name) # "Token Bucket Rate Limiter"
|
|
218
|
+
print(spec.description) # Full problem description
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Python Subset
|
|
222
|
+
|
|
223
|
+
The verifier supports a restricted Python subset for Z3 encoding:
|
|
224
|
+
|
|
225
|
+
**Supported:**
|
|
226
|
+
- Simple assignments: `x = expr`, `self.x = expr`
|
|
227
|
+
- Augmented assignments: `x += expr`, `x -= expr`
|
|
228
|
+
- Conditionals: `if/elif/else`
|
|
229
|
+
- Loops: `while`, `for x in range(n)`
|
|
230
|
+
- Returns: `return expr`
|
|
231
|
+
- Built-ins: `min`, `max`, `abs`
|
|
232
|
+
- Ternary: `x if cond else y`
|
|
233
|
+
|
|
234
|
+
**Not Supported:**
|
|
235
|
+
- Lists, dicts, sets
|
|
236
|
+
- Imports
|
|
237
|
+
- Exceptions (try/except)
|
|
238
|
+
- Classes
|
|
239
|
+
- List comprehensions
|
|
240
|
+
- Lambda functions
|
|
241
|
+
|
|
242
|
+
## API Reference
|
|
243
|
+
|
|
244
|
+
### Core Classes
|
|
245
|
+
|
|
246
|
+
- `ProblemSpec`: Problem specification with properties
|
|
247
|
+
- `VerificationResult`: Result of verification
|
|
248
|
+
- `SynthesisResult`: Result of synthesis
|
|
249
|
+
- `StructuredFeedback`: CE2P feedback with fault localization
|
|
250
|
+
|
|
251
|
+
### Functions
|
|
252
|
+
|
|
253
|
+
- `verify(code, spec)`: Verify code against properties
|
|
254
|
+
- `synthesize(spec, llm)`: Synthesize verified code
|
|
255
|
+
- `generate_feedback(code, result, spec)`: Generate CE2P feedback
|
|
256
|
+
- `encode_method(code, spec)`: Encode Python to Z3
|
|
257
|
+
|
|
258
|
+
### LLM Clients
|
|
259
|
+
|
|
260
|
+
- `OpenAIClient`: GPT-4 and other OpenAI models
|
|
261
|
+
- `AnthropicClient`: Claude models
|
|
262
|
+
- `OllamaClient`: Local Ollama models
|
|
263
|
+
|
|
264
|
+
## Development
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Clone and install in development mode
|
|
268
|
+
git clone https://github.com/rotalabs/rotalabs-verity.git
|
|
269
|
+
cd rotalabs-verity
|
|
270
|
+
pip install -e ".[dev]"
|
|
271
|
+
|
|
272
|
+
# Run tests
|
|
273
|
+
pytest tests/ -v
|
|
274
|
+
|
|
275
|
+
# Format code
|
|
276
|
+
black src/ tests/
|
|
277
|
+
ruff check src/ tests/
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Citation
|
|
281
|
+
|
|
282
|
+
If you use this package in research, please cite:
|
|
283
|
+
|
|
284
|
+
```bibtex
|
|
285
|
+
@software{rotalabs_verity,
|
|
286
|
+
title = {rotalabs-verity: Verified Code Synthesis with Z3},
|
|
287
|
+
author = {Rotalabs},
|
|
288
|
+
year = {2025},
|
|
289
|
+
url = {https://github.com/rotalabs/rotalabs-verity}
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Related Work
|
|
294
|
+
|
|
295
|
+
This package builds on research in:
|
|
296
|
+
|
|
297
|
+
- CEGIS (Counterexample-Guided Inductive Synthesis)
|
|
298
|
+
- Neuro-symbolic program synthesis
|
|
299
|
+
- SMT-based program verification
|
|
300
|
+
- Contrastive counterexample generation
|
|
301
|
+
|
|
302
|
+
## License
|
|
303
|
+
|
|
304
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
305
|
+
|
|
306
|
+
## Links
|
|
307
|
+
|
|
308
|
+
- Documentation: https://rotalabs.github.io/rotalabs-verity/
|
|
309
|
+
- PyPI: https://pypi.org/project/rotalabs-verity/
|
|
310
|
+
- GitHub: https://github.com/rotalabs/rotalabs-verity
|
|
311
|
+
- Website: https://rotalabs.ai
|
|
312
|
+
- Contact: research@rotalabs.ai
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# rotalabs-verity
|
|
2
|
+
|
|
3
|
+
Verified code synthesis with Z3. Formally verify LLM-generated code using neuro-symbolic synthesis.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`rotalabs-verity` is a neuro-symbolic synthesis framework that uses Z3 SMT solver to formally verify LLM-generated code. It implements CEGIS (Counterexample-Guided Inductive Synthesis) with CE2P (Counterexample-to-Program) feedback for structured repair suggestions.
|
|
8
|
+
|
|
9
|
+
### Key Features
|
|
10
|
+
|
|
11
|
+
- **Formal Verification**: Verify Python code against temporal properties using Z3
|
|
12
|
+
- **CEGIS Loop**: Iterative synthesis with LLM generation and Z3 verification
|
|
13
|
+
- **CE2P Feedback**: Structured counterexample analysis with fault localization and abductive repair
|
|
14
|
+
- **Multi-LLM Support**: OpenAI, Anthropic Claude, and local Ollama models
|
|
15
|
+
- **50 Benchmark Problems**: Rate limiting, circuit breakers, concurrency, consensus, replication, transactions
|
|
16
|
+
- **Python-to-Z3 Encoder**: Automatic translation of Python code to Z3 constraints
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Basic Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install rotalabs-verity
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### With LLM Providers
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# OpenAI (GPT-4)
|
|
30
|
+
pip install rotalabs-verity[openai]
|
|
31
|
+
|
|
32
|
+
# Anthropic (Claude)
|
|
33
|
+
pip install rotalabs-verity[anthropic]
|
|
34
|
+
|
|
35
|
+
# Local Ollama
|
|
36
|
+
pip install rotalabs-verity[ollama]
|
|
37
|
+
|
|
38
|
+
# All LLM providers
|
|
39
|
+
pip install rotalabs-verity[llm]
|
|
40
|
+
|
|
41
|
+
# All optional dependencies
|
|
42
|
+
pip install rotalabs-verity[all]
|
|
43
|
+
|
|
44
|
+
# Development dependencies
|
|
45
|
+
pip install rotalabs-verity[dev]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Verify Code Against Properties
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from rotalabs_verity import verify, VerificationStatus
|
|
54
|
+
from rotalabs_verity.problems import get_problem
|
|
55
|
+
|
|
56
|
+
# Load a benchmark problem
|
|
57
|
+
spec = get_problem("RL-001") # Token bucket rate limiter
|
|
58
|
+
|
|
59
|
+
# Code to verify
|
|
60
|
+
code = """
|
|
61
|
+
def allow(self, timestamp: float) -> bool:
|
|
62
|
+
if self.tokens >= 1:
|
|
63
|
+
self.tokens -= 1
|
|
64
|
+
return True
|
|
65
|
+
return False
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
# Verify
|
|
69
|
+
result = verify(code, spec)
|
|
70
|
+
|
|
71
|
+
if result.status == VerificationStatus.VERIFIED:
|
|
72
|
+
print("Code is correct!")
|
|
73
|
+
elif result.status == VerificationStatus.COUNTEREXAMPLE:
|
|
74
|
+
print(f"Bug found: {result.counterexample}")
|
|
75
|
+
print(f"Property violated: {result.property_violated.property_name}")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Synthesize Verified Code with LLM
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from rotalabs_verity import synthesize, SynthesisStatus
|
|
82
|
+
from rotalabs_verity.llm import OpenAIClient
|
|
83
|
+
from rotalabs_verity.problems import get_problem
|
|
84
|
+
|
|
85
|
+
# Load problem
|
|
86
|
+
spec = get_problem("RL-001")
|
|
87
|
+
|
|
88
|
+
# Create LLM client
|
|
89
|
+
llm = OpenAIClient(model="gpt-4")
|
|
90
|
+
|
|
91
|
+
# Synthesize with CEGIS loop
|
|
92
|
+
result = synthesize(spec, llm, max_iterations=10)
|
|
93
|
+
|
|
94
|
+
if result.status == SynthesisStatus.SUCCESS:
|
|
95
|
+
print(f"Synthesized verified code in {result.iterations} iterations:")
|
|
96
|
+
print(result.code)
|
|
97
|
+
else:
|
|
98
|
+
print(f"Synthesis failed: {result.error_message}")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Use CE2P Feedback
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from rotalabs_verity import verify, generate_feedback
|
|
105
|
+
from rotalabs_verity.problems import get_problem
|
|
106
|
+
|
|
107
|
+
spec = get_problem("RL-001")
|
|
108
|
+
|
|
109
|
+
buggy_code = """
|
|
110
|
+
def allow(self, timestamp: float) -> bool:
|
|
111
|
+
self.tokens -= 1 # Bug: doesn't check if tokens available
|
|
112
|
+
return True
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
result = verify(buggy_code, spec)
|
|
116
|
+
feedback = generate_feedback(buggy_code, result, spec=spec)
|
|
117
|
+
|
|
118
|
+
print(f"Property violated: {feedback.property_violated.property_name}")
|
|
119
|
+
print(f"Fault at line {feedback.fault_line}: {feedback.root_cause}")
|
|
120
|
+
print(f"Suggested fix: {feedback.suggested_fix}")
|
|
121
|
+
print(f"Guard condition: {feedback.repair_guard}")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### CLI Usage
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# List available problems
|
|
128
|
+
rotalabs-verity --list
|
|
129
|
+
|
|
130
|
+
# Synthesize solution for a problem
|
|
131
|
+
rotalabs-verity RL-001
|
|
132
|
+
|
|
133
|
+
# Use different LLM provider
|
|
134
|
+
rotalabs-verity RL-001 --provider anthropic
|
|
135
|
+
|
|
136
|
+
# Disable CE2P feedback
|
|
137
|
+
rotalabs-verity RL-001 --no-ce2p
|
|
138
|
+
|
|
139
|
+
# Save results to file
|
|
140
|
+
rotalabs-verity RL-001 --output results.json
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Benchmark Problems
|
|
144
|
+
|
|
145
|
+
50 problems across 6 categories:
|
|
146
|
+
|
|
147
|
+
| Category | Problems | Description |
|
|
148
|
+
|----------|----------|-------------|
|
|
149
|
+
| **RL** (Rate Limiting) | 8 | Token bucket, sliding window, leaky bucket, etc. |
|
|
150
|
+
| **CB** (Circuit Breaker) | 8 | Circuit breaker, bulkhead, retry, timeout, etc. |
|
|
151
|
+
| **CO** (Concurrency) | 8 | Distributed lock, semaphore, barrier, latch, etc. |
|
|
152
|
+
| **CN** (Consensus) | 9 | Leader election, Paxos, Raft, view change, etc. |
|
|
153
|
+
| **RP** (Replication) | 9 | Primary-backup, chain replication, quorum, etc. |
|
|
154
|
+
| **TX** (Transactions) | 8 | 2PC, saga, outbox, TCC, WAL, etc. |
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from rotalabs_verity.problems import list_problems, list_by_category, get_problem
|
|
158
|
+
|
|
159
|
+
# List all problems
|
|
160
|
+
print(list_problems()) # ['CB-001', 'CB-002', ..., 'TX-008']
|
|
161
|
+
|
|
162
|
+
# List by category
|
|
163
|
+
print(list_by_category("rate_limiting")) # ['RL-001', ..., 'RL-008']
|
|
164
|
+
|
|
165
|
+
# Get problem spec
|
|
166
|
+
spec = get_problem("RL-001")
|
|
167
|
+
print(spec.name) # "Token Bucket Rate Limiter"
|
|
168
|
+
print(spec.description) # Full problem description
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Python Subset
|
|
172
|
+
|
|
173
|
+
The verifier supports a restricted Python subset for Z3 encoding:
|
|
174
|
+
|
|
175
|
+
**Supported:**
|
|
176
|
+
- Simple assignments: `x = expr`, `self.x = expr`
|
|
177
|
+
- Augmented assignments: `x += expr`, `x -= expr`
|
|
178
|
+
- Conditionals: `if/elif/else`
|
|
179
|
+
- Loops: `while`, `for x in range(n)`
|
|
180
|
+
- Returns: `return expr`
|
|
181
|
+
- Built-ins: `min`, `max`, `abs`
|
|
182
|
+
- Ternary: `x if cond else y`
|
|
183
|
+
|
|
184
|
+
**Not Supported:**
|
|
185
|
+
- Lists, dicts, sets
|
|
186
|
+
- Imports
|
|
187
|
+
- Exceptions (try/except)
|
|
188
|
+
- Classes
|
|
189
|
+
- List comprehensions
|
|
190
|
+
- Lambda functions
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### Core Classes
|
|
195
|
+
|
|
196
|
+
- `ProblemSpec`: Problem specification with properties
|
|
197
|
+
- `VerificationResult`: Result of verification
|
|
198
|
+
- `SynthesisResult`: Result of synthesis
|
|
199
|
+
- `StructuredFeedback`: CE2P feedback with fault localization
|
|
200
|
+
|
|
201
|
+
### Functions
|
|
202
|
+
|
|
203
|
+
- `verify(code, spec)`: Verify code against properties
|
|
204
|
+
- `synthesize(spec, llm)`: Synthesize verified code
|
|
205
|
+
- `generate_feedback(code, result, spec)`: Generate CE2P feedback
|
|
206
|
+
- `encode_method(code, spec)`: Encode Python to Z3
|
|
207
|
+
|
|
208
|
+
### LLM Clients
|
|
209
|
+
|
|
210
|
+
- `OpenAIClient`: GPT-4 and other OpenAI models
|
|
211
|
+
- `AnthropicClient`: Claude models
|
|
212
|
+
- `OllamaClient`: Local Ollama models
|
|
213
|
+
|
|
214
|
+
## Development
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Clone and install in development mode
|
|
218
|
+
git clone https://github.com/rotalabs/rotalabs-verity.git
|
|
219
|
+
cd rotalabs-verity
|
|
220
|
+
pip install -e ".[dev]"
|
|
221
|
+
|
|
222
|
+
# Run tests
|
|
223
|
+
pytest tests/ -v
|
|
224
|
+
|
|
225
|
+
# Format code
|
|
226
|
+
black src/ tests/
|
|
227
|
+
ruff check src/ tests/
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Citation
|
|
231
|
+
|
|
232
|
+
If you use this package in research, please cite:
|
|
233
|
+
|
|
234
|
+
```bibtex
|
|
235
|
+
@software{rotalabs_verity,
|
|
236
|
+
title = {rotalabs-verity: Verified Code Synthesis with Z3},
|
|
237
|
+
author = {Rotalabs},
|
|
238
|
+
year = {2025},
|
|
239
|
+
url = {https://github.com/rotalabs/rotalabs-verity}
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Related Work
|
|
244
|
+
|
|
245
|
+
This package builds on research in:
|
|
246
|
+
|
|
247
|
+
- CEGIS (Counterexample-Guided Inductive Synthesis)
|
|
248
|
+
- Neuro-symbolic program synthesis
|
|
249
|
+
- SMT-based program verification
|
|
250
|
+
- Contrastive counterexample generation
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
255
|
+
|
|
256
|
+
## Links
|
|
257
|
+
|
|
258
|
+
- Documentation: https://rotalabs.github.io/rotalabs-verity/
|
|
259
|
+
- PyPI: https://pypi.org/project/rotalabs-verity/
|
|
260
|
+
- GitHub: https://github.com/rotalabs/rotalabs-verity
|
|
261
|
+
- Website: https://rotalabs.ai
|
|
262
|
+
- Contact: research@rotalabs.ai
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Core Types
|
|
2
|
+
|
|
3
|
+
Core type definitions for verification and synthesis.
|
|
4
|
+
|
|
5
|
+
## Verification Status
|
|
6
|
+
|
|
7
|
+
::: rotalabs_verity.core.types.VerificationStatus
|
|
8
|
+
|
|
9
|
+
## Synthesis Status
|
|
10
|
+
|
|
11
|
+
::: rotalabs_verity.core.types.SynthesisStatus
|
|
12
|
+
|
|
13
|
+
## Counterexample
|
|
14
|
+
|
|
15
|
+
::: rotalabs_verity.core.types.Counterexample
|
|
16
|
+
|
|
17
|
+
## Property Violation
|
|
18
|
+
|
|
19
|
+
::: rotalabs_verity.core.types.PropertyViolation
|
|
20
|
+
|
|
21
|
+
## Verification Result
|
|
22
|
+
|
|
23
|
+
::: rotalabs_verity.core.types.VerificationResult
|
|
24
|
+
|
|
25
|
+
## Synthesis Result
|
|
26
|
+
|
|
27
|
+
::: rotalabs_verity.core.types.SynthesisResult
|
|
28
|
+
|
|
29
|
+
## Trace Step
|
|
30
|
+
|
|
31
|
+
::: rotalabs_verity.core.types.TraceStep
|
|
32
|
+
|
|
33
|
+
## Structured Feedback
|
|
34
|
+
|
|
35
|
+
::: rotalabs_verity.core.types.StructuredFeedback
|