Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/atoma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion docs/architecture/REPOSITORY-MAP.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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/`
Expand Down
9 changes: 9 additions & 0 deletions docs/status/ROADMAP.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions docs/theory/UNIVERSAL-DECODER.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: CC-BY-SA-4.0
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
= 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.
56 changes: 56 additions & 0 deletions scripts/atoma-word-proof-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
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"

Check warning on line 28 in scripts/atoma-word-proof-gate.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Assign this positional parameter to a local variable.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_zigprove&issues=AaIP_lTUfV5NCHGuZQa1&open=AaIP_lTUfV5NCHGuZQa1&pullRequest=31
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'
91 changes: 91 additions & 0 deletions verification/atoma/consumer/agda/CanonicalWord.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
{-# 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)
... | ()
5 changes: 5 additions & 0 deletions verification/atoma/consumer/agda/CanonicalWordCubical.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
{-# OPTIONS --safe --cubical --double-check #-}
module CanonicalWordCubical where
import CanonicalWord
58 changes: 58 additions & 0 deletions verification/atoma/consumer/coq/CanonicalWord.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
(* SPDX-License-Identifier: MPL-2.0 *)
(* Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> *)
(* 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 <? 256 then
if w =? encode b then Some b else None
else None.

Lemma payload_encode : forall b, payload (encode b) = b.
Proof.
intro b. unfold payload, encode.
rewrite N.div_add_l by (unfold stride; discriminate).
assert (H : 1 / stride = 0) by (apply N.div_small; unfold stride; reflexivity).
rewrite H. apply N.add_0_r.
Qed.

Theorem decode_exact : forall w b,
decode w = Some b <-> b < 256 /\ w = encode b.
Proof.
intros w b. split.
- unfold decode. destruct (payload w <? 256) eqn:Hbound; [|discriminate].
destruct (w =? encode (payload w)) eqn:Hword; [|discriminate].
intro H. inversion H; subst. split.
+ now apply N.ltb_lt.
+ now apply N.eqb_eq.
- intros [Hbound ->]. 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.
58 changes: 58 additions & 0 deletions verification/atoma/consumer/lean4/CanonicalWord.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
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
Loading