From 9909c7bc0035076dcb24c9ed6631e2b8ab466abf Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:17:07 +0000 Subject: [PATCH 1/9] Interpret guarded decoder source and bind the imported encoder in Coq --- .github/workflows/atoma.yml | 2 + scripts/atoma-word-capsule.sh | 33 ++++ scripts/atoma-word-source-proof-gate.sh | 55 ++++++ tests/consumer-word/proven.pin | 1 + verification/atoma/consumer/coq/WordSource.v | 181 +++++++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 scripts/atoma-word-capsule.sh create mode 100644 scripts/atoma-word-source-proof-gate.sh create mode 100644 tests/consumer-word/proven.pin create mode 100644 verification/atoma/consumer/coq/WordSource.v diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 34bc2ab..d4df18d 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -41,6 +41,8 @@ jobs: 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: Universal decoder source and imported encoder + run: bash scripts/atoma-word-source-proof-gate.sh - name: Preserve canonical repository map for review run: | bash scripts/gen-repo-map.sh . diff --git a/scripts/atoma-word-capsule.sh b/scripts/atoma-word-capsule.sh new file mode 100644 index 0000000..5d5bcd6 --- /dev/null +++ b/scripts/atoma-word-capsule.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell +set -euo pipefail +[[ $# == 2 ]] || { echo 'usage: atoma-word-capsule.sh DECODER ENCODER' >&2; exit 2; } +for input in "$@"; do + [[ -f "$input" && $(wc -c < "$input") -le 65536 ]] || exit 2 +done +bytes() { + od -An -v -tu1 "$1" | awk 'BEGIN {printf "["} {for(i=1;i<=NF;i++) {if(n++) printf ";"; printf "%s",$i}} END {print "]."}' +} +cat <<'COQ' +From Coq Require Import List NArith. +Require Import WordSource. +Import ListNotations. +COQ +printf 'Definition decoder_bytes : list nat := ' +bytes "$1" +printf 'Definition encoder_bytes : list nat := ' +bytes "$2" +cat <<'COQ' +Lemma source_admitted : WordSource.check decoder_bytes encoder_bytes = true. +Proof. vm_compute. reflexivity. Qed. +Theorem source_checked : forall w b, + WordSource.run decoder_bytes encoder_bytes w = Some (Some b) <-> + (b < 256)%N /\ w = CanonicalWord.encode b. +Proof. apply WordSource.source_exact. exact source_admitted. Qed. +Theorem source_no_trap : forall w, + WordSource.run decoder_bytes encoder_bytes w = Some (CanonicalWord.decode w). +Proof. apply WordSource.source_corresponds. exact source_admitted. Qed. +Print Assumptions source_checked. +Print Assumptions source_no_trap. +COQ diff --git a/scripts/atoma-word-source-proof-gate.sh b/scripts/atoma-word-source-proof-gate.sh new file mode 100644 index 0000000..cae3ca3 --- /dev/null +++ b/scripts/atoma-word-source-proof-gate.sh @@ -0,0 +1,55 @@ +#!/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-source" +mkdir -p "$out" +work=$(mktemp -d) +trap 'status=$?; if ((status)); then tail -n 60 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT +revision=$(cat "$root/tests/consumer-word/proven.pin") +[[ $revision =~ ^[0-9a-f]{40}$ ]] +printf '%s\n' "$revision" > "$out/proven.pin" +for file in bits8_decode_word.zig bits8_word.zig; do + curl --proto '=https' --proto-redir '=https' -fL --retry 2 --connect-timeout 20 --max-time 120 \ + "https://raw.githubusercontent.com/hyperpolymath/proven/$revision/ffi/zig/src/refc/$file" -o "$out/$file" +done +cp "$root/verification/atoma/consumer/coq/"{ScalarSource,CanonicalWord,WordSource}.v "$work/" +cd "$work" +coqc -q ScalarSource.v > "$out/scalar-assumptions.txt" 2>&1 +coqc -q CanonicalWord.v > "$out/word-assumptions.txt" 2>&1 +coqc -q WordSource.v > "$out/source-assumptions.txt" 2>&1 +[[ $(grep -c '^Closed under the global context$' "$out/source-assumptions.txt") == 3 ]] +bash "$root/scripts/atoma-word-capsule.sh" "$out/bits8_decode_word.zig" "$out/bits8_word.zig" > AtomaWord.v +coqc -q AtomaWord.v > "$out/checked.txt" 2>&1 +[[ $(grep -c '^Closed under the global context$' "$out/checked.txt") == 2 ]] +coqchk -silent -Q . '' ScalarSource CanonicalWord WordSource AtomaWord > "$out/coqchk.txt" 2>&1 +cp AtomaWord.v "$out/" +reject() { + local name=$1 decoder=$2 encoder=$3 + bash "$root/scripts/atoma-word-capsule.sh" "$decoder" "$encoder" > Bad.v + if coqc -q Bad.v > "$out/reject-$name.txt" 2>&1; then + echo "FAIL accepted $name" >&2; exit 1 + fi + grep -q 'Unable to unify' "$out/reject-$name.txt" +} +for mutation in bound equality cast divisor import; do + case "$mutation" in + bound) sed '/if (payload > 255)/d' "$out/bits8_decode_word.zig" ;; + equality) sed '/if (raw != word.encodeWord(byte))/d' "$out/bits8_decode_word.zig" ;; + cast) sed 's/@intCast(payload)/@truncate(payload)/' "$out/bits8_decode_word.zig" ;; + divisor) sed 's@/ 4294967296@/ 2147483648@' "$out/bits8_decode_word.zig" ;; + import) sed 's/bits8_word.zig/other_word.zig/' "$out/bits8_decode_word.zig" ;; + esac > "$work/$mutation.zig" + reject "$mutation" "$work/$mutation.zig" "$out/bits8_word.zig" +done +sed 's/| 1/| 0/' "$out/bits8_word.zig" > tag.zig +reject encoder-tag "$out/bits8_decode_word.zig" tag.zig +sed 's/encodeWord/otherName/' "$out/bits8_word.zig" > renamed.zig +reject encoder-export "$out/bits8_decode_word.zig" renamed.zig +sed 's/bits8_word.zig/bits8_word .zig/' "$out/bits8_decode_word.zig" > import-space.zig +reject literal-whitespace import-space.zig "$out/bits8_word.zig" +printf '\nconst extra = @import("unbound.zig");\n' >> renamed.zig +reject trailing-import "$out/bits8_decode_word.zig" renamed.zig +sha256sum "$out/"*.zig ./*.v > "$out/inputs.sha256" +echo 'WORD SOURCE PASS: universal guarded source interpretation; pointer/compiler boundaries remain explicit' diff --git a/tests/consumer-word/proven.pin b/tests/consumer-word/proven.pin new file mode 100644 index 0000000..1a21cbf --- /dev/null +++ b/tests/consumer-word/proven.pin @@ -0,0 +1 @@ +c0b224778e193c38a6266a086b81ca84c040e31a diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v new file mode 100644 index 0000000..5410bc3 --- /dev/null +++ b/verification/atoma/consumer/coq/WordSource.v @@ -0,0 +1,181 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* Copyright (c) 2026 Jonathan D.A. Jewell *) +(* Closed guarded-decoder source semantics. Original bytes and the complete + imported encoder are inputs; an emitter-supplied AST/verdict is not used. + Machine/compiler and pointer-carrier correspondence are separate. *) +From Coq Require Import List String Ascii Bool NArith Lia. +Require Import ScalarSource CanonicalWord. +Import ListNotations. +Open Scope string_scope. + +Fixpoint strip_prefix (prefix xs : list nat) : option (list nat) := + match prefix, xs with + | [], _ => Some xs + | p :: ps, x :: rest => if Nat.eqb p x then strip_prefix ps rest else None + | _, _ => None + end. + +(* Only this literal import is admitted, including its unbroken quoted bytes. + Ignoring whitespace/comments inside string literals would be unsound. *) +Definition import_literal : list nat := + [34;98;105;116;115;56;95;119;111;114;100;46;122;105;103;34]. + +Fixpoint lex (fuel : nat) (xs : list nat) : option (list string) := + match xs with + | [] => Some [] + | c :: rest => match fuel with + | O => None + | S fuel' => + if ScalarSource.white c then lex fuel' rest else + match xs with + | 47 :: 47 :: tail => lex fuel' (ScalarSource.after_comment tail) + | _ => + let token_tail := + if Nat.eqb c 34 then + match strip_prefix import_literal xs with + | Some tail => Some ("encoder-import", tail) | None => None end + else if ScalarSource.wordchar c then Some (ScalarSource.take_word xs) + else match xs with + | 33 :: 61 :: tail => Some ("!=", tail) + | _ => if existsb (Nat.eqb c) [40;41;58;123;125;59;64;44;61;33;46;47;62] + then Some (String (ascii_of_nat c) EmptyString, rest) + else None + end in + match token_tail with + | None => None + | Some (t, tail) => match lex fuel' tail with + | Some ts => Some (t :: ts) | None => None end + end + end + end + end. + +Fixpoint decimal_acc (s : string) (acc : N) : option N := + match s with + | EmptyString => Some acc + | String c rest => let n := nat_of_ascii c in + if ScalarSource.digit n + then decimal_acc rest (10 * acc + N.of_nat (n - 48))%N else None + end. +Definition decimal (s : string) : option N := + if (1 <=? String.length s)%nat && (String.length s <=? 20)%nat + then decimal_acc s 0%N else None. + +Record program := Program { divisor : N; maximum : N }. + +(* This is one deliberately closed straight-line grammar: unsigned division, + refusal before checked narrowing, a bound import call, equality refusal, + and return. All names, types, order and trailing declarations are checked. + Literals become operands in the operational interpretation below. *) +Definition parse_tokens (ts : list string) : option program := + match ts with + | ["const";"word";"=";"@";"import";"(";"encoder-import";")";";"; + "pub";"fn";"decodeWord";"(";"raw";":";"u64";")"; + "error";"{";"InvalidRefcResult";"}";"!";"u8";"{"; + "const";"payload";"=";"raw";"/";d;";"; + "if";"(";"payload";">";m;")";"return";"error";".";"InvalidRefcResult";";"; + "const";"byte";":";"u8";"=";"@";"intCast";"(";"payload";")";";"; + "if";"(";"raw";"!=";"word";".";"encodeWord";"(";"byte";")";")"; + "return";"error";".";"InvalidRefcResult";";"; + "return";"byte";";";"}"] => + match decimal d, decimal m with + | Some divisor, Some maximum => Some (Program divisor maximum) + | _, _ => None end + | _ => None + end. +Definition parse (bytes : list nat) : option program := + if forallb (fun c => (c parse_tokens ts | None => None end + else None. + +Definition encoder_export (bytes : list nat) : bool := + match ScalarSource.lex (List.length bytes) bytes with + | Some ("pub" :: "fn" :: "encodeWord" :: _) => true + | _ => false end. +Definition encoder_row (bytes : list nat) (b : nat) : bool := + match ScalarSource.run bytes b with + | Some value => N.eqb value (CanonicalWord.encode (N.of_nat b)) + | None => false end. +Definition encoder_check (bytes : list nat) : bool := + encoder_export bytes && forallb (encoder_row bytes) (seq 0 256). + +Lemma encoder_check_sound : forall bytes, + encoder_check bytes = true -> forall b, (b < 256)%N -> + ScalarSource.run bytes (N.to_nat b) = Some (CanonicalWord.encode b). +Proof. + intros bytes H b Hb. unfold encoder_check in H. + apply andb_true_iff in H as [_ H]. rewrite forallb_forall in H. + assert (Hn : (N.to_nat b < 256)%nat). + { apply N2Nat.inj_lt in Hb. exact Hb. } + assert (Hin : In (N.to_nat b) (seq 0 256)). + { apply in_seq. split; [lia | exact Hn]. } + specialize (H (N.to_nat b) Hin). unfold encoder_row in H. + destruct (ScalarSource.run bytes (N.to_nat b)) as [v|] eqn:E; [|discriminate]. + apply N.eqb_eq in H. rewrite N2Nat.id in H. now rewrite H. +Qed. + +Definition check (source encoder : list nat) : bool := + match parse source with + | Some p => N.eqb (divisor p) CanonicalWord.stride && + (N.eqb (maximum p) 255 && encoder_check encoder) + | None => false end. + +(* A checked u8 cast preserves b only in range. The refusal precedes that cast. + The actual parsed encoder is evaluated at the narrowed byte. *) +(* Outer None denotes unsupported evaluation or a trap, never a normal + InvalidRefcResult. The correspondence theorem excludes it universally. *) +Definition evaluate (p : program) (encoder : list nat) (w : N) : option (option N) := + if N.eqb (divisor p) 0 then None else + let b := (w / divisor p)%N in + if (b <=? maximum p)%N then + if (b Some (if N.eqb w canonical then Some b else None) + | None => None end + else None + else Some None. +Definition run (source encoder : list nat) (w : N) : option (option N) := + match parse source with Some p => evaluate p encoder w | None => None end. + +Theorem source_corresponds : forall source encoder, + check source encoder = true -> forall w, + run source encoder w = Some (CanonicalWord.decode w). +Proof. + intros source encoder H w. unfold check in H. unfold run. + destruct (parse source) as [[d m]|] eqn:E; [|discriminate]. + apply andb_true_iff in H as [Hd H]. apply andb_true_iff in H as [Hm He]. + cbn in Hd, Hm. apply N.eqb_eq in Hd. apply N.eqb_eq in Hm. subst d m. + unfold evaluate, CanonicalWord.decode, CanonicalWord.payload. cbn [divisor maximum]. + change (if (w / CanonicalWord.stride <=? 255)%N then + if (w / CanonicalWord.stride Some (if N.eqb w canonical then Some (w / CanonicalWord.stride)%N else None) + | None => None end + else None else Some None) = + Some (if (w / CanonicalWord.stride forall w b, + run source encoder w = Some (Some b) <-> (b < 256)%N /\ w = CanonicalWord.encode b. +Proof. + intros source encoder H w b. rewrite (source_corresponds source encoder H w). + split. + - intro E. injection E as E. now apply CanonicalWord.decode_exact. + - intro E. now rewrite (proj2 (CanonicalWord.decode_exact w b) E). +Qed. + +Print Assumptions encoder_check_sound. +Print Assumptions source_corresponds. +Print Assumptions source_exact. From 288422f0c340db88418a1c565190a58df32ce22d Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:21:04 +0000 Subject: [PATCH 2/9] Keep source bytes in nat scope when importing binary word arithmetic --- scripts/atoma-word-capsule.sh | 1 + verification/atoma/consumer/coq/WordSource.v | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/atoma-word-capsule.sh b/scripts/atoma-word-capsule.sh index 5d5bcd6..01c2a6a 100644 --- a/scripts/atoma-word-capsule.sh +++ b/scripts/atoma-word-capsule.sh @@ -13,6 +13,7 @@ cat <<'COQ' From Coq Require Import List NArith. Require Import WordSource. Import ListNotations. +Open Scope nat_scope. COQ printf 'Definition decoder_bytes : list nat := ' bytes "$1" diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v index 5410bc3..4963b1b 100644 --- a/verification/atoma/consumer/coq/WordSource.v +++ b/verification/atoma/consumer/coq/WordSource.v @@ -7,6 +7,7 @@ From Coq Require Import List String Ascii Bool NArith Lia. Require Import ScalarSource CanonicalWord. Import ListNotations. Open Scope string_scope. +Open Scope nat_scope. Fixpoint strip_prefix (prefix xs : list nat) : option (list nat) := match prefix, xs with From bf78b2c45186ab9ececab96223c036192b49593c Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:21:29 +0000 Subject: [PATCH 3/9] Keep fast source-proof iteration mandatory before full replay --- .github/workflows/atoma.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index d4df18d..052488b 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -16,6 +16,27 @@ concurrency: cancel-in-progress: true jobs: + word_source: + name: Universal source interpretation + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: Provision independent Coq checker + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 + - name: Guarded decoder and imported encoder source + run: bash scripts/atoma-word-source-proof-gate.sh + - uses: actions/upload-artifact@v7.0.2 + if: always() + with: + name: word-source-proof-evidence-${{ github.sha }} + path: build/scalar-proof-evidence/word-source/ + if-no-files-found: error + scalar: name: Scalar source proof gate runs-on: ubuntu-24.04 @@ -41,8 +62,6 @@ jobs: 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: Universal decoder source and imported encoder - run: bash scripts/atoma-word-source-proof-gate.sh - name: Preserve canonical repository map for review run: | bash scripts/gen-repo-map.sh . @@ -56,7 +75,7 @@ jobs: soundness: name: Atoma soundness gate - needs: [scalar] + needs: [scalar, word_source] runs-on: ubuntu-24.04 timeout-minutes: 45 steps: From d9475fec74615e6d52d8d3f2711d2b7eaf72037e Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:30:12 +0000 Subject: [PATCH 4/9] Bind registry kernel source and disambiguate arithmetic lexer guards --- .github/workflows/atoma.yml | 6 +- scripts/atoma-registry-capsule.sh | 25 ++ scripts/atoma-registry-source-proof-gate.sh | 41 +++ scripts/atoma-word-source-proof-gate.sh | 1 + tests/consumer-word/uaa.pin | 1 + .../atoma/consumer/coq/RegistrySource.v | 268 ++++++++++++++++++ verification/atoma/consumer/coq/WordSource.v | 4 +- 7 files changed, 343 insertions(+), 3 deletions(-) create mode 100644 scripts/atoma-registry-capsule.sh create mode 100644 scripts/atoma-registry-source-proof-gate.sh create mode 100644 tests/consumer-word/uaa.pin create mode 100644 verification/atoma/consumer/coq/RegistrySource.v diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 052488b..2ef14cc 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -30,11 +30,15 @@ jobs: sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 - name: Guarded decoder and imported encoder source run: bash scripts/atoma-word-source-proof-gate.sh + - name: Actual registry state-kernel source + run: bash scripts/atoma-registry-source-proof-gate.sh - uses: actions/upload-artifact@v7.0.2 if: always() with: name: word-source-proof-evidence-${{ github.sha }} - path: build/scalar-proof-evidence/word-source/ + path: | + build/scalar-proof-evidence/word-source/ + build/scalar-proof-evidence/registry-source/ if-no-files-found: error scalar: diff --git a/scripts/atoma-registry-capsule.sh b/scripts/atoma-registry-capsule.sh new file mode 100644 index 0000000..6012225 --- /dev/null +++ b/scripts/atoma-registry-capsule.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell +set -euo pipefail +[[ $# == 1 && -f "$1" && $(wc -c < "$1") -le 65536 ]] || exit 2 +cat <<'COQ' +From Coq Require Import List Bool ZArith. +Require Import RegistrySource. +Import ListNotations. +Open Scope nat_scope. +COQ +printf 'Definition source_bytes : list nat := ' +od -An -v -tu1 "$1" | awk 'BEGIN {printf "["} {for(i=1;i<=NF;i++) {if(n++) printf ";"; printf "%s",$i}} END {print "]."}' +cat <<'COQ' +Lemma source_admitted : RegistrySource.check source_bytes = true. +Proof. vm_compute. reflexivity. Qed. +Theorem source_checked : exists p, RegistrySource.parse source_bytes = Some p /\ + (forall A (s : RegistrySource.state A) k e, RegistrySource.register p s k e = RegistrySource.spec_register s k e) /\ + (forall A (s : RegistrySource.state A) k, RegistrySource.unregister p s k = RegistrySource.spec_unregister s k) /\ + (forall A (s : RegistrySource.state A) k, RegistrySource.begin p s k = RegistrySource.spec_begin s k) /\ + (forall A (s : RegistrySource.state A), RegistrySource.finish p s = RegistrySource.busy_state s false) /\ + (forall z, RegistrySource.sanitize p z = if (0 <=? z)%Z && (z <=? 11)%Z then z else 6%Z). +Proof. apply RegistrySource.source_refines. exact source_admitted. Qed. +Print Assumptions source_checked. +COQ diff --git a/scripts/atoma-registry-source-proof-gate.sh b/scripts/atoma-registry-source-proof-gate.sh new file mode 100644 index 0000000..b8c0d1c --- /dev/null +++ b/scripts/atoma-registry-source-proof-gate.sh @@ -0,0 +1,41 @@ +#!/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/registry-source" +mkdir -p "$out" +work=$(mktemp -d) +trap 'status=$?; if ((status)); then tail -n 60 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT +revision=$(cat "$root/tests/consumer-word/uaa.pin") +[[ $revision =~ ^[0-9a-f]{40}$ ]] +printf '%s\n' "$revision" > "$out/uaa.pin" +curl --proto '=https' --proto-redir '=https' -fL --retry 2 --connect-timeout 20 --max-time 120 \ + "https://raw.githubusercontent.com/hyperpolymath/unified-api-adapter/$revision/src/interface/ffi/src/registry_state.zig" -o "$out/source.zig" +cp "$root/verification/atoma/consumer/coq/"{ScalarSource,RegistrySource}.v "$work/" +cd "$work" +coqc -q ScalarSource.v > "$out/scalar-assumptions.txt" 2>&1 +coqc -q RegistrySource.v > "$out/registry-assumptions.txt" 2>&1 +[[ $(grep -c '^Closed under the global context$' "$out/registry-assumptions.txt") == 6 ]] +bash "$root/scripts/atoma-registry-capsule.sh" "$out/source.zig" > AtomaRegistry.v +coqc -q AtomaRegistry.v > "$out/checked.txt" 2>&1 +[[ $(grep -c '^Closed under the global context$' "$out/checked.txt") == 1 ]] +coqchk -silent -Q . '' ScalarSource RegistrySource AtomaRegistry > "$out/coqchk.txt" 2>&1 +cp AtomaRegistry.v "$out/" +for mutation in selection frame busy restoration status identity import; do + case "$mutation" in + selection) sed 's/\.mcp => s.mcp/.mcp => s.rest/' "$out/source.zig" ;; + frame) sed 's/\.rest = s.rest, .mcp = endpoint/.rest = endpoint, .mcp = endpoint/' "$out/source.zig" ;; + busy) sed '/if (s.active)/d' "$out/source.zig" ;; + restoration) sed 's/return mark(E, s, false)/return mark(E, s, true)/' "$out/source.zig" ;; + status) sed 's/status <= 11/status <= 12/' "$out/source.zig" ;; + identity) sed 's/\.selected = endpoint/.selected = null/' "$out/source.zig" ;; + import) cat "$out/source.zig"; printf '\nconst hidden = @import("hidden.zig");\n' ;; + esac > "$work/$mutation.zig" + ! cmp -s "$work/$mutation.zig" "$out/source.zig" + bash "$root/scripts/atoma-registry-capsule.sh" "$work/$mutation.zig" > Bad.v + if coqc -q Bad.v > "$out/reject-$mutation.txt" 2>&1; then echo "FAIL accepted $mutation" >&2; exit 1; fi + grep -q 'Unable to unify' "$out/reject-$mutation.txt" +done +sha256sum "$out/source.zig" ./*.v > "$out/inputs.sha256" +echo 'REGISTRY SOURCE PASS: opaque endpoint identities and state transitions; foreign ownership remains a premise' diff --git a/scripts/atoma-word-source-proof-gate.sh b/scripts/atoma-word-source-proof-gate.sh index cae3ca3..9db036d 100644 --- a/scripts/atoma-word-source-proof-gate.sh +++ b/scripts/atoma-word-source-proof-gate.sh @@ -49,6 +49,7 @@ sed 's/encodeWord/otherName/' "$out/bits8_word.zig" > renamed.zig reject encoder-export "$out/bits8_decode_word.zig" renamed.zig sed 's/bits8_word.zig/bits8_word .zig/' "$out/bits8_decode_word.zig" > import-space.zig reject literal-whitespace import-space.zig "$out/bits8_word.zig" +cp "$out/bits8_word.zig" renamed.zig printf '\nconst extra = @import("unbound.zig");\n' >> renamed.zig reject trailing-import "$out/bits8_decode_word.zig" renamed.zig sha256sum "$out/"*.zig ./*.v > "$out/inputs.sha256" diff --git a/tests/consumer-word/uaa.pin b/tests/consumer-word/uaa.pin new file mode 100644 index 0000000..45894db --- /dev/null +++ b/tests/consumer-word/uaa.pin @@ -0,0 +1 @@ +e81904be0a233f7535255e6118cf782be32cc1e6 diff --git a/verification/atoma/consumer/coq/RegistrySource.v b/verification/atoma/consumer/coq/RegistrySource.v new file mode 100644 index 0000000..31e6ac0 --- /dev/null +++ b/verification/atoma/consumer/coq/RegistrySource.v @@ -0,0 +1,268 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* Copyright (c) 2026 Jonathan D.A. Jewell *) +From Coq Require Import List String Ascii Bool Arith ZArith Lia. +Require Import ScalarSource. +Import ListNotations. +Open Scope string_scope. +Open Scope nat_scope. +Open Scope list_scope. + +(* Closed lexical/profile grammar: generic opaque endpoint values, records, + field selection, copy/update, branches, local calls and signed status guards. + No imports, pointers, loops, effects or arbitrary comptime evaluation. *) +Fixpoint lex (fuel : nat) (xs : list nat) : option (list string) := + match xs with + | [] => Some [] + | c :: rest => match fuel with + | O => None + | S fuel' => if ScalarSource.white c then lex fuel' rest else + match xs with + | 47 :: 47 :: tail => lex fuel' (ScalarSource.after_comment tail) + | _ => let token_tail := + if ScalarSource.wordchar c then Some (ScalarSource.take_word xs) else + match xs with + | 61 :: 62 :: tail => Some ("=>", tail) + | 61 :: 61 :: tail => Some ("==", tail) + | 33 :: 61 :: tail => Some ("!=", tail) + | 62 :: 61 :: tail => Some (">=", tail) + | 60 :: 61 :: tail => Some ("<=", tail) + | _ => if existsb (Nat.eqb c) [40;41;58;123;125;59;64;44;61;63;46] + then Some (String (ascii_of_nat c) EmptyString, rest) else None + end in + match token_tail with + | Some (t, tail) => match lex fuel' tail with Some ts => Some (t::ts) | None => None end + | None => None end + end + end + end. +Fixpoint strip (prefix xs : list string) : option (list string) := + match prefix, xs with + | [], _ => Some xs + | p::ps, x::rest => if String.eqb p x then strip ps rest else None + | _, _ => None end. +Definition same (a b : list string) : bool := + if list_eq_dec string_dec a b then true else false. +Fixpoint body (fuel depth : nat) (acc xs : list string) : option (list string * list string) := + match fuel, xs with + | S f, "}"::rest => match depth with + | O => Some (rev acc, rest) | S d => body f d ("}"::acc) rest end + | S f, "{"::rest => body f (S depth) ("{"::acc) rest + | S f, x::rest => body f depth (x::acc) rest + | _, _ => None end. +Fixpoint functions (sigs : list (list string)) (xs : list string) : option (list (list string)) := + match sigs with + | [] => if same xs [] then Some [] else None + | sig::rest => match strip sig xs with + | Some tail => match body (List.length tail) 0 [] tail with + | Some (b, tail') => match functions rest tail' with Some bs => Some (b::bs) | None => None end + | None => None end + | None => None end + end. + +Definition generic := ["comptime";"E";":";"type"]. +Definition signatures : list (list string) := + [ ["pub";"fn";"State";"("] ++ generic ++ [")";"type";"{"]; + ["pub";"fn";"Reply";"("] ++ generic ++ [")";"type";"{"]; + ["pub";"fn";"get";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"slot";":";"Slot";")";"?";"E";"{"]; + ["pub";"fn";"put";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"slot";":";"Slot";",";"endpoint";":";"?";"E";")";"State";"(";"E";")";"{"]; + ["pub";"fn";"mark";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"active";":";"bool";")";"State";"(";"E";")";"{"]; + ["pub";"fn";"register";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"slot";":";"Slot";",";"endpoint";":";"E";")";"Reply";"(";"E";")";"{"]; + ["pub";"fn";"unregister";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"slot";":";"Slot";")";"Reply";"(";"E";")";"{"]; + ["pub";"fn";"begin";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";",";"slot";":";"Slot";")";"Reply";"(";"E";")";"{"]; + ["pub";"fn";"finish";"("] ++ generic ++ [",";"s";":";"State";"(";"E";")";")";"State";"(";"E";")";"{"]; + ["pub";"fn";"sanitize";"(";"status";":";"c_int";")";"c_int";"{"] ]. + +Inductive field := RestField | McpField. +Inductive value := FromRest | FromMcp | Argument. +Definition parse_field (s : string) : option field := + match s with "rest" => Some RestField | "mcp" => Some McpField | _ => None end. +Definition parse_value (xs : list string) : option (value * list string) := + match xs with + | "s"::"."::"rest"::rest => Some (FromRest, rest) + | "s"::"."::"mcp"::rest => Some (FromMcp, rest) + | "endpoint"::rest => Some (Argument, rest) + | _ => None end. +Definition parse_record (xs : list string) : option ((value * value) * list string) := + match strip [".";"{";".";"rest";"="] xs with + | Some tail => match parse_value tail with + | Some (r, ","::"."::"mcp"::"="::tail') => match parse_value tail' with + | Some (m, ","::"."::"active"::"="::"s"::"."::"active"::"}"::rest) => Some ((r,m),rest) + | _ => None end + | _ => None end + | None => None end. +Definition parse_get (xs : list string) : option (field * field) := + match xs with + | ["return";"switch";"(";"slot";")";"{";".";"mcp";"=>";"s";".";m;",";".";"rest";"=>";"s";".";r;"}";";"] => + match parse_field m, parse_field r with Some a, Some b => Some (a,b) | _,_ => None end + | _ => None end. +Definition parse_put (xs : list string) : option ((value * value) * (value * value)) := + match strip ["return";"switch";"(";"slot";")";"{";".";"mcp";"=>"] xs with + | Some tail => match parse_record tail with + | Some (a, ","::"."::"rest"::"=>"::tail') => match parse_record tail' with + | Some (b, [",";"}";";"]) => Some (a,b) | _ => None end + | _ => None end + | None => None end. +Definition parse_mark (xs : list string) : option (field * field) := + match xs with + | ["return";".";"{";".";"rest";"=";"s";".";r;",";".";"mcp";"=";"s";".";m;",";".";"active";"=";"active";"}";";"] => + match parse_field r, parse_field m with Some a,Some b => Some (a,b) | _,_ => None end + | _ => None end. +Definition numbers (a b c : string) : option (nat * nat * nat) := + match ScalarSource.decimal a, ScalarSource.decimal b, ScalarSource.decimal c with + | Some x,Some y,Some z => Some (x,y,z) | _,_,_ => None end. +Definition parse_update (comparison argument : string) (xs : list string) : option (nat * nat * nat) := + match xs with + | ["if";"(";"s";".";"active";")";"return";".";"{";".";"status";"=";busy;",";".";"next";"=";"s";"}";";"; + "if";"(";"get";"(";"E";",";"s";",";"slot";")";cmp;"null";")";"return";".";"{";".";"status";"=";other;",";".";"next";"=";"s";"}";";"; + "return";".";"{";".";"status";"=";ok;",";".";"next";"=";"put";"(";"E";",";"s";",";"slot";",";arg;")";"}";";"] => + if String.eqb cmp comparison && String.eqb arg argument then numbers busy other ok else None + | _ => None end. +Definition parse_begin (xs : list string) : option (nat * nat * nat) := + match xs with + | ["if";"(";"s";".";"active";")";"return";".";"{";".";"status";"=";busy;",";".";"next";"=";"s";"}";";"; + "const";"endpoint";"=";"get";"(";"E";",";"s";",";"slot";")";"orelse";"return";".";"{";".";"status";"=";absent;",";".";"next";"=";"s";"}";";"; + "return";".";"{";".";"status";"=";ok;",";".";"next";"=";"mark";"(";"E";",";"s";",";"true";")";",";".";"selected";"=";"endpoint";"}";";"] => numbers busy absent ok + | _ => None end. +Definition parse_finish (xs : list string) : option bool := + match xs with + | ["return";"mark";"(";"E";",";"s";",";"false";")";";"] => Some false + | ["return";"mark";"(";"E";",";"s";",";"true";")";";"] => Some true + | _ => None end. +Definition parse_sanitize (xs : list string) : option (nat * nat * nat) := + match xs with + | ["return";"if";"(";"status";">=";lo;"and";"status";"<=";hi;")";"status";"else";fallback;";"] => numbers lo hi fallback + | _ => None end. + +Record program := Program { + selectors : field * field; + updates : (value * value) * (value * value); + marked_fields : field * field; + register_codes : nat * nat * nat; + unregister_codes : nat * nat * nat; + begin_codes : nat * nat * nat; + finish_flag : bool; + status_bounds : nat * nat * nat +}. +Definition parse_bodies (bs : list (list string)) : option program := + match bs with + | [st;rp;g;p;m;r;u;b;f;z] => + if same st ["return";"struct";"{";"rest";":";"?";"E";"=";"null";",";"mcp";":";"?";"E";"=";"null";",";"active";":";"bool";"=";"false";"}";";"] && + same rp ["return";"struct";"{";"status";":";"u8";",";"next";":";"State";"(";"E";")";",";"selected";":";"?";"E";"=";"null";"}";";"] then + match parse_get g, parse_put p, parse_mark m, parse_update "!=" "endpoint" r, + parse_update "==" "null" u, parse_begin b, parse_finish f, parse_sanitize z with + | Some gp,Some pp,Some mp,Some rp,Some up,Some bp,Some fp,Some zp => Some (Program gp pp mp rp up bp fp zp) + | _,_,_,_,_,_,_,_ => None end else None + | _ => None end. +Definition parse (bytes : list nat) : option program := + if forallb (fun c => Nat.ltb c 128) bytes then + match lex (List.length bytes) bytes with + | Some ts => match strip ["pub";"const";"Slot";"=";"enum";"{";"mcp";",";"rest";"}";";"] ts with + | Some tail => match functions signatures tail with Some bs => parse_bodies bs | None => None end + | None => None end + | None => None end else None. + +Inductive slot := MCP | REST. +Record state (A : Type) := State { rest : option A; mcp : option A; active : bool }. +Arguments State {A}. Arguments rest {A}. Arguments mcp {A}. Arguments active {A}. +Record reply (A : Type) := Reply { status : nat; next : state A; selected : option A }. +Arguments Reply {A}. Arguments status {A}. Arguments next {A}. Arguments selected {A}. +Definition field_value {A} (f : field) (s : state A) := match f with RestField => rest s | McpField => mcp s end. +Definition expression {A} (e : value) (s : state A) (argument : option A) := + match e with FromRest => rest s | FromMcp => mcp s | Argument => argument end. +Definition get {A} (p : program) (s : state A) (k : slot) := + field_value (match k with MCP => fst (selectors p) | REST => snd (selectors p) end) s. +Definition put {A} (p : program) (s : state A) (k : slot) (e : option A) := + let pair := match k with MCP => fst (updates p) | REST => snd (updates p) end in + State (expression (fst pair) s e) (expression (snd pair) s e) (active s). +Definition mark {A} (p : program) (s : state A) (b : bool) := + State (field_value (fst (marked_fields p)) s) (field_value (snd (marked_fields p)) s) b. +Definition register {A} (p : program) (s : state A) (k : slot) (e : A) := + let '(busy,duplicate,ok) := register_codes p in + if active s then Reply busy s None else match get p s k with + | Some _ => Reply duplicate s None | None => Reply ok (put p s k (Some e)) None end. +Definition unregister {A} (p : program) (s : state A) (k : slot) := + let '(busy,absent,ok) := unregister_codes p in + if active s then Reply busy s None else match get p s k with + | None => Reply absent s None | Some _ => Reply ok (put p s k None) None end. +Definition begin {A} (p : program) (s : state A) (k : slot) := + let '(busy,absent,ok) := begin_codes p in + if active s then Reply busy s None else match get p s k with + | None => Reply absent s None | Some e => Reply ok (mark p s true) (Some e) end. +Definition finish {A} (p : program) (s : state A) := mark p s (finish_flag p). +Definition sanitize (p : program) (z : Z) : Z := + let '(lo,hi,fallback) := status_bounds p in + if (Z.of_nat lo <=? z)%Z && (z <=? Z.of_nat hi)%Z then z else Z.of_nat fallback. + +Definition canonical := Program (McpField,RestField) + ((FromRest,Argument),(Argument,FromMcp)) (RestField,McpField) + (6,9,0) (6,8,0) (6,11,0) false (0,11,6). +Definition program_eq_dec (a b : program) : {a=b}+{a<>b}. +Proof. repeat decide equality. Defined. +Definition check (bytes : list nat) : bool := match parse bytes with + | Some p => if program_eq_dec p canonical then true else false | None => false end. +Lemma check_binds : forall bytes, check bytes = true -> parse bytes = Some canonical. +Proof. + intros bytes H. unfold check in H. destruct (parse bytes) as [p|] eqn:E; [|discriminate]. + destruct (program_eq_dec p canonical); [now subst | discriminate]. +Qed. + +(* Independent contract denotation corresponding to Abi.RegistryState. + Source parsing/evaluation above supplies field identities and operation codes. *) +Definition lookup {A} (s : state A) (k : slot) := match k with MCP => mcp s | REST => rest s end. +Definition replace {A} (s : state A) (k : slot) (e : option A) := match k with + | MCP => State (rest s) e (active s) | REST => State e (mcp s) (active s) end. +Definition busy_state {A} (s : state A) (b : bool) := State (rest s) (mcp s) b. +Definition spec_register {A} (s : state A) (k : slot) (e : A) := + if active s then Reply 6 s None else match lookup s k with + | Some _ => Reply 9 s None | None => Reply 0 (replace s k (Some e)) None end. +Definition spec_unregister {A} (s : state A) (k : slot) := + if active s then Reply 6 s None else match lookup s k with + | None => Reply 8 s None | Some _ => Reply 0 (replace s k None) None end. +Definition spec_begin {A} (s : state A) (k : slot) := + if active s then Reply 6 s None else match lookup s k with + | None => Reply 11 s None | Some e => Reply 0 (busy_state s true) (Some e) end. + +Theorem source_refines : forall bytes, + check bytes = true -> exists p, parse bytes = Some p /\ + (forall A (s : state A) k e, register p s k e = spec_register s k e) /\ + (forall A (s : state A) k, unregister p s k = spec_unregister s k) /\ + (forall A (s : state A) k, begin p s k = spec_begin s k) /\ + (forall A (s : state A), finish p s = busy_state s false) /\ + (forall z, sanitize p z = if (0 <=? z)%Z && (z <=? 11)%Z then z else 6%Z). +Proof. + intros bytes H. exists canonical. repeat split. + - now apply check_binds. + - intros A s k e. destruct k; reflexivity. + - intros A s k. destruct k; reflexivity. + - intros A s k. destruct k; reflexivity. + - reflexivity. + - reflexivity. +Qed. + +Definition other (k : slot) := match k with MCP => REST | REST => MCP end. +Theorem update_frames_other : forall A (s : state A) k e, + lookup (replace s k e) (other k) = lookup s (other k). +Proof. intros A s k e. destruct k; reflexivity. Qed. +Theorem begin_identity : forall A (s : state A) k e, + active s = false -> lookup s k = Some e -> + spec_begin s k = Reply 0 (busy_state s true) (Some e). +Proof. intros A s k e Hb He. unfold spec_begin. now rewrite Hb, He. Qed. +Theorem reentrant_refused : forall A (s : state A) k, + spec_begin (busy_state s true) k = Reply 6 (busy_state s true) None. +Proof. reflexivity. Qed. +Theorem normal_return_frames : forall A (s : state A), + rest (finish canonical s) = rest s /\ mcp (finish canonical s) = mcp s /\ active (finish canonical s) = false. +Proof. intros. repeat split; reflexivity. Qed. +Theorem foreign_status_bounded : forall z, (0 <= sanitize canonical z <= 11)%Z. +Proof. + intro z. change (0 <= (if (0 <=? z)%Z && (z <=? 11)%Z then z else 6) <= 11)%Z. + destruct ((0 <=? z)%Z && (z <=? 11)%Z) eqn:E. + - apply andb_true_iff in E as [L H]. apply Z.leb_le in L. apply Z.leb_le in H. lia. + - lia. +Qed. +Print Assumptions source_refines. +Print Assumptions update_frames_other. +Print Assumptions begin_identity. +Print Assumptions reentrant_refused. +Print Assumptions normal_return_frames. +Print Assumptions foreign_status_bounded. diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v index 4963b1b..dd27f80 100644 --- a/verification/atoma/consumer/coq/WordSource.v +++ b/verification/atoma/consumer/coq/WordSource.v @@ -59,7 +59,7 @@ Fixpoint decimal_acc (s : string) (acc : N) : option N := then decimal_acc rest (10 * acc + N.of_nat (n - 48))%N else None end. Definition decimal (s : string) : option N := - if (1 <=? String.length s)%nat && (String.length s <=? 20)%nat + if Nat.leb 1 (String.length s) && Nat.leb (String.length s) 20 then decimal_acc s 0%N else None. Record program := Program { divisor : N; maximum : N }. @@ -85,7 +85,7 @@ Definition parse_tokens (ts : list string) : option program := | _ => None end. Definition parse (bytes : list nat) : option program := - if forallb (fun c => (c Nat.ltb c 128) bytes then match lex (List.length bytes) bytes with | Some ts => parse_tokens ts | None => None end else None. From 435efb730717dec64a51e8ac870e2749e6555512 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:33:16 +0000 Subject: [PATCH 5/9] Use pinned Coq comparison lemma and collect independent registry diagnostics --- .github/workflows/atoma.yml | 1 + verification/atoma/consumer/coq/WordSource.v | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 2ef14cc..ca658f3 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -31,6 +31,7 @@ jobs: - name: Guarded decoder and imported encoder source run: bash scripts/atoma-word-source-proof-gate.sh - name: Actual registry state-kernel source + if: success() || failure() run: bash scripts/atoma-registry-source-proof-gate.sh - uses: actions/upload-artifact@v7.0.2 if: always() diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v index dd27f80..df164a5 100644 --- a/verification/atoma/consumer/coq/WordSource.v +++ b/verification/atoma/consumer/coq/WordSource.v @@ -108,7 +108,9 @@ Proof. intros bytes H b Hb. unfold encoder_check in H. apply andb_true_iff in H as [_ H]. rewrite forallb_forall in H. assert (Hn : (N.to_nat b < 256)%nat). - { apply N2Nat.inj_lt in Hb. exact Hb. } + { apply Nat.compare_lt_iff. + change (N.to_nat b ?= N.to_nat 256)%nat = Lt. + rewrite <- N2Nat.inj_compare. exact Hb. } assert (Hin : In (N.to_nat b) (seq 0 256)). { apply in_seq. split; [lia | exact Hn]. } specialize (H (N.to_nat b) Hin). unfold encoder_row in H. From a495df7e6d1ea16a456ab2f6af560b17981cb1a3 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:37:01 +0000 Subject: [PATCH 6/9] Check registry frame and identity witnesses in Agda Lean and Cubical --- .github/workflows/atoma.yml | 2 + scripts/atoma-registry-proof-gate.sh | 34 ++++++++++++ .../atoma/consumer/agda/RegistryState.agda | 55 +++++++++++++++++++ .../consumer/agda/RegistryStateCubical.agda | 24 ++++++++ .../atoma/consumer/lean4/RegistryState.lean | 45 +++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 scripts/atoma-registry-proof-gate.sh create mode 100644 verification/atoma/consumer/agda/RegistryState.agda create mode 100644 verification/atoma/consumer/agda/RegistryStateCubical.agda create mode 100644 verification/atoma/consumer/lean4/RegistryState.lean diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index ca658f3..2cdf48b 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -67,6 +67,8 @@ jobs: 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: Generic registry theory (compatible Agda, Lean and full Cubical) + run: bash scripts/atoma-registry-proof-gate.sh - name: Preserve canonical repository map for review run: | bash scripts/gen-repo-map.sh . diff --git a/scripts/atoma-registry-proof-gate.sh b/scripts/atoma-registry-proof-gate.sh new file mode 100644 index 0000000..f49df60 --- /dev/null +++ b/scripts/atoma-registry-proof-gate.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +set -euo pipefail +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +out="$root/build/scalar-proof-evidence/registry-theory" +mkdir -p "$out" +work=$(mktemp -d) +trap 'status=$?; if ((status)); then tail -n 50 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT +cp "$root/verification/atoma/consumer/agda/RegistryState"*.agda "$work/" +cp "$root/verification/atoma/consumer/lean4/RegistryState.lean" "$work/" +cd "$work" +agda --safe --without-K --cubical-compatible --double-check --warning=error RegistryState.agda > "$out/agda.txt" 2>&1 +lean RegistryState.lean > "$out/lean.txt" 2>&1 +# Exactly these six declarations, with no axioms (including no sorryAx). +awk ' +BEGIN {names["updateFrame"]=1; names["updateIdentity"]=1; names["beginIdentity"]=1; + names["reentrantRefused"]=1; names["normalReturnFrame"]=1; names["normalReturnIdle"]=1} +{ + found=0 + for (n in names) { + expected = "\047RegistryState." n "\047 does not depend on any axioms" + if ($0 == expected && names[n] == 1) {names[n]=2; found=1; count++} + } + if (!found) exit 1 +} +END {if (count != 6) exit 1}' "$out/lean.txt" +agda --safe --cubical --double-check --warning=error RegistryStateCubical.agda > "$out/cubical.txt" 2>&1 +sed -e 's/module RegistryState where/module RegistryStateMutant where/' \ + -e 's/state e (mcp s) (active s)/state e e (active s)/' RegistryState.agda > RegistryStateMutant.agda +if agda --safe --cubical-compatible --double-check --warning=error RegistryStateMutant.agda > "$out/reject-frame.txt" 2>&1; then exit 1; fi +grep -q '!=' "$out/reject-frame.txt" +sha256sum ./*.agda ./*.lean > "$out/inputs.sha256" +echo 'REGISTRY THEORY PASS: compatible Agda, independent axiom-free Lean witnesses, full Cubical paths' + diff --git a/verification/atoma/consumer/agda/RegistryState.agda b/verification/atoma/consumer/agda/RegistryState.agda new file mode 100644 index 0000000..df3ca51 --- /dev/null +++ b/verification/atoma/consumer/agda/RegistryState.agda @@ -0,0 +1,55 @@ +-- SPDX-License-Identifier: MPL-2.0 +{-# OPTIONS --safe --without-K --cubical-compatible #-} +module RegistryState where +open import Agda.Builtin.Bool +open import Agda.Builtin.Maybe +open import Agda.Builtin.Equality + +data Slot : Set where rest-slot mcp-slot : Slot +record State (A : Set) : Set where + constructor state + field rest mcp : Maybe A + active : Bool +open State public +lookup : {A : Set} → Slot → State A → Maybe A +lookup rest-slot s = rest s +lookup mcp-slot s = mcp s +other : Slot → Slot +other rest-slot = mcp-slot +other mcp-slot = rest-slot +put : {A : Set} → Slot → Maybe A → State A → State A +put rest-slot e s = state e (mcp s) (active s) +put mcp-slot e s = state (rest s) e (active s) +mark : {A : Set} → State A → Bool → State A +mark s b = state (rest s) (mcp s) b +data Result (A : Set) : Set where + refused : State A → Result A + called : A → State A → Result A +begin : {A : Set} → Slot → State A → Result A +begin k s@(state r m true) = refused s +begin k s@(state r m false) with lookup k s +... | nothing = refused s +... | just e = called e (mark s true) + +update-frame : {A : Set} (k : Slot) (e : Maybe A) (s : State A) → + lookup (other k) (put k e s) ≡ lookup (other k) s +update-frame rest-slot e s = refl +update-frame mcp-slot e s = refl +update-identity : {A : Set} (k : Slot) (e : Maybe A) (s : State A) → + lookup k (put k e s) ≡ e +update-identity rest-slot e s = refl +update-identity mcp-slot e s = refl +begin-identity : {A : Set} (k : Slot) (r m : Maybe A) (e : A) → + lookup k (state r m false) ≡ just e → + begin k (state r m false) ≡ called e (state r m true) +begin-identity k r m e found rewrite found = refl +reentrant-refused : {A : Set} (k : Slot) (s : State A) → + begin k (mark s true) ≡ refused (mark s true) +reentrant-refused k s = refl +normal-return-frame : {A : Set} (k : Slot) (s : State A) → + lookup k (mark s false) ≡ lookup k s +normal-return-frame rest-slot s = refl +normal-return-frame mcp-slot s = refl +normal-return-idle : {A : Set} (s : State A) → active (mark s false) ≡ false +normal-return-idle s = refl + diff --git a/verification/atoma/consumer/agda/RegistryStateCubical.agda b/verification/atoma/consumer/agda/RegistryStateCubical.agda new file mode 100644 index 0000000..1f512b4 --- /dev/null +++ b/verification/atoma/consumer/agda/RegistryStateCubical.agda @@ -0,0 +1,24 @@ +-- SPDX-License-Identifier: MPL-2.0 +{-# OPTIONS --safe --cubical #-} +module RegistryStateCubical where +open import Agda.Builtin.Cubical.Path using (PathP) +open import Agda.Builtin.Equality using (_≡_; refl) +open import Agda.Builtin.Bool +open import Agda.Builtin.Maybe +open import RegistryState +to-path : {A : Set} {x y : A} → x ≡ y → PathP (λ _ → A) x y +to-path {x = x} refl i = x +update-frame-path : {A : Set} (k : Slot) (e : Maybe A) (s : State A) → + PathP (λ _ → Maybe A) (lookup (other k) (put k e s)) (lookup (other k) s) +update-frame-path k e s = to-path (update-frame k e s) +identity-path : {A : Set} (k : Slot) (r m : Maybe A) (e : A) → + lookup k (state r m false) ≡ just e → + PathP (λ _ → Result A) (begin k (state r m false)) (called e (state r m true)) +identity-path k r m e found = to-path (begin-identity k r m e found) +reentrant-path : {A : Set} (k : Slot) (s : State A) → + PathP (λ _ → Result A) (begin k (mark s true)) (refused (mark s true)) +reentrant-path k s = to-path (reentrant-refused k s) +return-path : {A : Set} (k : Slot) (s : State A) → + PathP (λ _ → Maybe A) (lookup k (mark s false)) (lookup k s) +return-path k s = to-path (normal-return-frame k s) + diff --git a/verification/atoma/consumer/lean4/RegistryState.lean b/verification/atoma/consumer/lean4/RegistryState.lean new file mode 100644 index 0000000..3e92820 --- /dev/null +++ b/verification/atoma/consumer/lean4/RegistryState.lean @@ -0,0 +1,45 @@ +-- SPDX-License-Identifier: MPL-2.0 +namespace RegistryState +inductive Slot where | rest | mcp +structure State (A : Type) where + rest : Option A + mcp : Option A + active : Bool +def lookup {A} (k : Slot) (s : State A) := match k with + | .rest => s.rest | .mcp => s.mcp +def other : Slot → Slot | .rest => .mcp | .mcp => .rest +def put {A} (k : Slot) (e : Option A) (s : State A) : State A := match k with + | .rest => ⟨e, s.mcp, s.active⟩ | .mcp => ⟨s.rest, e, s.active⟩ +def mark {A} (s : State A) (b : Bool) : State A := ⟨s.rest, s.mcp, b⟩ +inductive Result (A : Type) where + | refused : State A → Result A + | called : A → State A → Result A +def begin {A} (k : Slot) (s : State A) : Result A := + match s.active with + | true => .refused s + | false => match lookup k s with + | none => .refused s | some e => .called e (mark s true) +theorem updateFrame {A} (k : Slot) (e : Option A) (s : State A) : + lookup (other k) (put k e s) = lookup (other k) s := by cases k <;> rfl +theorem updateIdentity {A} (k : Slot) (e : Option A) (s : State A) : + lookup k (put k e s) = e := by cases k <;> rfl +theorem beginIdentity {A} (k : Slot) (r m : Option A) (e : A) + (h : lookup k (State.mk r m false) = some e) : + begin k (State.mk r m false) = .called e (State.mk r m true) := by + change (match lookup k (State.mk r m false) with + | none => Result.refused (State.mk r m false) + | some x => Result.called x (State.mk r m true)) = _ + rw [h] +theorem reentrantRefused {A} (k : Slot) (s : State A) : + begin k (mark s true) = .refused (mark s true) := rfl +theorem normalReturnFrame {A} (k : Slot) (s : State A) : + lookup k (mark s false) = lookup k s := by cases k <;> rfl +theorem normalReturnIdle {A} (s : State A) : (mark s false).active = false := rfl +#print axioms updateFrame +#print axioms updateIdentity +#print axioms beginIdentity +#print axioms reentrantRefused +#print axioms normalReturnFrame +#print axioms normalReturnIdle +end RegistryState + From dcbfed35be864de4951c532840a3fec0152b7311 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:38:05 +0000 Subject: [PATCH 7/9] Import the natural comparison and conversion libraries explicitly --- verification/atoma/consumer/coq/WordSource.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v index df164a5..aea9a7f 100644 --- a/verification/atoma/consumer/coq/WordSource.v +++ b/verification/atoma/consumer/coq/WordSource.v @@ -3,7 +3,7 @@ (* Closed guarded-decoder source semantics. Original bytes and the complete imported encoder are inputs; an emitter-supplied AST/verdict is not used. Machine/compiler and pointer-carrier correspondence are separate. *) -From Coq Require Import List String Ascii Bool NArith Lia. +From Coq Require Import List String Ascii Bool NArith PeanoNat Nnat Lia. Require Import ScalarSource CanonicalWord. Import ListNotations. Open Scope string_scope. From 1cc383c1ff2e747cb96d13a49638326ee75823f7 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:43:21 +0000 Subject: [PATCH 8/9] Connect source capsules to fresh native consumer replay and fix proof tactics --- scripts/atoma-consumer-source-gate.sh | 42 +++++++++++ scripts/atoma-gate.sh | 2 + scripts/atoma-source-profile-replay.sh | 69 +++++++++++++++++++ tests/consumer-scalar/consumers.tsv | 5 +- tests/consumer-word/proven.pin | 2 +- tests/consumer-word/uaa.pin | 2 +- .../atoma/consumer/coq/RegistrySource.v | 2 - verification/atoma/consumer/coq/WordSource.v | 6 +- 8 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 scripts/atoma-consumer-source-gate.sh create mode 100644 scripts/atoma-source-profile-replay.sh diff --git a/scripts/atoma-consumer-source-gate.sh b/scripts/atoma-consumer-source-gate.sh new file mode 100644 index 0000000..53b9689 --- /dev/null +++ b/scripts/atoma-consumer-source-gate.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +set -euo pipefail +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +mkdir -p "$root/build/atoma-evidence/source-consumers" +out=$(mktemp -d "$root/build/atoma-evidence/source-consumers/run.XXXXXXXX") +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +for profile in decoder registry; do + case "$profile" in + decoder) repo=proven; pin=proven.pin; runner=scripts/test-refc-decoder.sh + helper=ffi/zig/src/refc/bits8_decode_word.zig; wrapper=ffi/zig/src/refc/bits8.zig ;; + registry) repo=unified-api-adapter; pin=uaa.pin; runner=scripts/check-registry-state.sh + helper=src/interface/ffi/src/registry_state.zig; wrapper=src/interface/ffi/src/registry.zig ;; + esac + revision=$(cat "$root/tests/consumer-word/$pin") + [[ $revision =~ ^[0-9a-f]{40}$ ]] + checkout="$work/$repo" + git init -q "$checkout" + git -C "$checkout" remote add origin "https://github.com/hyperpolymath/$repo.git" + git -C "$checkout" fetch -q --depth 1 origin "$revision" + git -C "$checkout" checkout -q --detach FETCH_HEAD + [[ $(git -C "$checkout" rev-parse HEAD) == "$revision" ]] + mkdir "$out/$profile" + echo "$revision" > "$out/$profile/revision.txt" + cp "$checkout/$wrapper" "$out/$profile/consumer-wrapper.zig" + EVIDENCE_DIR="$out/$profile/native" bash "$checkout/$runner" + [[ $(cat "$out/$profile/native/result.txt") == PASS ]] + if [[ $profile == decoder ]]; then + imported="$checkout/ffi/zig/src/refc/bits8_word.zig" + cmp "$checkout/$helper" "$out/$profile/native/bits8_decode_word.zig" + cmp "$imported" "$out/$profile/native/bits8_word.zig" + else + imported=- + cmp "$checkout/$helper" "$out/$profile/native/registry_state.zig" + fi + bash "$root/scripts/atoma-source-profile-replay.sh" "$profile" "$checkout/$helper" "$imported" "$out/$profile/replay" + (cd "$checkout"; sha256sum "$helper" "$wrapper" "$runner") > "$out/$profile/consumer-inputs.sha256" +done +[[ -s "$out/decoder/replay/receipt.json" && -s "$out/registry/replay/receipt.json" ]] +echo 'SOURCE CONSUMERS PASS: fresh Idris2 authority, actual Zig helpers, native controls and independent replay' + diff --git a/scripts/atoma-gate.sh b/scripts/atoma-gate.sh index 5179988..7c391a2 100644 --- a/scripts/atoma-gate.sh +++ b/scripts/atoma-gate.sh @@ -75,6 +75,7 @@ grep -q 'TestExpectedEqual' "$evidence/compiled-bad.txt" bash scripts/atoma-gate-falsifiers.sh | tee "$evidence/falsifiers.txt" bash scripts/atoma-replay-gate.sh | tee "$evidence/replay.txt" bash scripts/atoma-consumer-scalar-gate.sh | tee "$evidence/scalar-consumers.txt" +bash scripts/atoma-consumer-source-gate.sh | tee "$evidence/source-consumers.txt" # Bind the source, contracts, proof sources and gate definitions to this run. # Exclude generated caches/witnesses to avoid self-referential digests. find tools/atoma/src examples/atoma/frame-v1/src examples/atoma/frame-v1/abi \ @@ -85,3 +86,4 @@ sha256sum tools/atoma/build.zig scripts/atoma-*.sh examples/atoma/frame-v1/verif verification/proofs/{agda,idris2}/MANIFEST .github/workflows/atoma.yml >> "$evidence/inputs.sha256" cp examples/atoma/frame-v1/witness/phase0.receipt.json "$evidence/" echo 'ATOMA GATE PASS — INCOMPLETE (Warrant); finite-model replay checked, program refinement unproved' + diff --git a/scripts/atoma-source-profile-replay.sh b/scripts/atoma-source-profile-replay.sh new file mode 100644 index 0000000..5af4aa0 --- /dev/null +++ b/scripts/atoma-source-profile-replay.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# Independent replay of original source bytes; no submitted AST or verdict. +set -euo pipefail +[[ $# == 4 ]] || { echo 'usage: source-replay PROFILE SOURCE IMPORT_OR_DASH NEW_DIRECTORY' >&2; exit 2; } +root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +profile=$1 +source_path=$(realpath "$2") +out=$(realpath -m "$4") +fail() { echo "SOURCE-REPLAY-REFUSED: $*" >&2; exit 1; } +mkdir "$out" || fail 'evidence directory must be new' +cp "$source_path" "$out/source.zig" +case "$profile" in + decoder) + import_path=$(realpath "$3") + cp "$import_path" "$out/encoder.zig" + libraries=(ScalarSource CanonicalWord WordSource) + reports=2 + ;; + registry) + [[ $3 == - ]] || exit 2 + libraries=(ScalarSource RegistrySource) + reports=1 + ;; + *) fail 'unsupported source profile' ;; +esac +for library in "${libraries[@]}"; do + cp "$root/verification/atoma/consumer/coq/$library.v" "$out/" +done +capsule() { + case "$profile" in + decoder) bash "$root/scripts/atoma-word-capsule.sh" "$out/source.zig" "$out/encoder.zig" ;; + registry) bash "$root/scripts/atoma-registry-capsule.sh" "$out/source.zig" ;; + esac +} +capsule > "$out/AtomaProof.v" +cd "$out" +for library in "${libraries[@]}"; do + timeout -k 5 180 coqc -q "$library.v" > "$library-assumptions.txt" 2>&1 +done +sha256sum ./*.v ./*.vo ./*.zig > before.sha256 +timeout -k 5 180 echidna prove "$out/AtomaProof.v" --prover coq --timeout 150 --output json > echidna.json 2> echidna.stderr \ + || fail 'ECHIDNA did not verify the source interpretation' +jq -e -s --arg goal "$out/AtomaProof.v" ' + length == 1 and (.[0] | .schema == "echidna.prove.result/1" and + .status == "verified" and .prover == "Coq" and .goal == $goal and + .trust.axioms == [] and .trust.confidence == null)' echidna.json >/dev/null +[[ -s AtomaProof.vo ]] || fail 'missing compiled proof' +sha256sum -c before.sha256 > recheck.txt || fail 'backend changed independent checker or source' +timeout -k 5 180 coqchk -silent -Q . '' "${libraries[@]}" AtomaProof > coqchk.txt 2>&1 +capsule > Audit.v +cmp -s AtomaProof.v Audit.v || fail 'capsule differs from independent regeneration' +timeout -k 5 180 coqc -q Audit.v > assumptions.txt 2>&1 +[[ $(grep -c '^Closed under the global context$' assumptions.txt) == "$reports" ]] || fail 'unexpected assumptions' +! grep -q '^Axioms:' assumptions.txt +cmp -s source.zig "$source_path" || fail 'source changed during replay' +if [[ $profile == decoder ]]; then cmp -s encoder.zig "$import_path" || fail 'import changed'; fi +for library in "${libraries[@]}"; do + cmp -s "$library.v" "$root/verification/atoma/consumer/coq/$library.v" || fail 'checker changed' +done +sha256sum ./*.zig ./*.v ./*.vo echidna.json assumptions.txt coqchk.txt > inputs.sha256 +for tool in coqc coqchk echidna; do sha256sum "$(command -v "$tool")"; done > tools.sha256 +jq -cnS --arg profile "$profile" \ + '{schema:"atoma.source.profile/1",status:"INCOMPLETE",profile:$profile, + checked:"original source interpretation; independent kernel replay",assumptions:[], + open:["Zig parser/compiler refinement","Idris primitive/compiler correspondence", + "cross-kernel witness transport","pointer validity and exclusive ownership","whole-wrapper effects"]}' > receipt.json +echo "SOURCE-CHECKED $profile: interpreted source; compiler and foreign boundary remain explicit" + diff --git a/tests/consumer-scalar/consumers.tsv b/tests/consumer-scalar/consumers.tsv index b602249..07d3f16 100644 --- a/tests/consumer-scalar/consumers.tsv +++ b/tests/consumer-scalar/consumers.tsv @@ -1,3 +1,4 @@ # repository commit helper contract-oracle -proven 21346ae1c85b7773a4bc16df51cb1ec5977f6b65 ffi/zig/src/refc/bits8_word.zig verification/header/ScalarOracle.idr -unified-api-adapter 730d0c775c9ce84edbe37854d49680cb3b3ed84d src/interface/ffi/src/protocol_tag.zig src/interface/ProtocolTagOracle.idr +proven a38d22ba10d0e22a1bc83a69d7ed7eb547c1c239 ffi/zig/src/refc/bits8_word.zig verification/header/ScalarOracle.idr +unified-api-adapter 759cffa2b631c47b949a7a2219b87d926a3bc7fb src/interface/ffi/src/protocol_tag.zig src/interface/ProtocolTagOracle.idr + diff --git a/tests/consumer-word/proven.pin b/tests/consumer-word/proven.pin index 1a21cbf..07e0da6 100644 --- a/tests/consumer-word/proven.pin +++ b/tests/consumer-word/proven.pin @@ -1 +1 @@ -c0b224778e193c38a6266a086b81ca84c040e31a +a38d22ba10d0e22a1bc83a69d7ed7eb547c1c239 diff --git a/tests/consumer-word/uaa.pin b/tests/consumer-word/uaa.pin index 45894db..7a32f20 100644 --- a/tests/consumer-word/uaa.pin +++ b/tests/consumer-word/uaa.pin @@ -1 +1 @@ -e81904be0a233f7535255e6118cf782be32cc1e6 +759cffa2b631c47b949a7a2219b87d926a3bc7fb diff --git a/verification/atoma/consumer/coq/RegistrySource.v b/verification/atoma/consumer/coq/RegistrySource.v index 31e6ac0..0390feb 100644 --- a/verification/atoma/consumer/coq/RegistrySource.v +++ b/verification/atoma/consumer/coq/RegistrySource.v @@ -235,8 +235,6 @@ Proof. - intros A s k e. destruct k; reflexivity. - intros A s k. destruct k; reflexivity. - intros A s k. destruct k; reflexivity. - - reflexivity. - - reflexivity. Qed. Definition other (k : slot) := match k with MCP => REST | REST => MCP end. diff --git a/verification/atoma/consumer/coq/WordSource.v b/verification/atoma/consumer/coq/WordSource.v index aea9a7f..e3e91b5 100644 --- a/verification/atoma/consumer/coq/WordSource.v +++ b/verification/atoma/consumer/coq/WordSource.v @@ -109,7 +109,7 @@ Proof. apply andb_true_iff in H as [_ H]. rewrite forallb_forall in H. assert (Hn : (N.to_nat b < 256)%nat). { apply Nat.compare_lt_iff. - change (N.to_nat b ?= N.to_nat 256)%nat = Lt. + change ((N.to_nat b ?= N.to_nat 256)%nat = Lt). rewrite <- N2Nat.inj_compare. exact Hb. } assert (Hin : In (N.to_nat b) (seq 0 256)). { apply in_seq. split; [lia | exact Hn]. } @@ -150,7 +150,7 @@ Proof. apply andb_true_iff in H as [Hd H]. apply andb_true_iff in H as [Hm He]. cbn in Hd, Hm. apply N.eqb_eq in Hd. apply N.eqb_eq in Hm. subst d m. unfold evaluate, CanonicalWord.decode, CanonicalWord.payload. cbn [divisor maximum]. - change (if (w / CanonicalWord.stride <=? 255)%N then + change ((if (w / CanonicalWord.stride <=? 255)%N then if (w / CanonicalWord.stride Some (if N.eqb w canonical then Some (w / CanonicalWord.stride)%N else None) @@ -158,7 +158,7 @@ Proof. else None else Some None) = Some (if (w / CanonicalWord.stride Date: Wed, 25 Nov 2026 02:07:04 +0000 Subject: [PATCH 9/9] Avoid trust-scanner identifier collision and document checked source scope --- docs/decisions/ATOMA-BOUNDARY-SOURCE.adoc | 84 ++++++++++++++++++++++ docs/decisions/ATOMA-SIBLING-TRANSFER.adoc | 27 +++++++ docs/plan/ULTRAPLAN.adoc | 20 ++++++ docs/status/PROOF-STATUS.adoc | 17 ++++- scripts/atoma-gate.sh | 2 +- scripts/atoma-registry-capsule.sh | 4 +- scripts/atoma-source-profile-replay.sh | 3 +- scripts/atoma-word-capsule.sh | 6 +- tests/consumer-scalar/consumers.tsv | 2 +- tests/consumer-word/uaa.pin | 2 +- 10 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 docs/decisions/ATOMA-BOUNDARY-SOURCE.adoc diff --git a/docs/decisions/ATOMA-BOUNDARY-SOURCE.adoc b/docs/decisions/ATOMA-BOUNDARY-SOURCE.adoc new file mode 100644 index 0000000..2266cd0 --- /dev/null +++ b/docs/decisions/ATOMA-BOUNDARY-SOURCE.adoc @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += Decoder and registry source-binding milestone +:revdate: 2026-11-25 + +This milestone is experimental. A source interpretation theorem is not a theorem +about all Zig programs, the compiler, the whole FFI wrapper or foreign memory. +The boundary architecture remains Idris2 ABI contracts and pure Zig FFIs/APIs. + +== Two distinct source profiles + +The decoder profile consumes the complete original Proven decoder module and +its complete imported encoder. The lexer preserves the exact quoted import +literal; the parser checks names, types, statement order and end of file. +It interprets unsigned division, the range refusal, checked narrowing, actual +encoder evaluation and full-word equality. The theorem quantifies over all +natural words, including every u64 input. Outer evaluation failure/trap and +normal InvalidRefcResult are distinct; successful admission excludes traps. +No finite native corpus is presented as the universal proof. + +The registry profile consumes UAA's actual generic pure state kernel. +The parser checks record declarations, all function signatures and bodies, +and absence of imports or trailing code. Field selectors, field updates, +status codes and restoration flags become operands in its interpretation. +It proves equivalence with an independently written contract denotation for +arbitrary opaque endpoint values. Endpoint identity includes the callback/context +pair as a value, not ownership or validity of the pointed-to objects. + +The actual UAA FFI calls this state kernel. The source theorem does not yet +interpret allocation, dereference, defer, callback execution or destruction. +The theorem about finish does not prove that every machine path invokes finish. +Native wrapper tests supply additional execution evidence under the ownership +premises below. An implementation digest binds identity; it does not close +these semantic gaps. + +== Contract and checker authority + +The pinned consumer commits live in tests/consumer-word/. Both must be present. +Atoma rebuilds total, warning-free, no-holes Idris2 oracles in fresh directories. +Proven provides 1026 decoder witnesses, including canonical values, tag/low-bit +corruption, high payloads, zero and the maximum word. +UAA supplies 900 two-operation traces over two distinct endpoint identities, +both slots, all initial occupancy/busy states, and 17 signed-status witnesses. +The actual Zig kernels must agree in Debug, ReleaseSafe, ReleaseFast and +ReleaseSmall. Compilable wrong implementations must disagree. + +Atoma independently compiles its Coq source checker, serializes original source +bytes, dispatches the capsule through ECHIDNA, requires a structured verified +result, runs coqchk and independently regenerates and compiles the audit capsule. +Checker objects and input sources must remain unchanged across dispatch. +Whole-boundary receipts remain INCOMPLETE. + +Agda develops the generic frame, endpoint-identity, reentrancy and restoration +witnesses with --safe --without-K --cubical-compatible --double-check. +Lean re-proves those statements without Mathlib; the gate requires six exact, +unique no-axioms reports. Coq instantiates the operational source interpretation. +Full Cubical checks path versions of the compatible Agda witnesses. +These are re-proved legs, not transported proof objects. Statement +correspondence is BRIDGE-PENDING; no PWG upgrade, external verified-checker +qualification or Mathesis admission follows automatically. + +== Ownership and execution premises still owed + +* A live registry has one serialized owner; concurrent operations are outside scope. +* Registered callback code and context, and a call's input slice, remain live. +* Foreign callbacks cannot write the registry through raw aliases. +* Callback return is normal; panic, longjmp, cancellation and nontermination + do not inherit a normal-return restoration theorem. +* RefC target/layout checks are required; pointer/integer-carrier and compiler + correspondence remain unproved. + +== Acceptance and next work + +Acceptance requires green exact-head remote checks in Atoma and both consumers, +native mutations killed for the intended reason, fresh receipts and a review of +the admitted source grammar. Draft code and passing model proofs alone do not +complete this milestone. Heavy local validation remains on hold. + +Next, interpret the wrappers' dereferences, begin/defer/finish sequencing and +callback effect contract; show an alias counterexample before claiming an +exclusive-ownership lift. Bind caller capabilities and lifetime transitions to +Idris2 contracts. Then reconcile the Agda/Lean/Coq statements and integrate the +estate's independent verified checkers. These are v1 prerequisites, not implied +by source-profile admission. + diff --git a/docs/decisions/ATOMA-SIBLING-TRANSFER.adoc b/docs/decisions/ATOMA-SIBLING-TRANSFER.adoc index 174ed0b..a9409a3 100644 --- a/docs/decisions/ATOMA-SIBLING-TRANSFER.adoc +++ b/docs/decisions/ATOMA-SIBLING-TRANSFER.adoc @@ -99,3 +99,30 @@ Run small experiments, not four simultaneous universal-verifier builds. each verifier owns its language boundary, Atoma owns the admitted Zig seam. No sibling files or schedules are changed by this Atoma sprint. + +== Lessons from the decoder and registry source profiles (2026-11-25) + +The first reusable result is a trust-boundary pattern: send original source +bytes to a separate closed parser/interpreter, bind every admitted import, +and audit the checked theorem independently of the emitter. Proven's guarded +decoder needed full import binding, distinction between refusal and trap, and +a universal arithmetic argument. UAA needed parameterized endpoint identity, +state frames, reentrancy and explicit normal-return premises. These are +different semantic obligations even though both use the same replay machinery. + +Fresh Idris2 oracles and four-mode native runs found the practical contract +surface without claiming compiler correctness. Wrong implementations must +compile and then fail execution; parser refusals and compilation failures +are useful controls but are not counted as native mutation kills. + +The portability boundary is also clearer: a generic state record can preserve +callback/context values without proving ownership of their pointees. A busy +flag is not a linear capability. Each sibling must state and discharge its +own alias, lifetime, runtime and exceptional-control-flow obligations. + +Reusable now: source envelopes, import-closure checks, fresh oracle construction, +capsule regeneration, unchanged-checker checks, exact assumption audits and +mutation accounting. Not established: automatic Agda-to-Lean/Coq transport, +equivalence of language semantics, compiler refinement or a measured speedup +for any sibling. Carry the BRIDGE-PENDING state into any second-language spike. + diff --git a/docs/plan/ULTRAPLAN.adoc b/docs/plan/ULTRAPLAN.adoc index 47d4478..8846f85 100644 --- a/docs/plan/ULTRAPLAN.adoc +++ b/docs/plan/ULTRAPLAN.adoc @@ -205,3 +205,23 @@ before each step and does the mechanical edits. The advisor reviews the close of each stage and each change to a status word. The person-week ranges in the sequence table above stay the planning basis; the sizes here only order the agent work. + +== Decoder and registry source binding (2026-11-25) + +R1/R2 now have an implementation under remote validation for two further source +profiles: Proven's guarded decoder plus imported encoder, and UAA's generic +registry state kernel. Both are called by the actual pure Zig FFI wrappers; +Idris2 owns their ABI contracts. See +link:../decisions/ATOMA-BOUNDARY-SOURCE.adoc[scope, acceptance and open obligations]. + +The new gates combine original-byte Coq interpretation, fresh native Idris/Zig +comparisons and ECHIDNA/coqchk replay. The registry theory adds compatible Agda, +axiom-free Lean witnesses and full Cubical paths. They do not establish whole +wrapper effects, compiler correctness, pointer leases or cross-kernel transport. +Their acceptance remains pending until exact-head consumer and Atoma runs pass. + +The next R1 exit item remains a concrete alias counterexample and a checked +ownership premise for callback/defer/finish. T1–T4 and S1–S6 stay open. The v1 +scope and person-week envelope above are unchanged; these deliberately narrow +source profiles are evidence for the experimental MVP, not a shortcut to v1. + diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 4f82753..80ba08b 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -1,7 +1,7 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 // Copyright (c) Jonathan D.A. Jewell = Atoma proof status -:revdate: 2026-11-07 +:revdate: 2026-11-25 Evidence remains *INCOMPLETE / Warrant*. Counts below describe scoped checks; they are not a fraction of Zig soundness or a release-readiness percentage. @@ -83,3 +83,18 @@ The manifests in `verification/proofs/` declare exact checked/quarantined scope. See link:../plan/ULTRAPLAN.adoc[the stable task register] and link:../audit/2026-11-07-soundness-sprint.adoc[the repair evidence]. + +== Source-binding milestone (under qualification) + +The decoder/import and registry-kernel source capsules passed their independent +Coq interpretation, assumption audits, coqchk and rejecting source mutations in +https://github.com/hyperpolymath/atoma/actions/runs/45527831101[run 45527831101] +at head 1cc383c1ff2e747cb96d13a49638326ee75823f7. Registry compatible Agda, +Lean and full Cubical witnesses passed in the same run. Combined consumer and +ECHIDNA qualification was still pending when this entry was prepared. + +The existing proof-policy claims table and grades above are not promoted by +these observations. Cross-kernel statement correspondence is BRIDGE-PENDING. +See link:../decisions/ATOMA-BOUNDARY-SOURCE.adoc[the source-profile decision] +for the exact interpretation, compiler, wrapper and ownership boundaries. + diff --git a/scripts/atoma-gate.sh b/scripts/atoma-gate.sh index 7c391a2..aac94fb 100644 --- a/scripts/atoma-gate.sh +++ b/scripts/atoma-gate.sh @@ -85,5 +85,5 @@ find tools/atoma/src examples/atoma/frame-v1/src examples/atoma/frame-v1/abi \ sha256sum tools/atoma/build.zig scripts/atoma-*.sh examples/atoma/frame-v1/verify.sh \ verification/proofs/{agda,idris2}/MANIFEST .github/workflows/atoma.yml >> "$evidence/inputs.sha256" cp examples/atoma/frame-v1/witness/phase0.receipt.json "$evidence/" -echo 'ATOMA GATE PASS — INCOMPLETE (Warrant); finite-model replay checked, program refinement unproved' +echo 'ATOMA GATE PASS — INCOMPLETE (Warrant); closed source profiles replayed; compiler and foreign-boundary refinement unproved' diff --git a/scripts/atoma-registry-capsule.sh b/scripts/atoma-registry-capsule.sh index 6012225..130e4c2 100644 --- a/scripts/atoma-registry-capsule.sh +++ b/scripts/atoma-registry-capsule.sh @@ -12,7 +12,7 @@ COQ printf 'Definition source_bytes : list nat := ' od -An -v -tu1 "$1" | awk 'BEGIN {printf "["} {for(i=1;i<=NF;i++) {if(n++) printf ";"; printf "%s",$i}} END {print "]."}' cat <<'COQ' -Lemma source_admitted : RegistrySource.check source_bytes = true. +Lemma source_accepted : RegistrySource.check source_bytes = true. Proof. vm_compute. reflexivity. Qed. Theorem source_checked : exists p, RegistrySource.parse source_bytes = Some p /\ (forall A (s : RegistrySource.state A) k e, RegistrySource.register p s k e = RegistrySource.spec_register s k e) /\ @@ -20,6 +20,6 @@ Theorem source_checked : exists p, RegistrySource.parse source_bytes = Some p /\ (forall A (s : RegistrySource.state A) k, RegistrySource.begin p s k = RegistrySource.spec_begin s k) /\ (forall A (s : RegistrySource.state A), RegistrySource.finish p s = RegistrySource.busy_state s false) /\ (forall z, RegistrySource.sanitize p z = if (0 <=? z)%Z && (z <=? 11)%Z then z else 6%Z). -Proof. apply RegistrySource.source_refines. exact source_admitted. Qed. +Proof. apply RegistrySource.source_refines. exact source_accepted. Qed. Print Assumptions source_checked. COQ diff --git a/scripts/atoma-source-profile-replay.sh b/scripts/atoma-source-profile-replay.sh index 5af4aa0..3ce325e 100644 --- a/scripts/atoma-source-profile-replay.sh +++ b/scripts/atoma-source-profile-replay.sh @@ -44,7 +44,8 @@ timeout -k 5 180 echidna prove "$out/AtomaProof.v" --prover coq --timeout 150 -- jq -e -s --arg goal "$out/AtomaProof.v" ' length == 1 and (.[0] | .schema == "echidna.prove.result/1" and .status == "verified" and .prover == "Coq" and .goal == $goal and - .trust.axioms == [] and .trust.confidence == null)' echidna.json >/dev/null + .trust.axioms == [] and .trust.confidence == null)' echidna.json >/dev/null \ + || fail 'ECHIDNA result was malformed, untrusted or not bound to this capsule' [[ -s AtomaProof.vo ]] || fail 'missing compiled proof' sha256sum -c before.sha256 > recheck.txt || fail 'backend changed independent checker or source' timeout -k 5 180 coqchk -silent -Q . '' "${libraries[@]}" AtomaProof > coqchk.txt 2>&1 diff --git a/scripts/atoma-word-capsule.sh b/scripts/atoma-word-capsule.sh index 01c2a6a..56f69b3 100644 --- a/scripts/atoma-word-capsule.sh +++ b/scripts/atoma-word-capsule.sh @@ -20,15 +20,15 @@ bytes "$1" printf 'Definition encoder_bytes : list nat := ' bytes "$2" cat <<'COQ' -Lemma source_admitted : WordSource.check decoder_bytes encoder_bytes = true. +Lemma source_accepted : WordSource.check decoder_bytes encoder_bytes = true. Proof. vm_compute. reflexivity. Qed. Theorem source_checked : forall w b, WordSource.run decoder_bytes encoder_bytes w = Some (Some b) <-> (b < 256)%N /\ w = CanonicalWord.encode b. -Proof. apply WordSource.source_exact. exact source_admitted. Qed. +Proof. apply WordSource.source_exact. exact source_accepted. Qed. Theorem source_no_trap : forall w, WordSource.run decoder_bytes encoder_bytes w = Some (CanonicalWord.decode w). -Proof. apply WordSource.source_corresponds. exact source_admitted. Qed. +Proof. apply WordSource.source_corresponds. exact source_accepted. Qed. Print Assumptions source_checked. Print Assumptions source_no_trap. COQ diff --git a/tests/consumer-scalar/consumers.tsv b/tests/consumer-scalar/consumers.tsv index 07d3f16..60d767b 100644 --- a/tests/consumer-scalar/consumers.tsv +++ b/tests/consumer-scalar/consumers.tsv @@ -1,4 +1,4 @@ # repository commit helper contract-oracle proven a38d22ba10d0e22a1bc83a69d7ed7eb547c1c239 ffi/zig/src/refc/bits8_word.zig verification/header/ScalarOracle.idr -unified-api-adapter 759cffa2b631c47b949a7a2219b87d926a3bc7fb src/interface/ffi/src/protocol_tag.zig src/interface/ProtocolTagOracle.idr +unified-api-adapter d60f9c10bfb92ce9f3b08ac0d92a753f0f49c90a src/interface/ffi/src/protocol_tag.zig src/interface/ProtocolTagOracle.idr diff --git a/tests/consumer-word/uaa.pin b/tests/consumer-word/uaa.pin index 7a32f20..4a72523 100644 --- a/tests/consumer-word/uaa.pin +++ b/tests/consumer-word/uaa.pin @@ -1 +1 @@ -759cffa2b631c47b949a7a2219b87d926a3bc7fb +d60f9c10bfb92ce9f3b08ac0d92a753f0f49c90a