Skip to content

Latest commit

 

History

History
78 lines (58 loc) · 6.23 KB

EXPLAINME.adoc

File metadata and controls

78 lines (58 loc) · 6.23 KB

proven: Formally Verified Safety via Idris2 — Show Me The Receipts

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."

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.

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).

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).

Claim 2: "120+ binding targets across 4 computing paradigms without reimplementing logic"

How it works: Bindings follow a strict FFI-only pattern (ADR-008 in .machine_readable/6a2/META.a2ml). Language-specific bindings (Rust, Zig, Deno, etc.) in bindings/<lang>/ are thin wrappers that: (1) accept user input in the target language, (2) marshal to C types, (3) call the Zig FFI (ffi/zig/), (4) unmarshal results back. No safety logic lives in bindings—only data conversion. This enables many targets without N reimplementations. A breaking change to SafeMath is fixed once in Idris2, recompiled to Zig, and all bindings immediately use the fixed code.

Caveat: Bindings are scaffolded — most languages are partially implemented. Incomplete bindings may lack support for all SafeMath operations or all 104 modules. Production focus: Rust, Zig, C first; others are aspirational. Pre-submission hypatia scans enforce 0 HIGH/CRITICAL findings before publishing to opam, crates.io, Hex.pm. Python/Cython bindings were deleted 2026-05-27 in line with the estate-wide Python ban (see hyperpolymath/standards language policy).

Evidence: bindings/rust/safe_math.rs calls proven FFI via unsafe { proven_ffi_safe_add(…​) }; bindings/zig/src/safe_math.zig wraps the same FFI directly; .machine_readable/6a2/META.a2ml documents ADR-008; hypatia-v2 . --severity critical --severity high confirms 0 findings.

Technology Choices

Technology Learn More

Idris2

Dependent types, %default total, totality checking (core proofs)

Zig

C ABI bridge, FFI compilation, zero-cost abstractions

RefC

Idris2 reference compiler (compiles to C)

104 Target Languages

C, Rust, AffineScript, Deno, Gleam, Erlang, Ada, Idris2, Zig, etc. (Python and ReScript bindings were removed per estate language policy — see hyperpolymath/standards.)

File Map

Path Purpose

src/Proven/

Idris2 core (THE TRUTH): 104 modules, all with %default total

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

src/Proven/SafeBuffer.idr

Memory buffer safety: bounds on read/write, offset validation

src/Proven/SafeArgs.idr

Command-line argument parsing without buffer overflows

src/Proven/SafeJson.idr

JSON parsing with size limits, nesting depth checks

src/Proven/SafeUrl.idr

URL parsing with RFC compliance, no XXE/SSRF, host validation

src/Proven/SafeCrypto.idr

Cryptographic operations: key size proofs, algorithm validation

…​

(99 more modules across security, web, data formats, system I/O, etc.)

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/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)

bindings/affinescript/src/

AffineScript binding (.afs files; replaces former ReScript binding 2026-05-27)

bindings/c/

C header files and static library linking instructions

bindings/<lang>/tests/

Language-specific test harnesses (call FFI, verify results)

docs/

Architecture diagrams, ADRs, FFI safety guarantees

.machine_readable/6a2/META.a2ml

Architecture decisions: ADR-008 (FFI-only), ADR-009 (120+ targets)

Dogfooted Across The Account

| Project | Integration | | panic-attacker | Scans bindings with hypatia for unsafe patterns (unwrap, getExn, expect) | proof-of-work | Puzzle arithmetic uses proven SafeMath for overflow safety | vql-ut | VeriSimDB uses proven SafeBuffer for result set marshaling | reposystem | Graph validation uses proven SafeGraph for cycle detection proofs

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.