diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 47cb93a5..34bc2abe 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -39,6 +39,12 @@ jobs: sha256sum scalar-lean.tar.zst > "$GITHUB_WORKSPACE/build/scalar-proof-evidence/lean-archive.sha256" - name: Agda then Lean and Coq, Cubical, source falsifiers run: bash scripts/atoma-scalar-proof-gate.sh + - name: Universal decoder theory (Agda, Lean, Coq and Cubical) + run: bash scripts/atoma-word-proof-gate.sh + - name: Preserve canonical repository map for review + run: | + bash scripts/gen-repo-map.sh . + cp docs/architecture/REPOSITORY-MAP.adoc build/scalar-proof-evidence/REPOSITORY-MAP.adoc - uses: actions/upload-artifact@v7.0.2 if: always() with: diff --git a/docs/architecture/REPOSITORY-MAP.adoc b/docs/architecture/REPOSITORY-MAP.adoc index 983bfbd1..1f4e4329 100644 --- a/docs/architecture/REPOSITORY-MAP.adoc +++ b/docs/architecture/REPOSITORY-MAP.adoc @@ -233,7 +233,6 @@ your own repo - but do not read their emptiness as neglect here. | `docs/reports/quality/` | `docs/reports/security/` | `docs/standards/` -| `docs/theory/` | `docs/theory/computing/` | `docs/theory/formalisms/` | `docs/theory/mathematics/` diff --git a/docs/status/ROADMAP.adoc b/docs/status/ROADMAP.adoc index ad42ea67..41f1ee26 100644 --- a/docs/status/ROADMAP.adoc +++ b/docs/status/ROADMAP.adoc @@ -35,6 +35,15 @@ the actual Proven word encoder and UAA protocol classifier to fresh Idris2 contracts and independently interprets their source bytes in Coq. It leaves pointer/ownership and stateful foreign-boundary obligations explicit. +The scalar MVP merged in PR #30 at `c59fe78fceeaf284c0beab96300c9ad392150598`. +The next theory slice has checked universal decoder models in strict safe +Agda, full safe Cubical, Lean and Coq/coqchk; see +link:../theory/UNIVERSAL-DECODER.adoc[the statements, hosted evidence and limits]. +These independent models do not yet establish cross-model correspondence or +prove the real decoder source. UAA PR #22 separately checks its total Idris2 +state contract and existing native campaign, with ownership/lifetime assumptions +explicit. Its source refinement and Agda/Lean/Coq state witnesses remain open. + * Proven: prove decoder acceptance iff the entire 64-bit word is a canonical byte encoding, then bind the actual raw-word decoder source and its encoder dependency. Immediate tagged words are not allocated objects; pointer-carrier diff --git a/docs/theory/UNIVERSAL-DECODER.adoc b/docs/theory/UNIVERSAL-DECODER.adoc new file mode 100644 index 00000000..7b1790d9 --- /dev/null +++ b/docs/theory/UNIVERSAL-DECODER.adoc @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// Copyright (c) 2026 Jonathan D.A. Jewell += Universal decoder proof development + +The target is acceptance exactly when a word is the canonical RefC Bits8 +encoding of a byte. Testing all encoder inputs does not establish this: +the decoder must refuse every noncanonical 64-bit word. + +== Theory stage + +`CanonicalWord.agda` models every 64-bit pattern as 24 high bits, eight payload +bits, 31 padding bits and a tag. Its decoder requires zero high/padding bits +and a set tag. It proves soundness, completeness, encoder injectivity and +universal noncanonical rejection without enumerating words. The compatible +safe check runs first, followed by a full safe Cubical import check. + +Lean and Coq independently prove the arithmetic statement over all natural +words: `decode w = Some b` iff `b < 256` and `w = b * 4294967296 + 1`. +Thus the arithmetic statement also covers all uint64 inputs. Coq's proof +assumptions are required to be closed; Lean's complete kernel-axiom report is +retained. The gate accepts only the four exact reports for the pinned Lean: +`propext` and `Quot.sound`, plus `Classical.choice` for the range lemma only. +Custom axioms, `sorryAx`, missing/duplicate reports and unexpected output fail. +A deliberately compiled custom-axiom mutant must be rejected. Standard Lean +kernel axioms are not hidden or described as an axiom-free proof. + +These are independently written models. Machine-checked correspondence +between Agda's bit fields and the arithmetic statements remains open; they +are not yet an exchanged cross-kernel proof witness or a derived proof grade. + +== Source and consumer stage + +Pending: extract Proven's raw-word decoder into a pure Zig helper, retain the +Idris2 ABI as authority, and bind the helper's source bytes to a closed +interpreter with guards and checked narrowing. Require rejection mutants for +missing bounds, missing canonical equality, altered shift/tag and unbound +imports. Retain native SDK/layout and actual-wrapper checks alongside proof. + +Pointers here carry immediate tagged words, not allocations. Pointer +provenance, borrowed buffers, foreign calling conventions and compiler +refinement remain separate obligations. UAA's following state milestone must +frame refusal paths and endpoint updates, preserve callback/context identity, +and restore busy state on normal callback return under explicit ownership and +serialization assumptions. No termination or arbitrary foreign-memory safety +claim follows from these decoder theorems. + +Hosted run +https://github.com/hyperpolymath/atoma/actions/runs/45509711011[45509711011] +checked proof commit `5a77c27c9db405bd68769fe8aa1007eefa453723` successfully: +strict safe Agda with `--cubical-compatible --double-check`, the full safe +Cubical import, Lean and Coq including `coqchk`. Coq's four theorem reports +are closed under the global context. Lean reports `propext` and `Quot.sound`; +the range lemma additionally reports `Classical.choice`. No `sorryAx` occurs. +All compiler and prover execution remains in remote CI during the local-work hold. diff --git a/scripts/atoma-word-proof-gate.sh b/scripts/atoma-word-proof-gate.sh new file mode 100644 index 00000000..a2c4f6e8 --- /dev/null +++ b/scripts/atoma-word-proof-gate.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell +set -euo pipefail +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +out="$root/build/scalar-proof-evidence/word" +mkdir -p "$out" +work=$(mktemp -d) +trap 'status=$?; if ((status)); then tail -n 60 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT +cp "$root/verification/atoma/consumer/agda/CanonicalWord"*.agda "$work/" +cp "$root/verification/atoma/consumer/lean4/CanonicalWord.lean" "$work/" +cp "$root/verification/atoma/consumer/coq/CanonicalWord.v" "$work/" +cd "$work" +# The strict compatible Agda proof is the first mandatory leg. +agda --safe --without-K --cubical-compatible --double-check --warning=error CanonicalWord.agda > "$out/agda.txt" 2>&1 +failed=0 +if ! lean CanonicalWord.lean > "$out/lean-assumptions.txt" 2>&1; then failed=1; fi +# Pinned Lean emits these exact reports. Reject custom axioms, duplicate or +# missing theorem reports, unexpected output and changes to approved axioms. +cat > "$work/expected-lean.txt" <<'REPORTS' +'CanonicalWord.decode_exact' depends on axioms: [propext, Quot.sound] +'CanonicalWord.noncanonical_refused' depends on axioms: [propext, Quot.sound] +'CanonicalWord.encode_injective' depends on axioms: [propext, Quot.sound] +'CanonicalWord.canonical_word_range' depends on axioms: [propext, Classical.choice, Quot.sound] +REPORTS +LC_ALL=C sort "$work/expected-lean.txt" > "$work/expected-lean-sorted.txt" +approved_lean_report() { + LC_ALL=C sort "$1" > "$work/actual-lean-sorted.txt" + cmp -s "$work/expected-lean-sorted.txt" "$work/actual-lean-sorted.txt" +} +if ! approved_lean_report "$out/lean-assumptions.txt"; then failed=1; fi +# Compile a real counterfeit proof: it has no sorryAx and still reports all +# four theorem names, but replaces the payload lemma with a custom axiom. +awk ' + /^theorem payload_encode / { + print "axiom forged : False" + print "theorem payload_encode (b : Nat) : payload (encode b) = b := False.elim forged" + skip=1; next + } + /^theorem decode_exact / { skip=0 } + !skip { print } +' CanonicalWord.lean > Forged.lean +if ! lean Forged.lean > "$out/lean-custom-axiom.txt" 2>&1; then failed=1; fi +if ! grep -q 'CanonicalWord.forged' "$out/lean-custom-axiom.txt"; then failed=1; fi +if approved_lean_report "$out/lean-custom-axiom.txt"; then failed=1; fi +head -n 3 "$out/lean-assumptions.txt" > "$out/lean-missing-report.txt" +if approved_lean_report "$out/lean-missing-report.txt"; then failed=1; fi +cat "$out/lean-assumptions.txt" "$out/lean-assumptions.txt" > "$out/lean-duplicate-reports.txt" +if approved_lean_report "$out/lean-duplicate-reports.txt"; then failed=1; fi +if ! coqc -q CanonicalWord.v > "$out/coq-assumptions.txt" 2>&1; then failed=1; fi +if [[ $(grep -c '^Closed under the global context$' "$out/coq-assumptions.txt") != 4 ]]; then failed=1; fi +if ! coqchk -silent -Q . '' CanonicalWord > "$out/coqchk.txt" 2>&1; then failed=1; fi +if ! agda --safe --cubical --double-check --warning=error CanonicalWordCubical.agda > "$out/cubical.txt" 2>&1; then failed=1; fi +sha256sum ./*.agda ./*.lean ./*.v > "$out/inputs.sha256" +[[ $failed == 0 ]] +echo 'WORD THEORY PASS: universal canonical decoder models; source and cross-model correspondence remain separate' diff --git a/verification/atoma/consumer/agda/CanonicalWord.agda b/verification/atoma/consumer/agda/CanonicalWord.agda new file mode 100644 index 00000000..74c186c6 --- /dev/null +++ b/verification/atoma/consumer/agda/CanonicalWord.agda @@ -0,0 +1,91 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +{-# OPTIONS --safe --without-K --cubical-compatible --double-check #-} +module CanonicalWord where +open import Agda.Builtin.Nat using (Nat; zero; suc) +open import Agda.Builtin.Bool using (Bool; true; false) +open import Agda.Builtin.Unit using (⊤; tt) +open import Agda.Builtin.Sigma using (Σ; _,_) +open import Agda.Builtin.Maybe using (Maybe; just; nothing) +open import Agda.Builtin.Equality using (_≡_; refl) + +data Empty : Set where + +cong : {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y +cong f refl = refl + +Bits : Nat → Set +Bits zero = ⊤ +Bits (suc n) = Σ Bool (λ _ → Bits n) + +zeros : (n : Nat) → Bits n +zeros zero = tt +zeros (suc n) = false , zeros n + +allZero : (n : Nat) → Bits n → Bool +allZero zero tt = true +allZero (suc n) (false , tail) = allZero n tail +allZero (suc n) (true , tail) = false + +allZero-sound : (n : Nat) (xs : Bits n) → + allZero n xs ≡ true → xs ≡ zeros n +allZero-sound zero tt h = refl +allZero-sound (suc n) (false , xs) h = + cong (λ tail → false , tail) (allZero-sound n xs h) +allZero-sound (suc n) (true , xs) () + +-- Every 64-bit pattern has these fields: 24 + 8 + 31 + 1 bits. +-- No enumeration or assumption that the input was produced by encode. +record Word : Set where + constructor word + field + high : Bits 24 + payload : Bits 8 + padding : Bits 31 + tag : Bool +open Word + +encode : Bits 8 → Word +encode b = word (zeros 24) b (zeros 31) true + +decode : Word → Maybe (Bits 8) +decode (word h b l false) = nothing +decode (word h b l true) with allZero 24 h | allZero 31 l +... | true | true = just b +... | true | false = nothing +... | false | _ = nothing + +fromMaybe : {A : Set} → A → Maybe A → A +fromMaybe fallback nothing = fallback +fromMaybe fallback (just a) = a + +just-injective : {A : Set} {a b : A} → just a ≡ just b → a ≡ b +just-injective {a = a} eq = cong (fromMaybe a) eq + +impossible : {A B : Set} {b : A} → nothing ≡ just b → B +impossible () + +decode-sound : (w : Word) (b : Bits 8) → + decode w ≡ just b → w ≡ encode b +decode-sound (word h p l false) b () +decode-sound (word h p l true) b eq + with allZero 24 h in eh | allZero 31 l in el +... | true | true + rewrite allZero-sound 24 h eh | allZero-sound 31 l el + | just-injective eq = refl +... | true | false = impossible eq +... | false | _ = impossible eq + +decode-complete : (b : Bits 8) → decode (encode b) ≡ just b +decode-complete b = refl + +encode-injective : (a b : Bits 8) → encode a ≡ encode b → a ≡ b +encode-injective a b eq = cong payload eq + +-- Rejection is a universal consequence of the acceptance theorem. +noncanonical-refused : (w : Word) → + ((b : Bits 8) → w ≡ encode b → Empty) → decode w ≡ nothing +noncanonical-refused w notCanonical with decode w in result +... | nothing = refl +... | just b with notCanonical b (decode-sound w b result) +... | () diff --git a/verification/atoma/consumer/agda/CanonicalWordCubical.agda b/verification/atoma/consumer/agda/CanonicalWordCubical.agda new file mode 100644 index 00000000..52129d82 --- /dev/null +++ b/verification/atoma/consumer/agda/CanonicalWordCubical.agda @@ -0,0 +1,5 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +{-# OPTIONS --safe --cubical --double-check #-} +module CanonicalWordCubical where +import CanonicalWord diff --git a/verification/atoma/consumer/coq/CanonicalWord.v b/verification/atoma/consumer/coq/CanonicalWord.v new file mode 100644 index 00000000..142bbe71 --- /dev/null +++ b/verification/atoma/consumer/coq/CanonicalWord.v @@ -0,0 +1,58 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* Copyright (c) 2026 Jonathan D.A. Jewell *) +(* Arithmetic model over ALL natural words, hence also all uint64 inputs. + Relating the bit-field Agda model and the source interpreter is separate. *) +From Coq Require Import NArith Lia. +Open Scope N_scope. + +Definition stride : N := 4294967296. +Definition encode (b : N) : N := b * stride + 1. +Definition payload (w : N) : N := w / stride. +Definition decode (w : N) : option N := + let b := payload w in + if b b < 256 /\ w = encode b. +Proof. + intros w b. split. + - unfold decode. destruct (payload w ]. unfold decode. rewrite payload_encode. + apply N.ltb_lt in Hbound. rewrite Hbound, N.eqb_refl. reflexivity. +Qed. + +Theorem noncanonical_refused : forall w, + (forall b, b < 256 -> w <> encode b) -> decode w = None. +Proof. + intros w H. destruct (decode w) as [b|] eqn:E; [|reflexivity]. + apply decode_exact in E as [Hb Ew]. exfalso. exact (H b Hb Ew). +Qed. + +Theorem encode_injective : forall a b, encode a = encode b -> a = b. +Proof. + intros a b H. apply (f_equal payload) in H. + now rewrite !payload_encode in H. +Qed. + +Theorem canonical_word_range : forall b, b < 256 -> + 0 < encode b < 18446744073709551616. +Proof. intros b Hb. unfold encode, stride. nia. Qed. + +Print Assumptions decode_exact. +Print Assumptions noncanonical_refused. +Print Assumptions encode_injective. +Print Assumptions canonical_word_range. diff --git a/verification/atoma/consumer/lean4/CanonicalWord.lean b/verification/atoma/consumer/lean4/CanonicalWord.lean new file mode 100644 index 00000000..88d2d247 --- /dev/null +++ b/verification/atoma/consumer/lean4/CanonicalWord.lean @@ -0,0 +1,58 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +import Std.Tactic + +namespace CanonicalWord +def stride : Nat := 4294967296 +def encode (b : Nat) : Nat := b * stride + 1 +def payload (w : Nat) : Nat := w / stride +def decode (w : Nat) : Option Nat := + if payload w < 256 then + if w = encode (payload w) then some (payload w) else none + else none + +theorem payload_encode (b : Nat) : payload (encode b) = b := by + unfold payload encode stride + omega + +theorem decode_exact (w b : Nat) : + decode w = some b ↔ b < 256 ∧ w = encode b := by + constructor + · intro h + unfold decode at h + split at h + · rename_i bound + split at h + · rename_i same + have hb := Option.some.inj h + exact ⟨hb ▸ bound, hb ▸ same⟩ + · cases h + · cases h + · rintro ⟨bound, rfl⟩ + unfold decode + rw [payload_encode] + rw [if_pos bound, if_pos rfl] + +theorem noncanonical_refused (w : Nat) + (h : ∀ b, b < 256 → w ≠ encode b) : decode w = none := by + cases result : decode w with + | none => rfl + | some b => + have parts := (decode_exact w b).mp result + exact False.elim (h b parts.1 parts.2) + +theorem encode_injective (a b : Nat) (h : encode a = encode b) : a = b := by + have hp := congrArg payload h + rw [payload_encode, payload_encode] at hp + exact hp + +theorem canonical_word_range (b : Nat) (h : b < 256) : + 0 < encode b ∧ encode b < 18446744073709551616 := by + unfold encode stride + omega + +#print axioms decode_exact +#print axioms noncanonical_refused +#print axioms encode_injective +#print axioms canonical_word_range +end CanonicalWord