diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 65452cf8..6bd714c0 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -26,6 +26,8 @@ jobs: persist-credentials: false - name: Provision pinned proof tools run: bash scripts/atoma-ci-toolchain.sh + - name: Provision source-model replay tools + run: bash scripts/atoma-ci-replay-toolchain.sh - name: Run required source, contract and proof checks run: bash scripts/atoma-gate.sh - name: Preserve evidence even on failure diff --git a/CLAUDE.md b/CLAUDE.md index badf3dad..6070b03d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell - + # You are in the hyperpolymath estate — orient before acting @@ -63,14 +63,14 @@ Put every question that needs the owner's decision through the selector (the Ask # This repo: `atoma` · clade `fv-atoma` - **Identity** — uuid `#u5"github.com/hyperpolymath/atoma"`; clade `fv` (secondary ``); born 2026-10-22; forge `hyperpolymath/atoma`. -- **IS** — Experimental source-bound verification for an explicitly closed Zig subset. Solver, model and compiled-test evidence remain distinct from independent proof replay. +- **IS** — Experimental source-bound obligations and finite-model proof replay for an explicitly closed Zig subset. Source/compiler refinement remains unproved. - **IS-NOT** — a general Zig soundness certificate · a production verifier · a repository template · an ECHIDNA replacement -- **Where it sits** — pipeline position **language-verification**; chain `Zig source and contracts -> Atoma obligations -> ECHIDNA proof exchange and independent replay (planned)`; coordination = `echidna`. +- **Where it sits** — pipeline position **language-verification**; chain `Zig source and contracts -> Atoma finite-model proof -> ECHIDNA/Coq replay (experimental); full kernel chain planned`; coordination = `echidna`. - **Constraints here** (AGENTIC) — fail-closed; evidence-per-step; no-silent-skip; rerun-after-fix; release-claim-requires-hard-pass. Never: banned langs (above), secrets, state files in repo root, AGPL. Details: the deed's `(bot-directives (methodology) (coverage) (debt))` clauses. - **Golden path** (ANCHOR) — `just test && just quality` → Core tests pass; Quality gates pass; No unresolved critical security findings. - **State** — phase active; maturity experimental. Milestones and next actions: `docs/status/ROADMAP.adoc`. - + ## Estate-Wide Format Migration Directives diff --git a/README.adoc b/README.adoc index 77a4fdd3..48b68e6b 100644 --- a/README.adoc +++ b/README.adoc @@ -8,12 +8,13 @@ Atoma develops source-bound verification for an explicitly closed Zig subset. It currently provides canonical contracts, a syntax screen, typechecked Idris2 specifications, Agda proofs of a store-free model and a finite u8 source pilot. It is not yet a general sound verifier for Zig. Evidence remains -*INCOMPLETE (Warrant)*: compiler/refinement arguments and independent replay -are unfinished. +*INCOMPLETE (Warrant)*: finite-model replay now runs through ECHIDNA and +coqchk, while compiler/refinement arguments and the full kernel chain remain +unfinished. == Build and check -Use Zig 0.15.2, Z3 4.13.3 and the Agda/Idris2 profiles in +Use Zig 0.15.2, Z3 4.13.3 and the Agda/Idris2/ECHIDNA/Coq profiles in link:docs/decisions/ATOMA-TOOLCHAIN.adoc[the toolchain decision]. From the repository root: @@ -25,6 +26,8 @@ bash scripts/atoma-gate.sh The gate rebuilds the current source, runs contract extraction and registered proof checks, checks the good and wrong-body fixtures against every u8 input, and exercises failures for missing tools, stale executables and I/O errors. +It also regenerates source-bound Coq model proofs, runs actual ECHIDNA, +checks the compiled libraries with coqchk and audits theorem assumptions. Evidence is written to `build/atoma-evidence/`. The hosted workflow publishes the same evidence and is required on `main`. @@ -44,8 +47,9 @@ translation, provenance and kernel-replay evidence. == Plan and collaboration The link:docs/plan/ULTRAPLAN.adoc[v1 plan] defines conjunctive release gates, -estimates and stop points. The next stage is a source/proof/replay vertical -slice and explicit alias/memory boundary work. +estimates and stop points. The first finite-model replay slice is described +in link:docs/audit/2026-11-07-source-replay.adoc[the replay report]. Next are +the typed semantic boundary, an alias counterexample and checked refinement. The link:docs/decisions/ATOMA-SIBLING-TRANSFER.adoc[sibling assessment] explains potential reuse with Quintessence, Apodeixis.jl and Bactrian. diff --git a/atoma_chora.deed b/atoma_chora.deed index 7be7ab54..9367d836 100644 --- a/atoma_chora.deed +++ b/atoma_chora.deed @@ -124,12 +124,12 @@ :project "atoma" :ecosystem "hyperpolymath" :position-type "verification-tool" - :purpose "Experimental source-bound verification for an explicitly closed Zig subset. Solver, model and compiled-test evidence remain distinct from independent proof replay." + :purpose "Experimental source-bound obligations and finite-model proof replay for an explicitly closed Zig subset. Source/compiler refinement remains unproved." :not ("a general Zig soundness certificate" "a production verifier" "a repository template" "an ECHIDNA replacement") :pipeline-position "language-verification" - :chain "Zig source and contracts -> Atoma obligations -> ECHIDNA proof exchange and independent replay (planned)" + :chain "Zig source and contracts -> Atoma finite-model proof -> ECHIDNA/Coq replay (experimental); full kernel chain planned" :coordination echidna - (related :name "echidna" :relationship proof-exchange :notes "Planned obligation dispatch and replay; integration is not yet demonstrated.") + (related :name "echidna" :relationship proof-exchange :notes "Real Coq backend exercised by the finite-u8 replay gate; general exchange and cross-kernel translation remain planned.") (related :name "standards" :relationship standard-source :notes "Estate policy and required verification boundaries; canonical repository metadatastician/standards.") (related :name "quintessence" :relationship sibling-verifier :notes "Elixir verification; possible shared Zig native-boundary evidence.") (related :name "Apodeixis.jl" :relationship sibling-verifier :notes "Julia verification; possible shared proof evidence interfaces.") diff --git a/docs/audit/2026-11-07-source-replay.adoc b/docs/audit/2026-11-07-source-replay.adoc new file mode 100644 index 00000000..ea9b833a --- /dev/null +++ b/docs/audit/2026-11-07-source-replay.adoc @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Atoma R1 finite-model replay slice +:revdate: 2026-11-07 + +== Scope and result + +`source-coq` lowers the same closed Zig u8 fragment as `source-vc` and emits a +Coq theorem about all 256 inputs. The body and postcondition are emitted +separately. A false obligation is still emitted: the finite evaluator does not +choose a successful proof. Coq checks finite reflection and the theorem that +the domain check entails the postcondition for every input below 256. + +The local positive run used Zig 0.15.2, ECHIDNA 2.3.0 built with Cargo.lock at +`2ab7574ae1e574b0e881422fde6252bf79dea178`, and Rocq/coqchk 9.2. ECHIDNA was +built with Rust 1.99.1 locally. The separate hosted bootstrap profile uses +Rust 1.99.0 and Ubuntu Noble Coq 8.18.0+dfsg-1build2. These are different +profiles; their environment evidence must not be described as identical. + +The real ECHIDNA `prove --output json` command compiles the exact generated +file. A separate `coqchk` process checks its compiled library recursively. +An importing audit restates the expected theorem directly from the source +with `source-coq-audit`, rather than trusting definitions inside the returned +library. It requires `Print Assumptions` +to report a closed context. The Coq backend invokes `coqc` by name; the adapter +checks that this is the same compiler it records in the tool manifest. + +Local replay controls passed for wrapping increment and identity. Rejections +cover a wrong body, a constant body, stale source, an admitted replacement, +a missing checker, an existing evidence directory, malformed JSON, unknown, +a fake verified result without a compiled proof, and a corrupted compiled +proof, and a valid compiled proof of the wrong model while the expected proof +source is left intact. The last control catches self-referential audits that +only check a returned library against its own definitions. A separate admitted-theorem control compiles and passes `coqchk` but +reports an axiom, demonstrating why the closure check is necessary. + +Hosted results must be read from the exact PR head; local evidence alone is +not a hosted pass. The existing required `Atoma soundness gate` now provisions +the replay tools and runs these checks without a missing-tool skip. + +== Evidence and trust boundary + +Run `bash scripts/atoma-gate.sh` for the complete gate, or build the CLI and +run `bash scripts/atoma-replay-gate.sh` with the pinned tools on PATH. +The latter writes fresh evidence directories below `build/atoma-evidence/`. +For an individual proof use: + +---- +tools/atoma/zig-out/bin/atoma source-coq examples/atoma/source-u8/increment.zig > /tmp/AtomaProof.v +bash scripts/atoma-replay.sh examples/atoma/source-u8/increment.zig /tmp/AtomaProof.v /tmp/new-atoma-replay +---- + +The adapter regenerates the proof from a source snapshot and requires exact +byte equality. A pre-existing directory is refused. The original source, +proof and regenerated proof are compared again after subprocesses finish. +The result includes the ECHIDNA JSON, compiled library, assumption audit, +tool versions, executable hashes and input hashes. A receipt is written only +after every stage succeeds. Its status is always `INCOMPLETE`. + +This is source-derived finite-model proof replay. It is *not* replay of a Z3 +proof certificate, a Zig/compiler refinement proof, an ECHIDNA translation +proof, or the full Dedukti/Coq/Lean4 chain. Coq compilation and coqchk are +separate checks within one prover family. The parser, lowering/emitter, +adapter, toolchain and execution environment remain trusted. Exact hash and +byte binding detects mismatched evidence; it does not prove the emitter's +semantic correctness. The compiled Zig exhaustive witness remains separate. + +== Next acceptance + +R1 is partial. The next work is an explicit typed boundary with source +locations, one aliasing counterexample, and a checked argument connecting +admitted Zig to the model. Before broadening the language, test invalidation +across compiler/target/mode and imported-source changes. Cross-kernel replay +and authenticated COMPLETE receipts remain later conjunctive v1 gates. + +Transfer to Quintessence, Apodeixis.jl and Bactrian should reuse the evidence +protocol, failure cases and trust ledger first. This result does not establish +shared actor, dynamic-dispatch, memory or effect semantics for those languages. diff --git a/docs/audit/2026-11-07-source-replay/README.adoc b/docs/audit/2026-11-07-source-replay/README.adoc new file mode 100644 index 00000000..fbe32e87 --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/README.adoc @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Local replay evidence + +These are results of the complete local gate, using the separately documented +local tool profile. The source manifest records the bytes executed in that +run; it is not a claim that a later documentation/CI repair commit was tested. +The generated proofs, compiled libraries, ECHIDNA result, coqchk logs, receipt +and tool hashes are generated afresh under build/atoma-evidence/replay.*/ and +uploaded by the required hosted Atoma soundness workflow. The committed text +is a review aid; fresh exact-head hosted evidence is the merge gate. + +The frame receipt remains a different model and still lacks its full kernel +chain. The new finite-u8 replay result remains INCOMPLETE: source/compiler +refinement, memory/aliasing and cross-kernel translation are unproved. diff --git a/docs/audit/2026-11-07-source-replay/identity-assumptions.txt b/docs/audit/2026-11-07-source-replay/identity-assumptions.txt new file mode 100644 index 00000000..b7c851e5 --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/identity-assumptions.txt @@ -0,0 +1,3 @@ +atoma_u8 : forall x : nat, x < 256 -> x = (x + 0) mod 256 + : forall x : nat, x < 256 -> x = (x + 0) mod 256 +Closed under the global context diff --git a/docs/audit/2026-11-07-source-replay/increment-assumptions.txt b/docs/audit/2026-11-07-source-replay/increment-assumptions.txt new file mode 100644 index 00000000..117abd62 --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/increment-assumptions.txt @@ -0,0 +1,3 @@ +atoma_u8 : forall x : nat, x < 256 -> (x + 1) mod 256 = (x + 1) mod 256 + : forall x : nat, x < 256 -> (x + 1) mod 256 = (x + 1) mod 256 +Closed under the global context diff --git a/docs/audit/2026-11-07-source-replay/local-gate.txt b/docs/audit/2026-11-07-source-replay/local-gate.txt new file mode 100644 index 00000000..e5c91b9f --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/local-gate.txt @@ -0,0 +1,60 @@ +1/3: Building FrameAbi (FrameAbi.idr) +2/3: Building Extract (Extract.idr) +3/3: Building Linearity (Linearity.idr) +EQUIVALENT blake3:ee4d77f0932619c5c1933d342f645a4eff85d9fead9fb0c1d9c8a0890feb2358 +F0.1 ok: Idris2 contract, QTT negatives and executable Face A extraction +atoma 24 tests (canon + frontend + vc + source) +G1 ok unit tests (frame_parse) +G2 ok cross-compiles: x86_64 aarch64 riscv64 wasm32 +G3 ok layout witness: 60 rows over 4 targets +G4 ok usize-across-FFI rejected on wasm32 (F0.3) +G5 ok seam equivalence blake3:f5f97a7bee44d4596590ecb7745c70565ebdf4fb5daa8a48d9a365a85f265756 +G5 ok divergence probe blake3:d49201f2c05100701a8ed42138066e50ee488b050b6d8ad49957c6226affca70 +G6 ok mutation sweep: 11 applied, 11 distinct artifacts +G7 ok 14 VCs discharged by z3: 8 unsat, 6 sat (blake3:dec3d83389ef29f4ec5d49805ba527f92fef6224b0613a98393ed7f1c69ce35d) +G8 ok Face B extracted from source blake3:ee4d77f0932619c5c1933d342f645a4eff85d9fead9fb0c1d9c8a0890feb2358 +G9 ok syntax screen: 6 exports, 6 contracts, 0 diagnostics +G10 ok negative corpus rejected: 20 diagnostics, 17 distinct codes +G11 ok metatheory typechecks: 4 modules, 0 postulates (blake3:e2b2f961812d4ed1165f3d306d267dd95af7d0f13f7ce146fde9355d7a647249) + +receipt: witness/phase0.receipt.json +{"artifacts":{"face-a":"blake3:f5f97a7bee44d4596590ecb7745c70565ebdf4fb5daa8a48d9a365a85f265756","face-b":"blake3:f5f97a7bee44d4596590ecb7745c70565ebdf4fb5daa8a48d9a365a85f265756","layout":"blake3:c75f72ce33010b457c8dc7f8c8514720904ddaeca9de0ce412cc7d61cf8accd1"},"contract":"atoma.frame.parse","equivalence":"EQUIVALENT","gate":"phase0","mutants":{"applied":11,"distinct":11},"proof":{"modules":4,"srcset":"blake3:e2b2f961812d4ed1165f3d306d267dd95af7d0f13f7ce146fde9355d7a647249","status":"checked"},"schema":"atoma.receipt.v1","smt":{"status":"discharged","vcs":14,"vcset":"blake3:dec3d83389ef29f4ec5d49805ba527f92fef6224b0613a98393ed7f1c69ce35d"},"status":"INCOMPLETE","status_class":"Warrant","subset":{"codes_negative_corpus":17,"contracts":6,"diagnostics_negative_corpus":20},"targets":["aarch64","riscv64","wasm32","x86_64"],"tests":{"atoma":24,"frame_parse":13}} +STATUS: INCOMPLETE (Warrant) - Dedukti/coqchk/lean4checker checks did not run. +SOURCE-PILOT-CHECKED inputs=256 source-blake3:bd2dd1c4c6b45f4ba3f58ece20f737ea9121bde5061f64b593b2e039d5e4d041 +STATUS: INCOMPLETE (Warrant); frontend/compiler refinement unproved +1/1 compiled-witness.test.compiled pilot matches the contract for every u8 input...OK +All 1 tests passed. +falsifier PASS missing ZIG rejected +falsifier PASS missing Z3 rejected +falsifier PASS missing AGDA rejected +falsifier PASS missing IDRIS2 rejected +falsifier PASS stale executable cannot bypass current-source build +falsifier PASS solver stdout cannot hide a failed process +falsifier PASS source command input/output errors are distinct from verification failures +falsifier PASS empty Agda registry rejected +REPLAY-MODEL-CHECKED: ECHIDNA + coqchk; INCOMPLETE, Zig refinement unproved +source.zig: OK +AtomaProof.v: OK +AtomaProof.vo: OK +Audit.v: OK +Audit.vo: OK +echidna.json: OK +coqchk.txt: OK +assumptions.txt: OK +coqc-version.txt: OK +coqchk-version.txt: OK +echidna-version.txt: OK +REPLAY-MODEL-CHECKED: ECHIDNA + coqchk; INCOMPLETE, Zig refinement unproved +REPLAY-FALSIFIER-KILLED wrong-body +REPLAY-FALSIFIER-KILLED literal +REPLAY-FALSIFIER-KILLED stale-source +REPLAY-FALSIFIER-KILLED admitted +REPLAY-FALSIFIER-KILLED missing-kernel +REPLAY-FALSIFIER-KILLED reused-directory +REPLAY-FALSIFIER-KILLED malformed +REPLAY-FALSIFIER-KILLED unknown +REPLAY-FALSIFIER-KILLED no-proof +REPLAY-FALSIFIER-KILLED corrupt +REPLAY-FALSIFIER-KILLED wrong-library +REPLAY GATE PASS: two source-derived models checked, 11 rejection controls, axiom control; INCOMPLETE +ATOMA GATE PASS — INCOMPLETE (Warrant); finite-model replay checked, program refinement unproved diff --git a/docs/audit/2026-11-07-source-replay/local-inputs.sha256 b/docs/audit/2026-11-07-source-replay/local-inputs.sha256 new file mode 100644 index 00000000..e9a0d0a1 --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/local-inputs.sha256 @@ -0,0 +1,35 @@ +eb84b84cc007189377d2a3e64fdb0b86fa505b0d2dba7a0ac138284eca4c6afb examples/atoma/frame-v1/abi/Extract.idr +e8bf96eb9e3ba594744548741a9ee28561a4174f40202d9d7055650930b36c4f examples/atoma/frame-v1/abi/FrameAbi.idr +b722461649bcded19c78a14dd4b6ef76d1f90e69c15d3b5d4e338606505242f8 examples/atoma/frame-v1/abi/FrameAbi.ipkg +31d3619fe4020fdfab117c504249f0c491eb0fd8605e35986d3638e4d77d7c42 examples/atoma/frame-v1/abi/Linearity.idr +f18d016580750126fb2e38ba9a02291a86574d7a316d0d18acbe5064e71661fa examples/atoma/frame-v1/spec/face-a.cspec +8ddc7ad8611fdbd323789fcc5ace9509433e95d84f1be79cf9034b3af454046a examples/atoma/frame-v1/spec/face-b.cspec +3d20b211285a7514cc2c5b3b6cf40d6a1b3a405116514569c5b87d9a940f6666 examples/atoma/frame-v1/spec/layout.cspec +d96d491575b4aa98344b2c408742b4192a3614b597b8d7d1f46ffac3685c1d24 examples/atoma/frame-v1/src/atoma.zig +2690434265c3ca2c6a4b8750ea81a496d4f52dbb25926c89645ff8040a28204f examples/atoma/frame-v1/src/frame_parse.zig +133752532ce17073b76626a6feeb3a9c3ec510fb836d5173c41d0644e9389238 examples/atoma/source-u8/compiled-witness.zig +0dfd0dc5af9adb93726d10dca8531f5140d1f1cf5117a4c68d948ac42c591a45 examples/atoma/source-u8/increment.zig +4296b25b6083732d72127cc021da50a7c4a4ac7ae7fb67274fafd9f261b95857 examples/atoma/source-u8/recursive.zig +605f194214cabbf703961c21b0ddb9e30465b895a9a4dc78351e08cfdce8276d examples/atoma/source-u8/wrong-body.zig +9a8b2000096ec3214899d822e11a4ad060b30515bb11865c70478f1057bb0fdf tools/atoma/src/canon.zig +1ae7f5e849324945e126c928111c78a42de3f6e14c3b24ab0de035752b4916a8 tools/atoma/src/frontend.zig +c9ad5d9f3e47b4127b922641c05ce7da7c7d84b9225d65f721066e98606e4457 tools/atoma/src/main.zig +679278f11b162256d3f3b9d8873c9738f6aa510d2cd894f6ed4a91f4287aede1 tools/atoma/src/source.zig +7bcb0cb5fe70f391e5b3a0c55fc5fd3325657943148090fd3cf7dbeb5b8240c9 tools/atoma/src/vc.zig +a060c98d92d78795186ad5b22e50a664efdc7e0fd618cedc09f889e14d8ff5cd verification/atoma/agda/Bv.agda +97c4e2e52364c0f1d8fef12a33e091ceb4f4cea9ae030d231651127d2390d3e5 verification/atoma/agda/Core.agda +f1e2447cf61217b3b6007dc56f0fcde88caa8f804c75c7e2aff7a4993cc9b643 verification/atoma/agda/Lin.agda +8526085a08c2f8d3c1093fb5137ba3d4fd60f230bf6cb8e623ba5818b73a41a4 verification/atoma/agda/Soundness.agda +d777465faa96e3a894bae826a60f7980fd50fb68cabfc97d9293990cc34c57f6 verification/atoma/check-agda.sh +b0eac35d5b00bef70a4927ccb68111dcc684f5df17ffad6b613ab977fe0f57d8 tools/atoma/build.zig +9259c3bf44be3182cd9f3d2206c72f215b2f41b33feddbbeb602b1efddee4c9f scripts/atoma-check-idris.sh +1798c74bba5da08d830f5ade38fd79881e4dc27f23b5b53e08205cc4cf1bf882 scripts/atoma-ci-replay-toolchain.sh +f17d862442291100bbfef0073925143a21a52aa1bc84fa8072a56584754b1df1 scripts/atoma-ci-toolchain.sh +f7bcacdf76a3e5230d532180902e3098e598dd6882d889f8f6b631efc6f01f06 scripts/atoma-gate-falsifiers.sh +c9d07e6aa84ab94ac4afe765821b1d73f8fa4071afea6110415f4147b6e862a5 scripts/atoma-gate.sh +1e4e7492b6994654bc5c0a396a3ff49c55d8b3b6d7abbb159b44f79f9bb73088 scripts/atoma-replay-gate.sh +6d6e11c3e5761c94209046969e6d9348eb455cc91dcaf06fe3f3af5c49898cd9 scripts/atoma-replay.sh +eedd113fdef194f42ee2ae9187f2d5b03476b91072fa5b8957511a8da4b5d0d4 examples/atoma/frame-v1/verify.sh +358cd904557a41b5c30cdfe9dcd67451ccac31c7cd09b5b2bd6c339023fded46 verification/proofs/agda/MANIFEST +f4d5954e01a91cc3f7911cd36a5eb699c5b3f62a4c457613e2147899a601a33d verification/proofs/idris2/MANIFEST +762fdabfc6752e57a41ab731b7e0c862502a2136f2b2b5f229f520ff08df0bd4 .github/workflows/atoma.yml diff --git a/docs/audit/2026-11-07-source-replay/wrong-library-rejected.txt b/docs/audit/2026-11-07-source-replay/wrong-library-rejected.txt new file mode 100644 index 00000000..d32dc8a4 --- /dev/null +++ b/docs/audit/2026-11-07-source-replay/wrong-library-rejected.txt @@ -0,0 +1,11 @@ +File "./Audit.v", line 2, characters 5-8: +Warning: "From Coq" has been replaced by "From Stdlib". +[deprecated-from-Coq,deprecated-since-9.0,deprecated,default] +File "./Audit.v", line 4, characters 7-26: +Error: +The term "atoma_u8" has type + "forall x : nat, x < 256 -> body x = specification x" +while it is expected to have type + "forall x : nat, x < 256 -> (x + 1) mod 256 = (x + 1) mod 256" +(cannot unify "body x = specification x" and +"(x + 1) mod 256 = (x + 1) mod 256"). diff --git a/docs/decisions/ATOMA-SOURCE-TO-PROOF.adoc b/docs/decisions/ATOMA-SOURCE-TO-PROOF.adoc index 8c91cac8..6e291769 100644 --- a/docs/decisions/ATOMA-SOURCE-TO-PROOF.adoc +++ b/docs/decisions/ATOMA-SOURCE-TO-PROOF.adoc @@ -67,6 +67,13 @@ cycles; imports, aliases and higher-order calls are not generally resolved. == Next semantic work +The R1 finite-model replay slice adds `source-coq` and +`scripts/atoma-replay.sh`: actual ECHIDNA compilation, independent `coqchk`, +and a closed-assumptions audit, with exact regenerated-proof/source binding. +See `docs/audit/2026-11-07-source-replay.adoc` for evidence and trust limits. +This checks a generated Coq model theorem, not a Z3 certificate translation +or Zig refinement. R1 and the full required replay chain remain partial. + . Define a closed typed scalar/struct/slice subset and an assumption manifest; pin the compiler adapter and targets. Add source locations to every IR node. . Model finite machine arithmetic separately from mathematical integers. Check diff --git a/docs/decisions/ATOMA-TOOLCHAIN.adoc b/docs/decisions/ATOMA-TOOLCHAIN.adoc index d25e9f44..08da0c72 100644 --- a/docs/decisions/ATOMA-TOOLCHAIN.adoc +++ b/docs/decisions/ATOMA-TOOLCHAIN.adoc @@ -16,6 +16,8 @@ the entire transitive system environment. | Z3 | 4.13.3 official x86_64 glibc 2.35 archive | SHA-256 pinned in installer; local Debian 4.13.3-1 also exercised | Idris2 | v0.8.0 commit `15a3e4e70843f7a34100f6470c04b791330788df`, Chez bootstrap | Exact fetched commit checked; local 0.8.0-b6cbc25d5 is a separate recorded profile | Agda | Ubuntu package `agda-bin=2.6.3-1build1` | apt authentication and exact package version; local Debian 2.6.4.3-1+b2 is a separate recorded profile +| Coq replay | Ubuntu Noble `coq=8.18.0+dfsg-1build2` | coqc and coqchk from the authenticated package; local Rocq 9.2 is a separate recorded profile +| ECHIDNA | `2ab7574ae1e574b0e881422fde6252bf79dea178`, locked release build, Rust 1.99.0 | No default optional prover features; local build uses Rust 1.99.1. This consumes the existing Rust verifier; it adds no Rust implementation proof claim | Actions | checkout v7.0.1, upload-artifact v7.0.2 | Immutable commits recorded by `gh actions-lock` in `actions.lock`; no credential persistence; read-only repository token |=== diff --git a/docs/plan/ULTRAPLAN.adoc b/docs/plan/ULTRAPLAN.adoc index 56158200..f895e4bd 100644 --- a/docs/plan/ULTRAPLAN.adoc +++ b/docs/plan/ULTRAPLAN.adoc @@ -35,6 +35,8 @@ The following gaps remain central: semantic subset checker. * No real ECHIDNA-to-Dedukti/Coq/Lean4 replay chain is demonstrated. Exported declarations and admitted skeletons are not checked proof translations. + The R1 slice now exercises real ECHIDNA-to-Coq finite-model compilation, + independent coqchk and a no-axioms audit; the full chain remains open. * Store, loops, aliasing, capabilities, modular calls and source refinement remain unproved. There is no sound general Zig verifier yet. * The deed/arrival pack now identify experimental Atoma. Estate compliance @@ -91,6 +93,13 @@ Re-estimate after R1, with compiler/formal-methods expertise available. | R5 | Three pilots, mutation/aspect campaigns, installation/release audit | 5–8 | Published release evidence; all v1 gates satisfied |=== +R1 progress: the source-bound u8 function now has a generated Coq model +theorem and a real ECHIDNA/coqchk path with adversarial replay controls. +This closes a narrow replay experiment, not R1: the alias counterexample, +typed-subset expansion and source-to-model refinement argument remain open. +Do those before expanding features or shortening the v1 estimate. See +`docs/audit/2026-11-07-source-replay.adoc`. + An initial envelope is about 30–60 focused person-weeks plus contingency, with some overlap. Two experienced contributors might deliver the restricted v1 in 6–12 months; part-time work scales accordingly. Broad Verus-like coverage is diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 61a0bd0f..0708ea79 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -18,8 +18,10 @@ execution over 256 inputs; wrong body rejected | Parser/lowering/compiler remain trusted; general calls, imports, memory and loops are refused | Legacy frame SMT | Eight unsat and six sat model obligations | Not derived from the frame implementation body -| Independent replay | Pending next milestone | No complete -ECHIDNA/Dedukti/Coq/Lean4 chain has been demonstrated +| Finite-model replay | Source-derived Coq theorem, actual ECHIDNA compilation, +independent coqchk and closed-assumptions audit; adversarial controls | +Trusted frontend/emitter; no Zig refinement or complete +ECHIDNA/Dedukti/Coq/Lean4 chain |=== The inherited general ABI scaffold has four Idris quarantines. Its Types model diff --git a/docs/status/ROADMAP.adoc b/docs/status/ROADMAP.adoc index 8998a40c..f605209d 100644 --- a/docs/status/ROADMAP.adoc +++ b/docs/status/ROADMAP.adoc @@ -21,9 +21,9 @@ head must independently pass hosted checks before merge. == Next acceptance -* Source/proof/replay vertical slice: a source-derived obligation accepted by - an independent checker, with exact source/tool identity and stale evidence - rejection. No unproved declaration or admitted theorem may count as replay. +* Extend the locally passing finite-model replay slice to a checked + source-to-model argument. Its ECHIDNA/coqchk path requires fresh source/proof + identity and closed assumptions; it does not establish Zig refinement. * Typed semantic boundary and explicit memory/alias counterexample. * Second-language transfer spike before choosing the full sibling sequence. diff --git a/scripts/atoma-ci-replay-toolchain.sh b/scripts/atoma-ci-replay-toolchain.sh new file mode 100644 index 00000000..eb003cbb --- /dev/null +++ b/scripts/atoma-ci-replay-toolchain.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Bounded CI bootstrap profile, alongside ATOMA-TOOLCHAIN.adoc. +set -euo pipefail +: "${RUNNER_TEMP:?runner scratch directory required}" +: "${GITHUB_PATH:?GitHub PATH file required}" +task="$RUNNER_TEMP/atoma-replay-toolchain" +mkdir -p "$task" +sudo apt-get update +sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 jq libssl-dev pkg-config +rustup toolchain install 1.99.0 --profile minimal +git init "$task/echidna" +git -C "$task/echidna" remote add origin https://github.com/hyperpolymath/echidna.git +git -C "$task/echidna" fetch --depth 1 origin 2ab7574ae1e574b0e881422fde6252bf79dea178 +git -C "$task/echidna" checkout --detach FETCH_HEAD +[[ $(git -C "$task/echidna" rev-parse HEAD) == 2ab7574ae1e574b0e881422fde6252bf79dea178 ]] +( + cd "$task/echidna" + cargo +1.99.0 build --locked --release --bin echidna -j 2 +) +echo "$task/echidna/target/release" >> "$GITHUB_PATH" +dpkg-query -W coq +"$task/echidna/target/release/echidna" --version diff --git a/scripts/atoma-gate-falsifiers.sh b/scripts/atoma-gate-falsifiers.sh index baf0230b..af2dfa88 100644 --- a/scripts/atoma-gate-falsifiers.sh +++ b/scripts/atoma-gate-falsifiers.sh @@ -47,14 +47,14 @@ echo 'falsifier PASS solver stdout cannot hide a failed process' atoma="$root/tools/atoma/zig-out/bin/atoma" printf 'export fn broken(' > "$tmp/syntax.zig" truncate -s 16777217 "$tmp/too-large.zig" -for command in source-check source-vc; do +for command in source-check source-vc source-coq source-coq-audit; do for input in absent.zig syntax.zig too-large.zig; do rc=0 "$atoma" "$command" "$tmp/$input" > "$tmp/out" 2>&1 || rc=$? [[ "$rc" == 3 ]] || { echo "FAIL $command $input exit=$rc, expected I/O/parse exit 3" >&2; exit 1; } done done -for command in source-check source-vc; do +for command in source-check source-vc source-coq source-coq-audit; do rc=0 "$atoma" "$command" "$root/examples/atoma/source-u8/increment.zig" > /dev/full 2> "$tmp/out" || rc=$? [[ "$rc" == 3 ]] || { echo "FAIL $command output write error exit=$rc, expected 3" >&2; exit 1; } diff --git a/scripts/atoma-gate.sh b/scripts/atoma-gate.sh index 7f95b0de..8a1a2650 100644 --- a/scripts/atoma-gate.sh +++ b/scripts/atoma-gate.sh @@ -73,6 +73,7 @@ fi 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" # 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 \ @@ -82,4 +83,4 @@ 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); no program-refinement or kernel-replay claim' +echo 'ATOMA GATE PASS — INCOMPLETE (Warrant); finite-model replay checked, program refinement unproved' diff --git a/scripts/atoma-replay-gate.sh b/scripts/atoma-replay-gate.sh new file mode 100644 index 00000000..d4761b95 --- /dev/null +++ b/scripts/atoma-replay-gate.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +set -euo pipefail +root=$(cd "$(dirname "$0")/.." && pwd) +cd "$root" +export ATOMA=${ATOMA:-$root/tools/atoma/zig-out/bin/atoma} +export ECHIDNA=${ECHIDNA:-echidna} COQC=${COQC:-coqc} COQCHK=${COQCHK:-coqchk} +mkdir -p "$root/build/atoma-evidence" +work=$(mktemp -d "$root/build/atoma-evidence/replay.XXXXXX") +pilot="$root/examples/atoma/source-u8" +replay="$root/scripts/atoma-replay.sh" +"$ATOMA" source-coq "$pilot/increment.zig" > "$work/good.v" +bash "$replay" "$pilot/increment.zig" "$work/good.v" "$work/good" +(cd "$work/good" && sha256sum -c inputs.sha256) +printf '/// @ensures result == x +%% 0\nexport fn identity(x: u8) callconv(.c) u8 { return x; }\n' > "$work/identity.zig" +"$ATOMA" source-coq "$work/identity.zig" > "$work/identity.v" +bash "$replay" "$work/identity.zig" "$work/identity.v" "$work/identity" +reject() { + local name=$1 expected=$2; shift 2 + if "$@" > "$work/$name.log" 2>&1; then + echo "FAIL replay accepted $name" >&2; exit 1 + fi + grep -qF "$expected" "$work/$name.log" || { cat "$work/$name.log" >&2; exit 1; } + [[ ! -e "$work/$name/receipt.json" ]] || { echo 'FAIL failure published a receipt' >&2; exit 1; } + echo "REPLAY-FALSIFIER-KILLED $name" +} +"$ATOMA" source-coq "$pilot/wrong-body.zig" > "$work/wrong.v" +reject wrong-body 'ECHIDNA did not verify' bash "$replay" "$pilot/wrong-body.zig" "$work/wrong.v" "$work/wrong-body" +printf '/// @ensures result == x +%% 0\nexport fn constant(x: u8) callconv(.c) u8 { return 0; }\n' > "$work/literal.zig" +"$ATOMA" source-coq "$work/literal.zig" > "$work/literal.v" +reject literal 'ECHIDNA did not verify' bash "$replay" "$work/literal.zig" "$work/literal.v" "$work/literal" +cp "$pilot/increment.zig" "$work/changed.zig" +printf '\n// a source identity change\n' >> "$work/changed.zig" +reject stale-source 'proof does not match current source' bash "$replay" "$work/changed.zig" "$work/good.v" "$work/stale-source" +sed 's/Proof\. vm_compute\. reflexivity\. Qed\./Admitted./' "$work/good.v" > "$work/admitted.v" +reject admitted 'proof does not match current source' bash "$replay" "$pilot/increment.zig" "$work/admitted.v" "$work/admitted" +reject missing-kernel 'missing tool:' env COQCHK="$work/no-such-checker" bash "$replay" "$pilot/increment.zig" "$work/good.v" "$work/missing-kernel" +reject reused-directory 'evidence directory must be new' bash "$replay" "$pilot/increment.zig" "$work/good.v" "$work/good" +cat > "$work/fake-echidna" <<'SH' +#!/usr/bin/env bash +set -euo pipefail +if [[ $1 == --version ]]; then echo 'echidna fake-negative-control'; exit 0; fi +case ${FAKE_MODE:?} in + malformed) echo '{' ;; + unknown) jq -cn --arg goal "$2" '{schema:"echidna.prove.result/1",status:"unknown",prover:"Coq",goal:$goal,trust:{axioms:[],confidence:null}}' ;; + no-proof) jq -cn --arg goal "$2" '{schema:"echidna.prove.result/1",status:"verified",prover:"Coq",goal:$goal,trust:{axioms:[],confidence:null}}' ;; + corrupt) + "$REAL_ECHIDNA" "$@" + printf 'corrupted compiled proof\n' > "${2%.v}.vo" + ;; + wrong-library) + cp "$2" "$2.original" + # Both sides change, so this is a valid closed theorem, but for the + # wrong source model. Restore the expected .v after compiling it. + sed 's/(x + 1) mod 256/(x + 2) mod 256/g' "$2.original" > "$2" + "$REAL_ECHIDNA" "$@" + mv "$2.original" "$2" + ;; + *) exit 2 ;; +esac +SH +chmod +x "$work/fake-echidna" +for mode in malformed unknown no-proof corrupt wrong-library; do + case $mode in + malformed|unknown) reason='malformed, non-verified or assumption-bearing' ;; + no-proof) reason='produced no compiled proof' ;; + corrupt) reason='independent compiled-proof check failed' ;; + wrong-library) reason='theorem type or assumption audit failed' ;; + *) exit 2 ;; + esac + reject "$mode" "$reason" env REAL_ECHIDNA="$ECHIDNA" ECHIDNA="$work/fake-echidna" FAKE_MODE="$mode" \ + bash "$replay" "$pilot/increment.zig" "$work/good.v" "$work/$mode" +done +# This control demonstrates why coqchk alone cannot discharge the no-axioms +# obligation: an admitted theorem compiles and checks, but is not closed. +mkdir "$work/axiom-control" +printf 'Theorem admitted_control : False. Admitted.\nPrint Assumptions admitted_control.\n' > "$work/axiom-control/Control.v" +( + cd "$work/axiom-control" + timeout -k 5 120 "$COQC" -q Control.v > assumptions.txt 2> assumptions.stderr + timeout -k 5 120 "$COQCHK" -silent -Q . '' Control > coqchk.txt 2>&1 + grep -q '^Axioms:' assumptions.txt + ! grep -q '^Closed under the global context$' assumptions.txt +) +echo 'REPLAY GATE PASS: two source-derived models checked, 11 rejection controls, axiom control; INCOMPLETE' diff --git a/scripts/atoma-replay.sh b/scripts/atoma-replay.sh new file mode 100644 index 00000000..a0027a6c --- /dev/null +++ b/scripts/atoma-replay.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Replay the closed u8 model. Never issues a COMPLETE receipt. +set -euo pipefail +[[ $# == 3 ]] || { echo 'usage: atoma-replay.sh SOURCE PROOF NEW_EVIDENCE_DIRECTORY' >&2; exit 2; } +root=$(cd "$(dirname "$0")/.." && pwd) +export ATOMA=${ATOMA:-$root/tools/atoma/zig-out/bin/atoma} +export ECHIDNA=${ECHIDNA:-echidna} COQC=${COQC:-coqc} COQCHK=${COQCHK:-coqchk} +fail() { echo "REPLAY-REFUSED: $*" >&2; exit 1; } +for tool in "$ATOMA" "$ECHIDNA" "$COQC" "$COQCHK" jq timeout sha256sum; do + command -v "$tool" >/dev/null || fail "missing tool: $tool" +done +ATOMA=$(realpath "$(command -v "$ATOMA")") +ECHIDNA=$(realpath "$(command -v "$ECHIDNA")") +COQC=$(realpath "$(command -v "$COQC")") +COQCHK=$(realpath "$(command -v "$COQCHK")") +# The pinned ECHIDNA Coq backend invokes coqc by name. Audit that exact +# compiler, even when a caller supplies COQC as an absolute path. +[[ $(realpath "$(command -v coqc)") == $(realpath "$(command -v "$COQC")") ]] \ + || fail 'COQC differs from the compiler ECHIDNA will invoke' +source_path=$(realpath "$1") +proof_path=$(realpath "$2") +out=$(realpath -m "$3") +# No pre-existing .vo, receipt, or cached result may contribute to this run. +mkdir "$out" || fail 'evidence directory must be new' +cp "$source_path" "$out/source.zig" +cp "$proof_path" "$out/AtomaProof.v" +"$ATOMA" source-coq "$out/source.zig" > "$out/regenerated.v" +cmp -s "$out/AtomaProof.v" "$out/regenerated.v" || fail 'proof does not match current source and emitter' +cd "$out" +"$COQC" --version > coqc-version.txt +"$COQCHK" --version > coqchk-version.txt +"$ECHIDNA" --version > echidna-version.txt +case $(head -n 1 coqc-version.txt) in + 'The Coq Proof Assistant, version 8.18.0'|'The Rocq Prover, version 9.2') ;; + *) fail 'unsupported Coq/Rocq profile' ;; +esac +# ECHIDNA's backend compiles this exact source file. Its JSON verdict alone +# does not certify a proof or the absence of assumptions. +timeout -k 5 120 "$ECHIDNA" prove "$out/AtomaProof.v" --prover coq --timeout 90 --output json \ + > echidna.json 2> echidna.stderr || fail 'ECHIDNA did not verify the obligation' +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 \ + || fail 'malformed, non-verified or assumption-bearing ECHIDNA result' +[[ -s AtomaProof.vo ]] || fail 'ECHIDNA produced no compiled proof' +# Check the actual compiled library, recursively, with no -admit/-norec. +timeout -k 5 120 "$COQCHK" -silent -Q . '' AtomaProof > coqchk.txt 2>&1 \ + || fail 'independent compiled-proof check failed' +# Restate the expected theorem from the source snapshot, never by trusting +# body/specification definitions in the returned .vo. A valid proof of a +# different model must fail even if the backend leaves the expected .v intact. +# coqchk also permits axioms, so audit this theorem's full assumption closure. +"$ATOMA" source-coq-audit source.zig > Audit.v +timeout -k 5 120 "$COQC" -q -Q . '' Audit.v > assumptions.txt 2> assumptions.stderr \ + || fail 'theorem type or assumption audit failed' +[[ $(grep -c '^Closed under the global context$' assumptions.txt) == 1 ]] \ + || fail 'the theorem is not closed under the global context' +! grep -q '^Axioms:' assumptions.txt || fail 'axioms in theorem closure' +cmp -s "$source_path" source.zig || fail 'source changed during replay' +cmp -s "$proof_path" AtomaProof.v || fail 'proof changed during replay' +cmp -s AtomaProof.v regenerated.v || fail 'proof was changed by a subprocess' +sha256sum source.zig AtomaProof.v AtomaProof.vo Audit.v Audit.vo echidna.json \ + coqchk.txt assumptions.txt coqc-version.txt coqchk-version.txt echidna-version.txt > inputs.sha256 +for tool in "$ATOMA" "$ECHIDNA" "$COQC" "$COQCHK"; do + sha256sum "$(command -v "$tool")" +done > tools.sha256 +source_digest=$(sha256sum source.zig | cut -d ' ' -f 1) +proof_digest=$(sha256sum AtomaProof.v | cut -d ' ' -f 1) +jq -cnS --arg source "$source_digest" --arg proof "$proof_digest" \ + '{schema:"atoma.replay.u8/1",status:"INCOMPLETE",scope:"source-derived finite u8 model", + source_sha256:$source,proof_sha256:$proof,echidna:"verified",coqchk:"checked", + assumptions:[],refinement:"unproved"}' > receipt.json.tmp +mv receipt.json.tmp receipt.json +echo 'REPLAY-MODEL-CHECKED: ECHIDNA + coqchk; INCOMPLETE, Zig refinement unproved' diff --git a/tools/atoma/src/main.zig b/tools/atoma/src/main.zig index bfc2be89..5226f814 100644 --- a/tools/atoma/src/main.zig +++ b/tools/atoma/src/main.zig @@ -71,7 +71,7 @@ fn sourceReport(comptime fmt: []const u8, args: anytype) void { } fn usage() noreturn { - sayLine("usage: atoma [args]"); + sayLine("usage: atoma [args]"); std.process.exit(2); } @@ -85,7 +85,7 @@ pub fn main() !void { if (args.len < 2) usage(); const cmd = args[1]; - if (std.mem.eql(u8, cmd, "source-vc") or std.mem.eql(u8, cmd, "source-check")) { + if (std.mem.eql(u8, cmd, "source-vc") or std.mem.eql(u8, cmd, "source-coq") or std.mem.eql(u8, cmd, "source-coq-audit") or std.mem.eql(u8, cmd, "source-check")) { if (args.len != 3) usage(); const src = readFile(args[2]) catch |e| { print("SOURCE-IO-ERROR {s}: {s}\n", .{ args[2], @errorName(e) }); @@ -98,10 +98,11 @@ pub fn main() !void { else => @as(u8, 1), }); }; - if (std.mem.eql(u8, cmd, "source-vc")) { + if (!std.mem.eql(u8, cmd, "source-check")) { var out = std.Io.Writer.Allocating.init(gpa); defer out.deinit(); - p.emit(&out.writer) catch |e| { + const emitted = if (std.mem.eql(u8, cmd, "source-coq")) p.emitCoq(&out.writer) else if (std.mem.eql(u8, cmd, "source-coq-audit")) p.emitCoqAudit(&out.writer) else p.emit(&out.writer); + emitted catch |e| { std.debug.print("SOURCE-IO-ERROR: {s}\n", .{@errorName(e)}); std.process.exit(3); }; diff --git a/tools/atoma/src/source.zig b/tools/atoma/src/source.zig index fd36c357..cb722961 100644 --- a/tools/atoma/src/source.zig +++ b/tools/atoma/src/source.zig @@ -28,6 +28,14 @@ pub const Expr = union(enum) { .add_wrap => |n| try w.print("(bvadd x (_ bv{d} 8))", .{n}), } } + + fn coq(self: Expr, w: *std.Io.Writer) !void { + switch (self) { + .input => try w.writeAll("x"), + .literal => |n| try w.print("{d}", .{n}), + .add_wrap => |n| try w.print("(x + {d}) mod 256", .{n}), + } + } }; pub const Program = struct { @@ -50,6 +58,44 @@ pub const Program = struct { try self.body.smt(w); try w.print(" (bvadd x (_ bv{d} 8)))))\n(check-sat)\n", .{self.ensures_add}); } + + /// A closed finite-model theorem, not a Zig/compiler refinement proof or + /// a translation of a solver certificate. A wrong body emits a false + /// obligation that Coq must reject; no evaluator verdict selects the proof. + pub fn emitCoq(self: Program, w: *std.Io.Writer) !void { + const hash = std.fmt.bytesToHex(self.source_hash, .lower); + try w.print("(* atoma.source.u8.coq.v1 source-blake3:{s} *)\n", .{hash}); + try w.writeAll("From Coq Require Import Arith List Bool.\nDefinition body (x : nat) : nat := "); + try self.body.coq(w); + try w.print(".\nDefinition specification (x : nat) : nat := (x + {d}) mod 256.\n", .{self.ensures_add}); + try w.writeAll( + \\Definition domain_check : bool := + \\ forallb (fun x => Nat.eqb (body x) (specification x)) (seq 0 256). + \\Lemma domain_checked : domain_check = true. + \\Proof. vm_compute. reflexivity. Qed. + \\Theorem atoma_u8 : forall x : nat, x < 256 -> body x = specification x. + \\Proof. + \\ intros x Hx. apply Nat.eqb_eq. + \\ assert (Hin : In x (seq 0 256)). + \\ { apply in_seq. split; [apply Nat.le_0_l | exact Hx]. } + \\ pose proof domain_checked as H. + \\ unfold domain_check in H. rewrite forallb_forall in H. + \\ exact (H x Hin). + \\Qed. + \\Print Assumptions atoma_u8. + \\ + ); + } + + /// Restate the expected theorem from source. Referring to body/specification + /// inside the returned library would only check that library against itself. + pub fn emitCoqAudit(self: Program, w: *std.Io.Writer) !void { + const hash = std.fmt.bytesToHex(self.source_hash, .lower); + try w.print("(* atoma.source.u8.audit.v1 source-blake3:{s} *)\n", .{hash}); + try w.writeAll("From Coq Require Import Arith.\nRequire Import AtomaProof.\nCheck (AtomaProof.atoma_u8 : forall x : nat, x < 256 -> "); + try self.body.coq(w); + try w.print(" = (x + {d}) mod 256).\nPrint Assumptions AtomaProof.atoma_u8.\n", .{self.ensures_add}); + } }; const Cursor = struct {