diff --git a/EXPLAINME.adoc b/EXPLAINME.adoc index c83dbad9..e81dc7a6 100644 --- a/EXPLAINME.adoc +++ b/EXPLAINME.adoc @@ -7,13 +7,13 @@ The README makes claims. This file backs them up. == Claims Substantiation -=== Claim 1: "Mathematically proven safe operations. Code that cannot crash, verified with Idris2 dependent types and totality checking." +=== Claim 1: "Safe operations written in Idris2, with dependent types and totality checking." (goal: code that cannot crash) -**How it works:** The 104 core safety modules in `src/Proven/` are written in Idris2 with `%default total`, meaning every function is proved to: (1) terminate (no infinite loops), (2) cover all input cases (no pattern match exceptions), and (3) return a value (no throwing runtime exceptions). Dependent types encode preconditions as types (e.g., `SafeDiv : (a : Nat) -> (b : Nat) -> (h : NonZero b) -> Nat` requires a proof that `b` is nonzero before dividing). The Idris2 compiler enforces these proofs at compile time. Examples: `SafeMath.rs` proves arithmetic never overflows (returns `Result` or bounded nat); `SafeString.rs` proves buffer bounds are checked before reading. FFI bindings call these verified functions only—no reimplementation in other languages. +**How it works:** The core safety modules in `src/Proven/` are written in Idris2, most with `%default total`. A `total` function is checked to (1) terminate and (2) cover all input cases, so it (3) returns a value. **Not every module meets that bar** (measured 2026-11-25, comments excluded): 4 modules use `%default covering` (`SafeJson/Access`, `SafeBase64`, `SafeBase64/Encode`, `SafeRBAC`), 66 functions in 14 files are marked `covering`, and 1 `assert_smaller` site, in `SafeInput`, bypasses the totality checker. Those are not totality-proven. Dependent types encode preconditions as types (e.g., `SafeDiv : (a : Nat) -> (b : Nat) -> (h : NonZero b) -> Nat` requires a proof that `b` is nonzero before dividing). The Idris2 compiler enforces these proofs at compile time. Examples: `SafeMath.idr` returns `Maybe`/bounded results instead of overflowing; `SafeString.idr` checks buffer bounds before reading. FFI bindings call these verified functions only—no reimplementation in other languages. -**Caveat:** Verification covers correctness (no crashes, no undefined behavior), not functional correctness (the algorithm might be wrong). Also, Idris2 proved code is only safe if the FFI bridge (`ffi/zig/`) correctly marshals data. If Zig FFI incorrectly casts types or ignores preconditions, safety claims are violated. Hypatia scans prove this doesn't happen (0 unsafe patterns in critical FFI code). +**Caveat:** For functions the totality checker accepts as `total`, without an `assert_total` or `assert_smaller` escape hatch, Idris2 establishes termination and coverage of every input case, plus the preconditions written into the types. It does not establish this for the `covering` code and escape-hatch sites listed above, and it does not establish functional correctness (the algorithm might still be wrong). The FFI bridge (`ffi/zig/`) is outside the Idris2 check: the Idris2 guarantees hold only if it marshals data correctly. If Zig FFI incorrectly casts types or ignores preconditions, safety claims are violated. Hypatia scans report 0 unsafe patterns in critical FFI code; a scan is evidence, not a proof. -**Evidence:** `src/Proven/SafeMath.idr` with `%default total` and dependent type proofs; `src/Proven/SafeString.idr` with bounds-checked buffer operations. FFI in `ffi/zig/src/main.zig` calls verified functions only. Test suite: 49 tests passing, 0 believe_me count (eliminated via ADR-008). +**Evidence:** `src/Proven/SafeMath.idr` with `%default total` and dependent type proofs; `src/Proven/SafeString.idr` with bounds-checked buffer operations. FFI in `ffi/zig/src/main.zig` calls verified functions only. `believe_me` count: 0 (eliminated via ADR-008). The test suite did not build at the link:AFFIRMATION.adoc[AFFIRMATION] anchor; see its "What we do NOT claim". === Claim 2: "120+ binding targets across 4 computing paradigms without reimplementing logic" @@ -41,7 +41,7 @@ The README makes claims. This file backs them up. |=== | Path | Purpose -| `src/Proven/` | Idris2 core (THE TRUTH): 104 modules, all with `%default total` +| `src/Proven/` | Idris2 core (THE TRUTH): 104 modules, most with `%default total` (4 use `%default covering`; see Claim 1) | `src/Proven/SafeMath.idr` | Arithmetic proofs: overflow-safe add/sub/mul/div, bounded nat, checked operations | `src/Proven/SafeString.idr` | String buffer bounds, encoding safety, slicing without panics | `src/Proven/SafeFloat.idr` | Floating-point proofs: no NaN, denormal, infinity handling, comparison stability @@ -54,7 +54,7 @@ The README makes claims. This file backs them up. | `ffi/zig/` | C ABI bridge layer | `ffi/zig/src/main.zig` | Wraps Idris2 RefC output, exposes C functions for each Safe* module | `ffi/zig/build.zig` | Builds Idris2 code to .o files, links with Zig, outputs shared library -| `bindings/` | Language-specific thin wrappers (18 complete, 102 scaffolded) +| `bindings/` | Language-specific thin wrappers (16 complete, 102 scaffolded) | `bindings/rust/` | Rust bindings: safe_*.rs files call proven FFI via unsafe { } | `bindings/rust/safe_math.rs` | Wraps proven_ffi_safe_add, proven_ffi_safe_mul, etc. | `bindings/zig/src/` | Zig language binding (calls FFI directly; necessarily Zig) @@ -75,4 +75,4 @@ The README makes claims. This file backs them up. == Readiness -**CRG Grade:** C (Beta) - Core modules proven (0 believe_me, 104 modules), Rust/Python/C bindings complete and tested (18 targets), remaining 102 targets scaffolded and awaiting completion. Production-ready for Rust/Python/C; others are research-stage. +**CRG Grade:** C (Beta) - Core modules implemented with 0 `believe_me` (104 modules); not all are totality-proven (1 `assert_smaller` site, 4 `%default covering` modules; see Claim 1), and AFFIRMATION.adoc does not affirm "mathematically proven". 16 binding targets complete and 102 scaffolded: 118 targets in the TOPOLOGY.adoc list, which was not re-measured. The "120+" figure in Claim 2 is the headline count and was not re-measured either. The Python/Cython and ReScript bindings were deleted. Rust and C are the production focus; others are research-stage. diff --git a/README.adoc b/README.adoc index 0fd0efe3..38fd363d 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 -= proven: Formally Verified Safety via Idris2 += proven: Safe Operations in Idris2 with Dependent Types :toc: macro :toclevels: 2 :icons: font @@ -61,13 +61,13 @@ only. Any non‑Idris safety logic in bindings is being removed or rewritten. === Supported Languages [.lead] -*General Purpose:* Ada • C • C++ • Crystal • D • Dart • Deno • Elixir • Elm • Erlang • F# • Gleam • Go • Groovy • Haskell • Java • JavaScript • Julia • Kotlin • Lua • Nim • OCaml • Odin • Perl • PHP • Prolog • PureScript • Python • R • Racket • ReScript • Ruby • Rust • Scala • Swift • Tcl • TypeScript • V • Zig +*General Purpose:* Ada • C • C++ • Crystal • D • Dart • Deno • Elixir • Elm • Erlang • F# • Gleam • Go • Groovy • Haskell • Java • JavaScript • Julia • Kotlin • Lua • Nim • OCaml • Odin • Perl • PHP • Prolog • PureScript • R • Racket • Ruby • Rust • Scala • Swift • Tcl • TypeScript • V • Zig *Shell:* Bash • Fish • PowerShell • Zsh | *Functional:* Clojure • Common Lisp • Guile | *Legacy:* COBOL • Forth • Fortran *Config:* CUE • Dhall • HCL • Jsonnet • JSON-Schema • Nickel • Starlark • YAML-Schema -*Domain:* Arduino • Cairo • CMake • GDScript • Ink • MicroPython • Move • Solidity • Svelte • Unity C# • Vue • Vyper +*Domain:* Arduino • Cairo • CMake • GDScript • Ink • Move • Solidity • Svelte • Unity C# • Vue • Vyper *Query/Policy:* CEL • GraphQL • PromQL • Rego | *Formal:* Alloy • TLA+ | *OS:* BSD • POSIX @@ -135,19 +135,27 @@ only. Any non‑Idris safety logic in bindings is being removed or rewritten. | Core Modules | 104 -| Idris 2 verified implementations (258 total .idr files including FFI wrappers) +| Idris 2 implementations, totality-checked except as listed in <> (802 `.idr` files in the repository, counted 2026-11-17) | Binding Targets | 120+ -| Languages, platforms, and paradigms (18 complete, 102 scaffolded) +| Languages, platforms, and paradigms (16 complete, 102 scaffolded) | believe_me Count | 0 | Eliminated from ~4,566 instances (remediated 2026-02-22) -| Overall Completion -| ~55% -| Core solid (100%), apps (7%), hardware (0%), convenience (0%) +| assert_total / assert_smaller +| 1 +| 1 non-comment site (`assert_smaller` in `SafeInput`); it bypasses the totality checker (see <>) + +| `%default covering` modules +| 4 +| Not totality-checked by default + +| Completion +| 16 of 120+ binding targets +| 102 targets are scaffolded with FFI stubs; apps, hardware and convenience layers are early (see link:TOPOLOGY.adoc[TOPOLOGY.adoc]) |=== === Binding Categories @@ -157,8 +165,8 @@ only. Any non‑Idris safety logic in bindings is being removed or rewritten. | Category | Count | Description | General Purpose -| 39 -| Traditional programming languages (C, Rust, Python, Go, etc.) +| 37 +| Traditional programming languages (C, Rust, Zig, Go, etc.) | Shell/Scripting | 4 @@ -169,7 +177,7 @@ only. Any non‑Idris safety logic in bindings is being removed or rewritten. | CUE, Dhall, HCL, Jsonnet, Nickel, Starlark, JSON/YAML Schema | Domain-Specific -| 12 +| 11 | Game dev, blockchain, embedded, web frameworks | Query/Policy @@ -226,11 +234,13 @@ Every one of these will crash your app or create a security hole. == The Solution +NOTE: The examples in this README are written in Python syntax to show the shape of the API. The Python bindings themselves were removed on 2026-05-27 (see <<_python,Python>>), so use a binding from link:TOPOLOGY.adoc[TOPOLOGY.adoc] to run them. + [source,python] ---- from proven import SafeMath, SafeJson, SafeUrl, SafePassword, SafeRegex, SafeHtml, SafeCommand, SafeSql -# Cannot crash. Ever. Mathematically proven. +# Design goal: no exceptions. Totality-checked only where the module is `total` (see Proof status). result = SafeMath.div(10, user_input) # Returns None if zero, not an exception data = SafeJson.get(response, "key") # Returns None if missing, typed if present url = SafeUrl.parse(user_url) # Returns structured error or valid URL @@ -246,8 +256,21 @@ query = SafeSql.query("SELECT * FROM users WHERE name = ?", [user_input]) # SQL This isn’t marketing fluff. Here’s what makes proven different from regular libraries: * Every function in proven is written in Idris 2, a language with dependent types. -* The compiler literally proves your code is correct before it runs. -* All 104 core modules have verified implementations (believe_me=0 as of v1.2.0). 120+ binding targets exist (18 fully implemented, 102 scaffolded with FFI stubs). Overall project ~55% complete — see link:TOPOLOGY.md[TOPOLOGY.md] for full dashboard. +* The compiler checks every type. For a `total` function it also checks that the function terminates and covers every input. A function proves only what its type states. +* All 104 core modules have implementations with no `believe_me` (as of v1.2.0). They are not all totality-proven: see <>. 120+ binding targets exist (16 fully implemented, 102 scaffolded with FFI stubs); see link:TOPOLOGY.adoc[TOPOLOGY.adoc] for the full dashboard. + +[[proof-status]] +=== Status of the proofs + +Measured on 2026-11-25 by grep over `src/` (comment lines excluded). Status words follow standards `3-practice/PROOF-POLICY.adoc` §5: a module with an escape hatch is not `proven`. + +* *`believe_me`*: 0. +* *`assert_total` / `assert_smaller`*: 1 site, `assert_smaller` at `SafeInput.idr:282`, which bypasses the totality checker. (On 2026-11-17 there were 22 sites in 7 modules; the others have since been removed on `main`.) +* *`%default covering`*: 4 modules, `SafeJson/Access`, `SafeBase64`, `SafeBase64/Encode` and `SafeRBAC`. Their functions are checked for coverage, not termination. +* *Functions marked `covering`*: 66, in 14 files (most in `SafeFiniteField`, `SafeHeap` and `SafeBitset`). +* *Proven theorems*: link:AFFIRMATION.adoc[AFFIRMATION.adoc] does not affirm "mathematically proven". Its sample found a discharged theorem in 1 of 32 modules. 77 `.idr` files under `src/` still list `OWED` obligations. + +So "cannot crash" is the design goal, not a proven property of the whole library. === Understanding Dependent Types (In 2 Minutes) @@ -277,16 +300,16 @@ This is the core insight: instead of runtime crashes, we get compile-time errors [cols="1,1"] |=== -| Regular Code | Proven Code +| Regular Code | Proven Code (where a function is `total` with no escape hatch; see <>) | "I think this won’t crash" -| "The compiler proved this cannot crash" +| "The compiler checked that this terminates and handles every input" | "I tested it and it worked" -| "Every possible input was checked at compile time" +| "Every input case is covered, checked at compile time" | "It passed code review" -| "A theorem prover verified it" +| "The Idris2 type checker accepted its types (named theorems: see AFFIRMATION.adoc)" |=== === Want to Learn More? @@ -297,7 +320,7 @@ The proofs are available in `src/Proven/` and we encourage you to explore them! * https://www.youtube.com/watch?v=__gXFtYmDnQ[Type-Driven Development with Idris] — Edwin Brady’s talk * link:docs/PROOFS.md[Our proof documentation] — Explains each proof in this library -That said, you can absolutely use the library without understanding the proofs—the whole point of formal verification is that the compiler has already checked correctness for you. +That said, you can use the library without understanding the proofs. The compiler checks what the types and totality annotations state: preconditions, and termination and coverage where a function is `total`. It does not check that an algorithm is correct (see <>). == Modules @@ -1714,14 +1737,7 @@ npx jsr add @proven/core === Python -[source,bash] ----- -# Using pipx (recommended) -pipx install proven - -# Using pip -pip install proven ----- +Python bindings were removed on 2026-05-27 under the estate language policy. This repository publishes no Python package, and `pip install proven` does not install these bindings. === Go @@ -1807,7 +1823,7 @@ Notable additions beyond traditional languages: ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Language Bindings (auto-generated) │ -│ Python: ctypes | Rust: bindgen | JS: WebAssembly │ +│ C: header | Rust: bindgen | JS: WebAssembly │ │ Go: cgo | Zig: native | Quantum: OpenQASM/Q# | SPICE: lib │ └─────────────────────────────────────────────────────────────────┘ │ @@ -1822,10 +1838,10 @@ Notable additions beyond traditional languages: ┌─────────────────────────────────────────────────────────────────┐ │ Idris 2 Verified Core (v1.1.0) │ │ │ -│ • 104 modules with dependent types: compiler PROVES code │ -│ is correct │ -│ • Total functions: every input produces valid output │ -│ • No runtime exceptions: impossible by construction │ +│ • 104 modules with dependent types; the compiler checks the │ +│ stated types, not full functional correctness │ +│ • `total` functions terminate and cover every input │ +│ • Escape hatches remain in 7 modules (see Proof status) │ │ • ECHIDNA integration for CI verification │ │ │ │ Used by: aerospace, automotive, financial, blockchain │ @@ -1853,7 +1869,8 @@ If you find a bug in proven, you’ve likely found a bug in either: 1. The language bindings (our bug, please report) 2. The Idris 2 compiler (extremely rare) 3. Your understanding of the function (check the docs) -The core logic is mathematically proven. But the bindings are written by humans. +4. The core logic itself: type and totality checking do not prove that an algorithm is correct +The core logic is type-checked, and totality-checked where it is `total` (see <>). The bindings are written by humans. Q: Why not just use existing libraries?:: [cols="1,1"] @@ -1877,7 +1894,7 @@ Q: Why not just use existing libraries?:: |=== Q: Is this production ready?:: -Yes, as of v1.0.0. All core modules and bindings are complete. Security audit passed, comprehensive test suite, and ECHIDNA integration for proof verification. +Partly. The Idris2 core modules are implemented, with the totality limits listed in <>. Of the 120+ binding targets, 16 are complete and 102 are scaffolds that are not ready for use. Rust and C are the production focus; the other bindings are research-stage. Check the status table before choosing a binding for production. Q: I'm using Rust... isn't my code invincible anyway? @@ -1899,17 +1916,7 @@ Think of it as a seatbelt for your invincible sports car. Q: I'm using Python... I thought code meant to crash? -Python’s dynamism is powerful, but crashes aren’t inevitable! proven’s Python bindings let you: - -Replace try/except spaghetti with compile-time guarantees (via Idris 2 proofs). -Use type-safe alternatives for error-prone operations: - -* SafeJson.parse() → No more KeyError or JSONDecodeError. -* SafePath.join_safe() → No more ../../../etc/passwd exploits. -* SafeRegex.compile() → No more ReDoS attacks. - -Keep Python’s ergonomics while eliminating entire classes of runtime errors. -Performance overhead? ~1–5% (almost always faster than hand-rolled defensive code). +Python bindings were removed on 2026-05-27 under the estate language policy, so proven is not available from Python through this repository. The supported bindings are listed in link:TOPOLOGY.adoc[TOPOLOGY.adoc]; Rust and C are the production focus. Crashes are a choice. Choose otherwise. @@ -1929,7 +1936,7 @@ Crashes are a choice. Choose otherwise. === v1.0.0 * ✅ Initial release with 74 core modules and dependent type proofs -* 120+ binding targets via Zig FFI (18 complete, 102 scaffolded) +* 120+ binding targets via Zig FFI (16 complete, 102 scaffolded) * ✅ Complete test suite with fuzzing * ✅ Security audit passed * ✅ CI/CD infrastructure diff --git a/TOPOLOGY.adoc b/TOPOLOGY.adoc index eb7a8a46..458de02b 100644 --- a/TOPOLOGY.adoc +++ b/TOPOLOGY.adoc @@ -66,11 +66,11 @@ └────────────────┬────────────────┘ │ ┌──────────────────────────────▼──────────────────────────────┐ - │ LANGUAGE BINDINGS (15%) │ + │ LANGUAGE BINDINGS (16 of 120) │ │ (Thin Wrappers — FFI Calls Only) │ │ │ - │ ✅ Complete (18): Python, Rust, JavaScript, Deno, │ - │ ReScript, Gleam, Julia, Swift, Kotlin, Go, Elixir, │ + │ ✅ Complete (16): Rust, JavaScript, Deno, Gleam, │ + │ Julia, Swift, Kotlin, Go, Elixir, │ │ Zig, Lua, Ruby, Nim, OCaml, Haskell, Ada │ │ │ │ ░░ Scaffolded (102): C, C++, Erlang, Dart, Java, │ @@ -104,12 +104,12 @@ CORE MODULES (IDRIS2) VERIFICATION ECHIDNA Integration ██████████ 100% ProofTerm + Validator + Soundness - Totality Checking ██████████ 100% --total flag enforced + Totality Checking not complete 4 %default covering modules, 1 assert_smaller site (README Proof status) believe_me Count ██████████ 100% 0 instances (was 4,566) BRIDGE & BINDINGS Zig FFI Bridge ██████████ 100% 65 exports, stable C ABI - Bindings Complete ██░░░░░░░░ 15% 18/120 fully implemented + Bindings Complete █░░░░░░░░░ 13% 16/120 fully implemented (list not re-measured) Bindings Scaffolded █████████░ 85% 102/120 have FFI stubs APPLICATIONS