SMT Solver¶
Low-level SMT solving with Z3.
Overview¶
The SMT solver module provides:
- SMTVerifier: Low-level Z3 integration
- VerificationResult: Verification results
- VerificationStatus: Result status enum
Class Documentation¶
upir.verification.solver.VerificationStatus
¶
Bases: Enum
Status of a formal verification attempt.
Based on standard SMT solver result categories. Verification can: - PROVED: Property definitely holds (satisfiable/valid) - DISPROVED: Property definitely does not hold (counterexample found) - UNKNOWN: Solver cannot determine (incomplete theory, heuristics failed) - TIMEOUT: Verification exceeded time limit - ERROR: Internal error during verification
References: - SMT-LIB standard: Standard result categories - Z3 solver results: sat, unsat, unknown
Source code in upir/verification/solver.py
upir.verification.solver.VerificationResult
dataclass
¶
Result of verifying a temporal property against an architecture.
Verification results capture everything needed to understand whether a property holds, including the property itself, verification status, optional proof certificate, counterexamples if disproved, and metadata.
Based on TD Commons disclosure, verification results enable: - Decision making: Is this architecture safe? - Debugging: Why did verification fail? (counterexample) - Caching: Avoid re-verifying (cached flag) - Provenance: What was proved and when? (certificate)
Attributes:
| Name | Type | Description |
|---|---|---|
property |
TemporalProperty
|
The temporal property that was verified |
status |
VerificationStatus
|
Verification status (PROVED, DISPROVED, etc.) |
certificate |
Optional[ProofCertificate]
|
Optional proof certificate for PROVED results |
counterexample |
Optional[Dict[str, Any]]
|
Optional counterexample for DISPROVED results |
execution_time |
float
|
Time taken for verification (seconds) |
cached |
bool
|
Whether result came from cache (not freshly computed) |
Example
result = VerificationResult( ... property=TemporalProperty(...), ... status=VerificationStatus.PROVED, ... certificate=ProofCertificate(...), ... counterexample=None, ... execution_time=1.23, ... cached=False ... ) result.verified True
References: - TD Commons: Verification result structure - SMT solving: Standard result format (status + model/proof)
Source code in upir/verification/solver.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
Functions¶
verified()
¶
Check if property was successfully verified (proved).
Returns:
| Type | Description |
|---|---|
bool
|
True if status is PROVED, False otherwise |
Example
result = VerificationResult( ... property=TemporalProperty(...), ... status=VerificationStatus.PROVED, ... execution_time=1.0 ... ) result.verified True result2 = VerificationResult( ... property=TemporalProperty(...), ... status=VerificationStatus.UNKNOWN, ... execution_time=1.0 ... ) result2.verified False
Source code in upir/verification/solver.py
to_dict()
¶
Serialize verification result to JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with all result fields |
Example
result = VerificationResult( ... property=TemporalProperty(...), ... status=VerificationStatus.PROVED, ... execution_time=1.23 ... ) d = result.to_dict() d["status"] 'PROVED'
Source code in upir/verification/solver.py
from_dict(data)
classmethod
¶
Deserialize verification result from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing result fields |
required |
Returns:
| Type | Description |
|---|---|
VerificationResult
|
VerificationResult instance |
Example
data = { ... "property": {...}, ... "status": "PROVED", ... "certificate": None, ... "counterexample": None, ... "execution_time": 1.23, ... "cached": False ... } result = VerificationResult.from_dict(data) result.status == VerificationStatus.PROVED True
Source code in upir/verification/solver.py
__str__()
¶
Human-readable string representation.
Source code in upir/verification/solver.py
__repr__()
¶
Developer-friendly representation.
upir.verification.solver.ProofCertificate
dataclass
¶
A certificate attesting to a formal verification result.
Proof certificates provide cryptographically verifiable evidence that a property was (or was not) proved for a specific architecture at a specific time with specific assumptions.
Based on TD Commons disclosure, certificates enable: - Reproducibility: Same property + architecture should give same result - Auditability: Trace what was verified and when - Caching: Avoid re-proving same properties
Attributes:
| Name | Type | Description |
|---|---|---|
property_hash |
str
|
SHA-256 hash of the temporal property |
architecture_hash |
str
|
SHA-256 hash of the architecture |
status |
VerificationStatus
|
Verification result status |
proof_steps |
List[Dict[str, Any]]
|
List of proof steps (solver-specific format) |
assumptions |
List[str]
|
List of assumptions made during proof |
timestamp |
datetime
|
When verification was performed (UTC) |
solver_version |
str
|
Version of solver used (e.g., "z3-4.12.2") |
Example
cert = ProofCertificate( ... property_hash="abc123...", ... architecture_hash="def456...", ... status=VerificationStatus.PROVED, ... proof_steps=[{"step": 1, "action": "simplify"}], ... assumptions=["network_reliable"], ... timestamp=datetime.utcnow(), ... solver_version="z3-4.12.2" ... ) cert_hash = cert.generate_hash()
References: - TD Commons: Proof certificate structure - Cryptographic certificates: SHA-256 for integrity
Source code in upir/verification/solver.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
Functions¶
generate_hash()
¶
Generate SHA-256 hash of this certificate for integrity verification.
The hash is computed over all certificate fields (except the hash itself) in a deterministic way to enable verification that the certificate has not been tampered with.
Returns:
| Type | Description |
|---|---|
str
|
Hexadecimal SHA-256 hash string |
Example
cert = ProofCertificate( ... property_hash="abc", ... architecture_hash="def", ... status=VerificationStatus.PROVED, ... timestamp=datetime(2024, 1, 1, 12, 0, 0), ... solver_version="z3-4.12.2" ... ) hash1 = cert.generate_hash() hash2 = cert.generate_hash() hash1 == hash2 # Deterministic True
References: - SHA-256: Industry standard cryptographic hash - Python hashlib: https://docs.python.org/3/library/hashlib.html
Source code in upir/verification/solver.py
to_dict()
¶
Serialize proof certificate to JSON-compatible dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with all certificate fields |
Example
cert = ProofCertificate( ... property_hash="abc", ... architecture_hash="def", ... status=VerificationStatus.PROVED, ... timestamp=datetime(2024, 1, 1, 12, 0, 0), ... solver_version="z3-4.12.2" ... ) d = cert.to_dict() d["status"] 'PROVED'
Source code in upir/verification/solver.py
from_dict(data)
classmethod
¶
Deserialize proof certificate from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary containing certificate fields |
required |
Returns:
| Type | Description |
|---|---|
ProofCertificate
|
ProofCertificate instance |
Example
data = { ... "property_hash": "abc", ... "architecture_hash": "def", ... "status": "PROVED", ... "proof_steps": [], ... "assumptions": [], ... "timestamp": "2024-01-01T12:00:00", ... "solver_version": "z3-4.12.2" ... } cert = ProofCertificate.from_dict(data) cert.status == VerificationStatus.PROVED True
Source code in upir/verification/solver.py
See Also¶
- Verifier - High-level verification API