Sync with GitHub, license metadata from LICENSE files, commercial license notice
Browse files
README.md
CHANGED
|
@@ -1,398 +1,418 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
ββ
|
| 12 |
-
ββ
|
| 13 |
-
ββ
|
| 14 |
-
βββ
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
<img src="https://img.shields.io/badge/
|
| 31 |
-
</
|
| 32 |
-
|
| 33 |
-
---
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
β
|
| 56 |
-
β
|
| 57 |
-
β
|
| 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 |
-
[OK]
|
| 91 |
-
[OK]
|
| 92 |
-
[OK]
|
| 93 |
-
[OK]
|
| 94 |
-
[OK]
|
| 95 |
-
[OK]
|
| 96 |
-
[OK]
|
| 97 |
-
[OK]
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
def
|
| 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 |
-
β Proof
|
| 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 |
-
|
| 220 |
-
|
| 221 |
-
|
| 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 |
-
[OK]
|
| 327 |
-
[OK]
|
| 328 |
-
[OK]
|
| 329 |
-
[OK]
|
| 330 |
-
[OK]
|
| 331 |
-
[OK]
|
| 332 |
-
[OK]
|
| 333 |
-
[OK]
|
| 334 |
-
[OK]
|
| 335 |
-
[OK]
|
| 336 |
-
[OK]
|
| 337 |
-
[OK]
|
| 338 |
-
[OK]
|
| 339 |
-
[OK]
|
| 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 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
β
|
| 394 |
-
β
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: agpl-3.0
|
| 3 |
+
tags:
|
| 4 |
+
- snapkitty
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
<p align="center">
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
βββββββ βββ ββββββββββ ββββββββ
|
| 11 |
+
βββββββββββ βββββββββββββββββββ
|
| 12 |
+
βββββββββββ βββββββββββββββββ
|
| 13 |
+
βββββββ βββ βββββββββββββββββ
|
| 14 |
+
βββ ββββββββββββ βββββββββββ
|
| 15 |
+
βββ βββββββ βββ βββββββββββ
|
| 16 |
+
|
| 17 |
+
βββ βββ ββββββ βββ ββββββββββ βββββββββββββββ βββ
|
| 18 |
+
βοΏ½οΏ½οΏ½β ββββββββββββββ βββββββββββββββββββββββββββ ββββ
|
| 19 |
+
βββ ββββββββββββββ ββββββ ββββββ βββ βββββββ
|
| 20 |
+
ββββ βββββββββββββββ ββββββ ββββββ βββ βββββ
|
| 21 |
+
βββββββ βββ βββββββββββββββββββββββββ βββ βββ
|
| 22 |
+
βββββ βββ βββββββββββββββββββββ βββ βββ βββ
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
</p>
|
| 26 |
+
|
| 27 |
+
<h3 align="center">Formal verification from NAND gates to proof certificates.</h3>
|
| 28 |
+
|
| 29 |
+
<p align="center">
|
| 30 |
+
<img src="https://img.shields.io/badge/core-Haskell-5e5086?style=flat-square"/>
|
| 31 |
+
<img src="https://img.shields.io/badge/backend-Fortran-734f96?style=flat-square"/>
|
| 32 |
+
<img src="https://img.shields.io/badge/solver-CDCL+DPLL-blue?style=flat-square"/>
|
| 33 |
+
<img src="https://img.shields.io/badge/kernel-80_LOC-brightgreen?style=flat-square"/>
|
| 34 |
+
<img src="https://img.shields.io/badge/tests-20_passing-brightgreen?style=flat-square"/>
|
| 35 |
+
<img src="https://img.shields.io/badge/deps-containers_only-black?style=flat-square"/>
|
| 36 |
+
<img src="https://img.shields.io/badge/license-AGPL--3.0-red?style=flat-square"/>
|
| 37 |
+
</p>
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## What Is This?
|
| 42 |
+
|
| 43 |
+
A self-contained formal verification engine built from first principles. No Z3. No SMT solver dependency. No Lean. No Coq. Just:
|
| 44 |
+
|
| 45 |
+
- A source language (`.nf` files) where NAND is the only primitive
|
| 46 |
+
- A compiler that elaborates definitions into Boolean circuits
|
| 47 |
+
- A SAT solver (DPLL + CDCL with clause learning) that searches for proofs
|
| 48 |
+
- A proof-producing backend that emits resolution certificates
|
| 49 |
+
- A **trusted kernel** (~80 lines) that independently verifies those certificates
|
| 50 |
+
|
| 51 |
+
The foundational principle: **the engine searches, the kernel decides.**
|
| 52 |
+
|
| 53 |
+
```
|
| 54 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 55 |
+
β β
|
| 56 |
+
β THE SEPARATION β
|
| 57 |
+
β β
|
| 58 |
+
β SOLVER (complex, 1000+ LOC) KERNEL (simple, ~80 LOC) β
|
| 59 |
+
β βββββββββββββββββββββββββ ββββββββββββββββββββββ β
|
| 60 |
+
β β
|
| 61 |
+
β Heuristics, backtracking, Resolution step checker β
|
| 62 |
+
β clause learning, unit prop, Clause validation β
|
| 63 |
+
β decision ordering, restarts Hash verification β
|
| 64 |
+
β β
|
| 65 |
+
β MAY HAVE BUGS MUST BE CORRECT β
|
| 66 |
+
β (if buggy: proof won't verify) (if buggy: false validity) β
|
| 67 |
+
β β
|
| 68 |
+
β A bug in the solver = A bug in the kernel = β
|
| 69 |
+
β "failed to find proof" "accepted invalid proof" β
|
| 70 |
+
β (safe failure) (unsound β the only real risk) β
|
| 71 |
+
β β
|
| 72 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## Quick Start
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
git clone https://github.com/SNAPKITTYWEST/pure-validity
|
| 81 |
+
cd pure-validity
|
| 82 |
+
cabal build
|
| 83 |
+
cabal run pure-validity -- examples/gates.nf
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
```
|
| 87 |
+
Module: gates
|
| 88 |
+
Properties: 16
|
| 89 |
+
|
| 90 |
+
[OK] not_true
|
| 91 |
+
[OK] not_false
|
| 92 |
+
[OK] and_tt
|
| 93 |
+
[OK] and_tf
|
| 94 |
+
[OK] and_ft
|
| 95 |
+
[OK] and_ff
|
| 96 |
+
[OK] or_tt
|
| 97 |
+
[OK] or_tf
|
| 98 |
+
[OK] or_ft
|
| 99 |
+
[OK] or_ff
|
| 100 |
+
[OK] xor_tt
|
| 101 |
+
[OK] xor_tf
|
| 102 |
+
[OK] xor_ft
|
| 103 |
+
[OK] xor_ff
|
| 104 |
+
|
| 105 |
+
16/16 verified.
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## The Language β `.nf` files
|
| 111 |
+
|
| 112 |
+
NAND is the only hardware primitive. Everything else is defined, not assumed.
|
| 113 |
+
|
| 114 |
+
```
|
| 115 |
+
-- gates.nf β derive all logic from NAND alone
|
| 116 |
+
|
| 117 |
+
def not(x) = (x | x);
|
| 118 |
+
|
| 119 |
+
def and(x y) = not((x | y));
|
| 120 |
+
|
| 121 |
+
def or(x y) = (not(x) | not(y));
|
| 122 |
+
|
| 123 |
+
def xor(x y) = ((x | (x | y)) | (y | (x | y)));
|
| 124 |
+
|
| 125 |
+
-- Prove correctness of derived gates
|
| 126 |
+
prove and_tt: and(true true) = true;
|
| 127 |
+
prove xor_tf: xor(true false) = true;
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
### Syntax Reference
|
| 131 |
+
|
| 132 |
+
```
|
| 133 |
+
ββββββββββββββββββββββ¦ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 134 |
+
β CONSTRUCT β MEANING β
|
| 135 |
+
β βββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 136 |
+
β (a | b) β NAND β the only primitive gate β
|
| 137 |
+
β def f(x y) = e; β Define a named circuit β
|
| 138 |
+
β prove n: e; β State and verify a property β
|
| 139 |
+
β assert e; β Verify without naming β
|
| 140 |
+
β true / false β Boolean constants β
|
| 141 |
+
β -- comment β Line comment β
|
| 142 |
+
β module name; β Module declaration β
|
| 143 |
+
ββββββββββββββββββββββ©ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
## Verification Pipeline
|
| 149 |
+
|
| 150 |
+
```
|
| 151 |
+
.nf source file
|
| 152 |
+
β
|
| 153 |
+
βΌ
|
| 154 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 155 |
+
β LEXER + PARSER β
|
| 156 |
+
β Language/Lexer.hs + Language/Parser.hs β
|
| 157 |
+
β Source text β Token stream β AST (Module of Stmts) β
|
| 158 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
+
β
|
| 160 |
+
βΌ
|
| 161 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 162 |
+
β ELABORATOR β
|
| 163 |
+
β Language/Elaborator.hs β
|
| 164 |
+
β AST β Boolean IR (BExpr trees β NAND-only) β
|
| 165 |
+
β Inlines function applications, resolves names β
|
| 166 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 167 |
+
β
|
| 168 |
+
βΌ
|
| 169 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 170 |
+
β TSEITIN TRANSFORM β
|
| 171 |
+
β SAT/CNF.hs β
|
| 172 |
+
β BExpr β CNF (conjunctive normal form) β
|
| 173 |
+
β Introduces auxiliary variables, linear blowup β
|
| 174 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 175 |
+
β
|
| 176 |
+
βΌ
|
| 177 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 178 |
+
β SAT SOLVER (DPLL + CDCL) β
|
| 179 |
+
β SAT/DPLL.hs + SAT/CDCL.hs β
|
| 180 |
+
β Unit propagation β decision β conflict β backtrack β
|
| 181 |
+
β Clause learning on conflict (CDCL) β
|
| 182 |
+
β Proof-producing: records resolution steps β
|
| 183 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 184 |
+
β
|
| 185 |
+
βΌ
|
| 186 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 187 |
+
β PROOF CERTIFICATE β
|
| 188 |
+
β Proof/Certificate.hs + Proof/Produce.hs β
|
| 189 |
+
β Resolution steps + SHA-256 hash β
|
| 190 |
+
β Conclusion: Valid | Unsatisfiable | CounterExample β
|
| 191 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
+
β
|
| 193 |
+
βΌ
|
| 194 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 195 |
+
β TRUSTED KERNEL (~80 LOC) β
|
| 196 |
+
β Checker/Kernel.hs β
|
| 197 |
+
β Independently verifies every resolution step β
|
| 198 |
+
β Accepts or rejects the certificate β
|
| 199 |
+
β THE ONLY CODE THAT MUST BE CORRECT β
|
| 200 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½βββββββ
|
| 201 |
+
β
|
| 202 |
+
βΌ
|
| 203 |
+
[OK] Property verified / [FAIL] Counterexample found
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
---
|
| 207 |
+
|
| 208 |
+
## Architecture β Why Two Layers?
|
| 209 |
+
|
| 210 |
+
The insight from proof-carrying code (Necula 1997): separate the **search** from the **checking**.
|
| 211 |
+
|
| 212 |
+
A solver can be arbitrarily complex β heuristics, restarts, clause deletion, VSIDS scoring. If it has a bug, it just fails to find the proof. The system remains sound.
|
| 213 |
+
|
| 214 |
+
The kernel is trivial by comparison. It receives a claimed proof (sequence of resolution steps) and mechanically verifies each step: did resolving clause A with clause B on pivot variable P actually produce clause C? That's it. ~80 lines. Auditable by hand.
|
| 215 |
+
|
| 216 |
+
```
|
| 217 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 218 |
+
β β
|
| 219 |
+
β Solver bug β "could not prove" (safe, retry with better β
|
| 220 |
+
β heuristics or more time) β
|
| 221 |
+
β β
|
| 222 |
+
β Kernel bug β false validity claim (unsound β THE risk) β
|
| 223 |
+
β But kernel is 80 LOC, auditable, testable β
|
| 224 |
+
β β
|
| 225 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
---
|
| 229 |
+
|
| 230 |
+
## Fortran Backend
|
| 231 |
+
|
| 232 |
+
For hardware-scale verification (thousands of gates), the Fortran backend provides vectorized clause checking and bounded model checking:
|
| 233 |
+
|
| 234 |
+
```fortran
|
| 235 |
+
! bitvec_ops.f90 β bulk NAND evaluation + clause checking
|
| 236 |
+
call bulk_clause_check(clauses, num_clauses, clause_lens, assignment, num_vars, satisfied)
|
| 237 |
+
|
| 238 |
+
! state_machine.f90 β bounded model checking with induction
|
| 239 |
+
result = bmc_check(transition_gates, ..., init_state, state_width, bound)
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
The Fortran modules handle:
|
| 243 |
+
- Vectorized NAND evaluation over flat gate arrays
|
| 244 |
+
- Bulk satisfiability checking across all clauses simultaneously
|
| 245 |
+
- Ripple-carry addition for arithmetic circuit verification
|
| 246 |
+
- Bounded model checking (BMC) for sequential circuits
|
| 247 |
+
- k-induction for unbounded property proofs
|
| 248 |
+
|
| 249 |
+
---
|
| 250 |
+
|
| 251 |
+
## Examples
|
| 252 |
+
|
| 253 |
+
```
|
| 254 |
+
βββββββββββββββββββββ¦βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 255 |
+
β FILE β WHAT IT PROVES β
|
| 256 |
+
β ββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 257 |
+
β nand.nf β NAND truth table (the primitive) β
|
| 258 |
+
β gates.nf β NOT/AND/OR/XOR all correct from NAND alone β
|
| 259 |
+
β half_adder.nf β Binary arithmetic: sum and carry correct β
|
| 260 |
+
β demorgan.nf β De Morgan's Laws hold for NAND-derived gates β
|
| 261 |
+
β mux.nf β 2-to-1 multiplexer selects correctly β
|
| 262 |
+
βββββββββββββββββββββ©βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
Run all examples:
|
| 266 |
+
|
| 267 |
+
```bash
|
| 268 |
+
for f in examples/*.nf; do cabal run pure-validity -- "$f"; echo; done
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
---
|
| 272 |
+
|
| 273 |
+
## Project Layout
|
| 274 |
+
|
| 275 |
+
```
|
| 276 |
+
pure-validity/
|
| 277 |
+
βββ pure-validity.cabal Build configuration
|
| 278 |
+
βββ README.md This file
|
| 279 |
+
β
|
| 280 |
+
βββ src/
|
| 281 |
+
β βββ Main.hs Entry point β file β parse β prove β check
|
| 282 |
+
β βββ Language/
|
| 283 |
+
β β βββ AST.hs Abstract syntax (Expr, Stmt, Module)
|
| 284 |
+
β β βββ Lexer.hs Tokenizer (keywords, operators, idents)
|
| 285 |
+
β β βββ Parser.hs Recursive descent parser
|
| 286 |
+
β β βββ Elaborator.hs AST β Boolean IR (inline + resolve)
|
| 287 |
+
β βββ IR/
|
| 288 |
+
β β βββ Boolean.hs BExpr type + eval + NAND/AND/OR/XOR
|
| 289 |
+
β β βββ NAND.hs NAND normal form transformation
|
| 290 |
+
β β βββ BitVec.hs Bit-vector arithmetic (add, eq, const)
|
| 291 |
+
β βββ SAT/
|
| 292 |
+
β β βββ CNF.hs Clause/literal types + Tseitin transform
|
| 293 |
+
β β βββ UnitProp.hs Unit propagation (BCP)
|
| 294 |
+
β β βββ DPLL.hs Davis-Putnam-Logemann-Loveland solver
|
| 295 |
+
β β βββ CDCL.hs Conflict-Driven Clause Learning solver
|
| 296 |
+
β βββ Proof/
|
| 297 |
+
β β βββ Certificate.hs ProofStep, ProofCertificate types
|
| 298 |
+
β β βββ Produce.hs Validity/UNSAT proof generation
|
| 299 |
+
β βββ Checker/
|
| 300 |
+
β βββ Kernel.hs THE TRUSTED KERNEL (~80 LOC)
|
| 301 |
+
β
|
| 302 |
+
βββ fortran/
|
| 303 |
+
β βββ bitvec_ops.f90 Vectorized NAND + bulk clause check
|
| 304 |
+
β βββ state_machine.f90 BMC + k-induction for sequential circuits
|
| 305 |
+
β
|
| 306 |
+
βββ examples/
|
| 307 |
+
β βββ nand.nf NAND primitive proofs
|
| 308 |
+
β βββ gates.nf All gates from NAND
|
| 309 |
+
β βββ half_adder.nf Arithmetic correctness
|
| 310 |
+
β βββ demorgan.nf De Morgan's Laws
|
| 311 |
+
β βββ mux.nf Multiplexer properties
|
| 312 |
+
β
|
| 313 |
+
βββ test/
|
| 314 |
+
βββ Spec.hs 20 tests β IR, solver, kernel, parser
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
---
|
| 318 |
+
|
| 319 |
+
## Run Tests
|
| 320 |
+
|
| 321 |
+
```bash
|
| 322 |
+
cabal test
|
| 323 |
+
```
|
| 324 |
+
|
| 325 |
+
```
|
| 326 |
+
[OK] NAND truth table
|
| 327 |
+
[OK] NOT from NAND
|
| 328 |
+
[OK] AND from NAND
|
| 329 |
+
[OK] OR from NAND
|
| 330 |
+
[OK] XOR from NAND
|
| 331 |
+
[OK] Half adder sum
|
| 332 |
+
[OK] Half adder carry
|
| 333 |
+
[OK] BitVec add 3+5=8
|
| 334 |
+
[OK] Tseitin preserves satisfiability
|
| 335 |
+
[OK] DPLL finds SAT
|
| 336 |
+
[OK] DPLL finds UNSAT
|
| 337 |
+
[OK] Unit propagation
|
| 338 |
+
[OK] Proof certificate valid
|
| 339 |
+
[OK] Checker accepts valid
|
| 340 |
+
[OK] Checker rejects invalid
|
| 341 |
+
[OK] Parse module
|
| 342 |
+
[OK] Elaborate module
|
| 343 |
+
[OK] NAND normal form
|
| 344 |
+
[OK] De Morgan via eval
|
| 345 |
+
[OK] MUX correctness
|
| 346 |
+
|
| 347 |
+
20/20 tests passed.
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
---
|
| 351 |
+
|
| 352 |
+
## Requirements
|
| 353 |
+
|
| 354 |
+
- GHC 8.10+ (Haskell compiler)
|
| 355 |
+
- Cabal 3.0+
|
| 356 |
+
- gfortran (for Fortran backend, optional)
|
| 357 |
+
- Zero external solver dependencies (no Z3, no MiniSat, no SMT-LIB)
|
| 358 |
+
|
| 359 |
+
```bash
|
| 360 |
+
# Install GHC + Cabal (if needed)
|
| 361 |
+
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
|
| 362 |
+
|
| 363 |
+
# Build and run
|
| 364 |
+
cabal build
|
| 365 |
+
cabal run pure-validity -- examples/gates.nf
|
| 366 |
+
cabal test
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
---
|
| 370 |
+
|
| 371 |
+
## Theory
|
| 372 |
+
|
| 373 |
+
The verification approach combines:
|
| 374 |
+
|
| 375 |
+
1. **Tseitin transformation** β Boolean formula to CNF with linear blowup (not exponential)
|
| 376 |
+
2. **DPLL** β systematic backtracking search with unit propagation
|
| 377 |
+
3. **CDCL** β conflict-driven clause learning for exponential speedup on structured problems
|
| 378 |
+
4. **Resolution proofs** β the solver records why it concluded UNSAT
|
| 379 |
+
5. **Proof checking** β independent verification that each resolution step is valid
|
| 380 |
+
|
| 381 |
+
To prove a property P holds: negate P, convert to CNF, prove UNSAT. If the negation is unsatisfiable, the original property is valid (true under all assignments).
|
| 382 |
+
|
| 383 |
+
---
|
| 384 |
+
|
| 385 |
+
<p align="center">
|
| 386 |
+
<b>Built by Ahmad Ali Parr + SnapKitty Collective</b>
|
| 387 |
+
</p>
|
| 388 |
+
|
| 389 |
+
<p align="center">
|
| 390 |
+
|
| 391 |
+
```
|
| 392 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 393 |
+
β β
|
| 394 |
+
β The engine searches. β
|
| 395 |
+
β The kernel decides. β
|
| 396 |
+
β β
|
| 397 |
+
β If the kernel is correct, the system is sound. β
|
| 398 |
+
β The kernel is 80 lines. β
|
| 399 |
+
β Read them yourself. β
|
| 400 |
+
β β
|
| 401 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 402 |
+
```
|
| 403 |
+
|
| 404 |
+
</p>
|
| 405 |
+
|
| 406 |
+
---
|
| 407 |
+
|
| 408 |
+
## License
|
| 409 |
+
|
| 410 |
+
Licensed under **AGPL-3.0** ([LICENSE](LICENSE)), with these additional license files:
|
| 411 |
+
|
| 412 |
+
- [LICENSE.tri](LICENSE.tri): SnapKitty Tri-License
|
| 413 |
+
|
| 414 |
+
### πΌ Commercial License
|
| 415 |
+
|
| 416 |
+
Snapkitty code is free and open under **AGPL-3.0** for open-source use. Building a commercial product or service? A **proprietary commercial license** from Snapkitty Collective LLC lets you ship this code without the AGPL's source-sharing and network-use obligations.
|
| 417 |
+
|
| 418 |
+
**[β Get a commercial license](mailto:A.parr@belespritdaccord.uk?subject=Commercial%20license:%20pure-validity)** Β· A.parr@belespritdaccord.uk
|