diff --git a/.github/workflows/zig-ci.yml b/.github/workflows/zig-ci.yml index d4da30ad..76e81fb3 100644 --- a/.github/workflows/zig-ci.yml +++ b/.github/workflows/zig-ci.yml @@ -77,6 +77,10 @@ jobs: tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP" echo "$RUNNER_TEMP/zig-x86_64-linux-${ZIG_VERSION}" >> "$GITHUB_PATH" + # PROOF-POLICY §6 deviation (state: open): Idris2 is built from its + # pinned release commit here, not installed through build/guix.scm or the + # container. Neither is available on the CI runner. The commit is asserted + # below. Record: docs/status/PROOF-STATUS.adoc, "Toolchain deviations". - name: Build Idris2 from the pinned release commit run: | set -euo pipefail @@ -104,3 +108,61 @@ jobs: idris2 --build src/interface/E2e/abi-e2e.ipkg LD_LIBRARY_PATH=zig-out/lib src/interface/E2e/build/exec/abi-e2e \ tests/testdata/crosscheck.traces tests/testdata/crosscheck-root.anchor + + # Chain-of-trust theory (PROOF-POLICY §1-§2, §8): the Agda source and its Rocq + # and Lean re-proofs, with one receipt per leg on every commit. + # + # PROOF-POLICY §6 deviation (state: open): Agda and Rocq come from Ubuntu's + # apt archive and Lean from its GitHub release tarball, not from + # build/guix.scm or the container, which the runner lacks. Each install + # asserts the exact version, and Lean's tarball its sha256, before use. + # Record: docs/status/PROOF-STATUS.adoc, "Toolchain deviations". + theory-proofs: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + permissions: + contents: read + env: + AGDA_DEB: "2.6.3-1build1" + COQ_DEB: "8.18.0+dfsg-1build2" + LEAN_VERSION: "4.15.0" + LEAN_SHA256: "af71a2569a9f68337de2434829b3008cd8e32c436e9cb6bd8c84a2c2ba3585c9" + steps: + - uses: actions/checkout@v7.0.1 + + - name: Install Agda and Rocq (version-asserted) + run: | + set -euo pipefail + sudo apt-get update -q + sudo apt-get install -y -q "agda-bin=${AGDA_DEB}" "coq=${COQ_DEB}" + test "$(dpkg-query -W -f='${Version}' agda-bin)" = "$AGDA_DEB" + test "$(dpkg-query -W -f='${Version}' coq)" = "$COQ_DEB" + sha256sum "$(command -v agda)" "$(command -v coqc)" + + - name: Install Lean (checksum-verified) + run: | + set -euo pipefail + curl --proto '=https' --tlsv1.2 -fsSL -o "$RUNNER_TEMP/lean.tar.zst" \ + "https://github.com/leanprover/lean4/releases/download/v${LEAN_VERSION}/lean-${LEAN_VERSION}-linux.tar.zst" + echo "${LEAN_SHA256} $RUNNER_TEMP/lean.tar.zst" | sha256sum -c - + tar --zstd -xf "$RUNNER_TEMP/lean.tar.zst" -C "$RUNNER_TEMP" + echo "$RUNNER_TEMP/lean-${LEAN_VERSION}-linux/bin" >> "$GITHUB_PATH" + + - name: Check every proof MANIFEST (Agda, Rocq, Lean) + run: | + set -euo pipefail + scripts/check-proofs.sh agda + scripts/check-proofs.sh coq + scripts/check-proofs.sh lean4 + + - name: Chain-of-trust receipts (one per leg, this commit) + run: | + set -euo pipefail + scripts/theory-receipts.sh "$RUNNER_TEMP/theory-receipts.jsonl" + { + echo "### Chain-of-trust receipts" + echo + echo '```' + cat "$RUNNER_TEMP/theory-receipts.jsonl" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.machine_readable/root-allow.txt b/.machine_readable/root-allow.txt index f8115901..a08e8b0d 100644 --- a/.machine_readable/root-allow.txt +++ b/.machine_readable/root-allow.txt @@ -32,6 +32,7 @@ LICENSE LICENSES/ # REUSE licence texts, dual-licence model (code MPL-2.0 / docs CC-BY-SA-4.0) CHANGELOG.adoc # AsciiDoc is the estate-standard documentation format CITATION.cff # citation metadata; GitHub reads it from the root of the default branch only +EXPLAINME.adoc # claims-to-evidence map and proof ledger; the estate README/EXPLAINME standard (standards docs/README-EXPLAINME-STANDARD.adoc) places it at the repository root only zig-dnssec_chora.deed # the repo deed: universal AI entry point; family-7 allocation manifest + ply tree folded in (standards#837 pilot). Filename carries the repo slug (deed dispatch _chora.deed), so repo-init renames it at mint CLAUDE.md # generated arrival pack; the generator, pre-commit and Claude Code all read it from the ROOT (do not hand-edit; edit the repo deed) ?GEMINI.md # pointer to CLAUDE.md for repos without AGENTS.md yet diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index a2838964..a8f747aa 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -30,9 +30,31 @@ https://semver.org/spec/v2.0.0.html[Semantic Versioning]. the interface (`src/interface/Abi/`) whose result type cannot carry an answer for a bogus or indeterminate verdict; tests keep the three in step, and an Idris2 end-to-end test (`just abi-e2e`) runs in CI. +* Chain-of-trust soundness as theory (PROOF-POLICY §1): for any signature check, a + validator walking signed keys down from a trust anchor returns `secure` or + `insecure` only for a fully verified chain, and `bogus` for anything else. Agda is + the source of truth (`verification/proofs/agda/ChainOfTrust.agda`, `--safe + --without-K --cubical-compatible`). Rocq and Lean re-prove it, and the statement + correspondence is in `verification/proofs/CORRESPONDENCE.adoc`: PWG-2ii, no axioms + in any leg. `scripts/theory-receipts.sh` and the `theory-proofs` CI job write one + receipt per leg on each commit. +* Proof ledger (`EXPLAINME.adoc#proof-ledger`) and a proof-status file + (`docs/status/PROOF-STATUS.adoc`) with grades, receipts, boundary assumptions and + toolchain deviations. They replace the template's status files, which still read + "0% proven" and listed template obligations. +* Idris2 ABI model: decoding is exact. No byte decodes to a code other than its own, + proved by evaluation over all 256 values (status codes: 0..255). The safe wrapper + refuses a library of another ABI version, and a reported text length that does not + fit its buffer. ==== Fixed +* The deed's `(canon …)` pin moves from 2.1.3 to canon 2.1.5 (gates sha256 + `5c510bba…`). Canon lockstep had been red since `standards` released 2.1.4 + on 2026-11-05. The new gate table only widens accepted layouts; criteria + are unchanged. The template adopts the same pin in + hyperpolymath/rsr-template-repo#306. + * Integer overflow in name decoding at the 255-octet boundary (found by fuzzing). * DNAME answers were rejected because the synthesised CNAME was examined diff --git a/EXPLAINME.adoc b/EXPLAINME.adoc new file mode 100644 index 00000000..767346b9 --- /dev/null +++ b/EXPLAINME.adoc @@ -0,0 +1,333 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += zig-dnssec — EXPLAINME +:toc: preamble +:icons: font + +This file maps each claim in link:README.adoc[README.adoc] to the code that implements it, +the evidence that checks it and its limits, for anyone deciding how far to trust it. + +[IMPORTANT] +==== +zig-dnssec is experimental and has not been independently reviewed. Nothing below is +a substitute for that review. +==== + +== Claims and their implementation + +=== Wire codec + +[quote, README.adoc] +____ +bounds-checked decoding that rejects malformed messages (compression pointers must point +strictly backwards; names in RDATA are decompressed only where RFC 3597 permits; trailing +data, misplaced OPT and meta-types are rejected), and an encoder with name compression. +____ + +How this is implemented:: +link:src/wire/message.zig[], link:src/wire/name.zig[] and link:src/wire/rdata.zig[]. The +presentation format is in link:src/wire/text.zig[]. Each strict prefix of a valid message +is rejected by the unit tests, and the fuzz targets are described in +link:docs/reports/FUZZ-RESULTS.adoc[]. + +Caveat:: +Tested and fuzzed, not proved. Fuzzing found and fixed one integer overflow in name +decoding. + +=== Signatures + +[quote, README.adoc] +____ +RSASHA1, RSASHA1-NSEC3-SHA1, RSASHA256, RSASHA512, ECDSAP256SHA256, ECDSAP384SHA384 and +ED25519, all through Zig's standard library; DS digests SHA-1, SHA-256 and SHA-384. No +cryptographic primitive is implemented here. +____ + +How this is implemented:: +link:src/dnssec/crypto.zig[] calls Zig's `std.crypto`. The tests are the RFC known-answer +vectors in link:tests/vectors.zig[]. + +Caveat:: +The correctness of `std.crypto` is assumed, not reviewed here (see the proof ledger). + +=== Chain of trust + +[quote, README.adoc] +____ +DS → DNSKEY → RRSIG from the signer up to the closest trust anchor, RRSIG validity windows +in RFC 1982 serial arithmetic, CNAME and DNAME chains, wildcard expansion. +____ + +How this is implemented:: +The code is link:src/dnssec/validator.zig[], link:src/dnssec/rrset.zig[] and +link:src/dnssec/anchors.zig[]. It is checked by link:tests/replay.zig[], which replays 263 +recorded responses, and by the Unbound and ldns cross-check +(link:tests/crosscheck/REPORT.adoc[]). The decision procedure is proved sound in +link:verification/proofs/agda/ChainOfTrust.agda[] and re-proved in Rocq and Lean (see the +proof ledger). + +Caveat:: +The proof is about a model of the chain walk. That `validator.zig` follows the model is +argued, not proved. Closest-anchor selection, validity windows and wildcards are tested, +not proved. + +=== Denial of existence + +[quote, README.adoc] +____ +NSEC and NSEC3 proofs for NXDOMAIN, NODATA, wildcards and insecure delegations, including +Opt-Out and the RFC 6840 restrictions. +____ + +How this is implemented:: +The code is link:src/dnssec/nsec.zig[] and link:src/dnssec/nsec3.zig[]. The tests, +link:tests/denial.zig[], cover every Appendix B example of RFC 4035 and RFC 5155. + +Caveat:: +Tested, not proved. The chain-of-trust proof treats a denial as one signed object and does +not model NSEC/NSEC3 semantics. + +=== Verdicts that cannot be downgraded silently + +[quote, README.adoc] +____ +the result is `secure | insecure | bogus | indeterminate`. Answer data is reachable only +from the `secure` arm, or from the `insecure` arm together with the reason and the zone at +which insecurity was _proven_. Every failure is `bogus` or `indeterminate`. +____ + +How this is implemented:: +In the library, the `Verdict` tagged union in link:src/dnssec/validator.zig[] carries an +answer only in the `secure` and `insecure` arms. At the C ABI, the Idris2 model in +link:src/interface/Abi/Types.idr[] makes an answer unrepresentable for Bogus and +Indeterminate. In the theory, the `fail-closed` theorem says a chain that is not fully +verified is `bogus`. + +Caveat:: +The Zig union is a type-level guarantee checked by the Zig compiler, not by a proof. The +theory covers the model, not the code. + +=== Stub client + +[quote, README.adoc] +____ +DoH over TLS 1.2/1.3 with certificate verification, optional HTTP CONNECT proxy (TLS end to +end), RFC 8467 query padding. +____ + +How this is implemented:: +link:src/stub/doh.zig[] and link:src/stub/client.zig[]. Every cross-check query goes +through this transport. + +Caveat:: +Zig 0.17.0's `std.http.Client` sends HTTPS requests in cleartext through a CONNECT proxy, so +the transport drives `std.crypto.tls.Client` itself. Correctness of the TLS client is +assumed. + +=== From C, Idris2 and other languages + +[quote, README.adoc] +____ +The header is the contract: a verdict whose security is never `SECURE` unless the call +succeeded, and answer text only for `SECURE` and `INSECURE`. +____ + +How this is implemented:: +The contract is link:src/interface/ffi/include/zig_dnssec.h[], implemented in +link:src/interface/ffi/src/main.zig[]. It is checked three ways: ++ +* link:src/interface/ffi/test/abi_test.zig[] runs the C behaviour; +* link:src/interface/ffi/test/seam_test.zig[] compares the Idris2 model with the header; +* link:src/interface/E2e/Main.idr[] runs Idris2 → C → Zig end to end. + +Caveat:: +The Idris2 FFI marshalling and the library's memory safety are assumed (see the proof +ledger). + +== Dogfooded Across The Account + +[cols="1,2,2", options="header"] +|=== +| Technology / Pattern | Used here | Also used in + +| Idris2 interface and ABI proofs +| `src/interface/Abi/`: verdict codes, layout, and no answer with a failed verdict +| link:https://github.com/hyperpolymath/proven[proven], + link:https://github.com/hyperpolymath/proven-servers[proven-servers] + +| Agda theory rechecked in Rocq and Lean (PROOF-POLICY §1–§2) +| `verification/proofs/`: chain-of-trust soundness +| link:https://github.com/hyperpolymath/mathesis[mathesis] (the estate proof catalogue), + link:https://github.com/hyperpolymath/echidna[echidna] (multi-prover exchange) + +| RSR template seams and gates (deed, contractiles, variant contract) +| the repository layout, `just validate`, `scripts/check-variant-drift.sh` +| link:https://github.com/hyperpolymath/rsr-template-repo[rsr-template-repo] +|=== + +== Known gaps + +[CAUTION] +==== +Not implemented, as the README says: DNS-over-QUIC, Ed448 and GOST/SM2 signatures, +HTTP/2, RFC 5011 trust-anchor rollover, negative trust anchors, caching and QTYPE `ANY`. +What each gap means for a caller is in link:docs/architecture/THREAT-MODEL.adoc[]. +==== + +[CAUTION] +==== +Proofs stop at the model. That `validator.zig` follows the proved chain-of-trust +procedure is argued, not proved. Tracked in +link:https://github.com/hyperpolymath/zig-dnssec/issues/9[#9]. +==== + +[CAUTION] +==== +Independent review: none yet. Live validation against the real root was run by hand +once (2026-10-13) and is not automated. +==== + +[[evidence-index]] +== Evidence Index + +[cols="2,3", options="header"] +|=== +| Path | Proves + +| link:docs/reports/VERIFICATION.adoc[] +| Every claim with its status and artefact, including the cross-check and fuzzing detail + +| link:docs/status/PROOF-STATUS.adoc[] +| The proof-status file: grades, receipts, assumptions and toolchain deviations + +| link:verification/proofs/CORRESPONDENCE.adoc[] +| How the Agda, Rocq and Lean statements of the theory correspond + +| link:tests/crosscheck/REPORT.adoc[] +| Every disagreement with Unbound and ldns, explained +|=== + +[[proof-ledger]] +== Proof Ledger + +Rows use the closed status vocabulary of the README/EXPLAINME standard +(`proven`, `proven-with-postulates`, `argued`, `tested-only`, `open`); PROOF-POLICY §5 +names them `PROVEN`, `PROVEN-WITH-AXIOMS`, `ASSUMED`, `TESTED` and `OPEN`. The checker +versions are those of the latest receipts in `docs/status/PROOF-STATUS.adoc`. + +[cols="3,1,2,3,3", options="header"] +|=== +| Obligation | Status | Checker (version, flags) | Where | Trust boundary + +| Chain-of-trust soundness: `secure` and `insecure` only from a fully verified chain from the anchor; anything else is `bogus` (theory, Agda source) +| proven +| Agda 2.6.3, `--safe --without-K --cubical-compatible` +| `verification/proofs/agda/ChainOfTrust.agda`: `secure-sound`, `insecure-sound`, `complete`, `fail-closed` +| A model of the chain walk; the signature check is a parameter, so unforgeability is outside the proof + +| The same four theorems, Rocq leg (re-proved) +| proven +| Coq 8.18.0, `coqc`; `Print Assumptions`: closed +| `verification/proofs/coq/ChainOfTrust.v` +| Statement correspondence with the Agda source by reading, `verification/proofs/CORRESPONDENCE.adoc` + +| The same four theorems, Lean leg (re-proved) +| proven +| Lean 4.15.0, `lean`; `#print axioms`: none +| `verification/proofs/lean4/ChainOfTrust.lean` +| As for the Rocq leg + +| `validator.zig` follows the proved chain-of-trust procedure +| argued +| - +| `docs/reports/VERIFICATION.adoc` (estate note), `verification/proofs/CORRESPONDENCE.adoc` +| Not formalised; the code is tested against the same failures (`tests/replay.zig`) + +| C ABI codes: status, security and reason codes round-trip +| proven +| Idris2 0.7.0, `--typecheck src/interface/abi.ipkg`, `%default total`, no escape hatch +| `src/interface/Abi/Types.idr`: `statusRoundTrip`, `securityRoundTrip`, `reasonRoundTrip` +| The model of the header; its agreement with the header is the seam row below + +| No byte decodes to a constructor other than the one that encodes to it (security and reason: all 256 values; status: codes 0..255) +| proven +| Idris2 0.7.0, as above (proof by evaluation) +| `src/interface/Abi/Types.idr`: `securityDecodeExact`, `reasonDecodeExact`, `statusDecodeExact`, `allBytesCount` +| Idris2's primitive `Bits8`/`Int` equality + +| Status codes outside 0..255 decode to no status +| argued +| - +| `src/interface/Abi/Types.idr`: `statusFromCode`'s catch-all clause +| A proof by evaluation cannot range over all of `Int` + +| A zeroed verdict decodes to no verdict +| proven +| Idris2 0.7.0, as above +| `src/interface/Abi/Types.idr`: `zeroIsNoVerdict` +| - + +| No answer can be returned with a Bogus or Indeterminate verdict +| proven +| Idris2 0.7.0, as above +| `src/interface/Abi/Types.idr`: `answerOnlyIfUsable`; `src/interface/Abi/Foreign.idr`: `Outcome`, `answerOf` +| Idris2 callers only; C callers rely on the header contract and the tests below + +| The verdict struct's fields are aligned, in order, not overlapping, and its size is a multiple of its alignment +| proven +| Idris2 0.7.0, as above +| `src/interface/Abi/Layout.idr`: `verdictLayoutValid` +| Natural alignment and 8-bit bytes, as on the 64-bit targets built for + +| The Idris2 model matches the C header as the C compiler sees it (codes, offsets, sizes, `%foreign` parameter kinds) +| tested-only +| `zig build test` +| `src/interface/ffi/test/seam_test.zig` +| Eleven planted mismatches, one of each kind, were each caught when the test was written + +| The Zig exports have exactly the header's types, and every validator reason has a header code +| tested-only +| Zig 0.17.0 compiler, every build +| `src/interface/ffi/src/main.zig`: `exportChecked`, `reasonCode` +| A compile-time check by the Zig compiler, not a proof kernel + +| The C ABI fails closed: security NONE on every non-OK status; no answer text for any of the 51 recorded bogus scenarios; text emptied before argument checks +| tested-only +| `zig build test` +| `src/interface/ffi/test/abi_test.zig` +| The recorded scenarios and the listed bad-argument cases + +| The Idris2 wrapper refuses a library of another ABI version, and a reported text length that does not fit its buffer +| tested-only +| `just abi-e2e` +| `src/interface/Abi/Foreign.idr`: `validateTrace`; `src/interface/E2e/Main.idr` +| The negative controls (ABI 2, over-reported `text_len`) were run by hand, not in CI + +| The Idris2 FFI marshalling (Chez backend) passes values as the `%foreign` types say +| argued +| - +| `src/interface/Abi/Foreign.idr` (header comment) +| Idris2 0.7.0 (`27780073`) runtime, assumed (PROOF-POLICY §1.1) + +| Closest-anchor selection: an insecure ancestor cannot override a closer anchor +| tested-only +| `zig build test` +| `tests/replay.zig` (four island-anchor cases) +| Not in the chain-of-trust model + +| NSEC and NSEC3 denial proofs are correct +| tested-only +| `zig build test` +| `tests/denial.zig` +| Every RFC 4035 and RFC 5155 Appendix B example; not proved + +| Signature verification is correct +| argued +| - +| `src/dnssec/crypto.zig` over `std.crypto` +| Zig 0.17.0 `std.crypto`, assumed; RFC vectors in `tests/vectors.zig` test the calls +|=== + +Census of rows: 8 `proven` of 18; 6 `tested-only`, 4 `argued`, 0 `open`. The closest-anchor +rule, denial semantics and the model-to-code link are the rows with no proof yet; +`docs/status/PROOF-NEEDS.adoc` lists them as needs. diff --git a/README.adoc b/README.adoc index c1f79540..0cc90993 100644 --- a/README.adoc +++ b/README.adoc @@ -133,11 +133,17 @@ is sent anywhere. Running the tests needs no network. Only the live examples abo zig build test # unit, RFC vector, denial, replay, fuzz smoke and C ABI tests idris2 --typecheck src/interface/abi.ipkg # proofs of the Idris2 ABI model just abi-e2e # Idris2 -> C ABI -> Zig end to end +scripts/theory-receipts.sh # chain-of-trust theory: Agda, Rocq and Lean, with receipts zig build fuzz --fuzz=500K -Doptimize=ReleaseSafe # coverage-guided fuzzing zig build fuzz-tool -Doptimize=ReleaseSafe && ./zig-out/bin/dnssec-fuzz all 60 tests/crosscheck/make-zones.sh && tests/crosscheck/servers.sh start && tests/crosscheck/run.sh ---- +What is proved, tested or only argued, and how strongly, is the proof ledger in +link:EXPLAINME.adoc#proof-ledger[EXPLAINME.adoc]: 8 proven of 18 rows; 6 tested-only, +4 argued, 0 open. The theory needs Agda 2.6.3, Coq 8.18 and Lean 4.15; versions and +receipts are in link:docs/status/PROOF-STATUS.adoc[docs/status/PROOF-STATUS.adoc]. + The cross-check needs NSD, Unbound, ldns tools and haproxy; `build/container/Containerfile` provides them. Its latest output is link:tests/crosscheck/REPORT.adoc[`tests/crosscheck/REPORT.adoc`]. diff --git a/docs/architecture/REPOSITORY-MAP.adoc b/docs/architecture/REPOSITORY-MAP.adoc index 780ceb7c..d40083f5 100644 --- a/docs/architecture/REPOSITORY-MAP.adoc +++ b/docs/architecture/REPOSITORY-MAP.adoc @@ -97,6 +97,10 @@ predecessors did. | optional | estate docs gate (standards scripts/check-docs-presence.sh) requires CONTRIBUTING at the ROOT; this is the copy it verifies +| `EXPLAINME.adoc` +| yes +| claims-to-evidence map and proof ledger; the estate README/EXPLAINME standard (standards docs/README-EXPLAINME-STANDARD.adoc) places it at the repository root only + | `GEMINI.md` | optional | pointer to CLAUDE.md for repos without AGENTS.md yet diff --git a/docs/reports/VERIFICATION.adoc b/docs/reports/VERIFICATION.adoc index 0934b8f2..4aec198d 100644 --- a/docs/reports/VERIFICATION.adoc +++ b/docs/reports/VERIFICATION.adoc @@ -3,15 +3,16 @@ = zig-dnssec: what has been verified, and what has not :toc: -Status as of 2026-10-13, Zig 0.17.0, Idris2 0.7.0. Every claim below is tagged with the -estate's five statuses and names the artefact that discharges it. The PROVEN rows are -about the C ABI seam (`src/interface/`) and are checked by Idris2; nothing about the -validator's own logic is proved yet. +Status as of 2026-10-13, Zig 0.17.0, Idris2 0.7.0, except where a row gives its own +date. Every claim below is tagged with the estate's five statuses and names the artefact +that discharges it. The PROVEN rows are about the C ABI seam (`src/interface/`), checked +by Idris2, and, from 2026-11-09, about the chain-of-trust decision procedure as a model, +checked in Agda, Rocq and Lean. Nothing about the validator's own code is proved. [cols="1,4",options="header"] |=== | Status | Meaning here -| PROVEN | discharged by a machine-checked proof (Idris2 typecheck of `src/interface/abi.ipkg`) +| PROVEN | discharged by a machine-checked proof: the Idris2 typecheck of `src/interface/abi.ipkg` for the C ABI rows; Agda, Rocq and Lean, run by `scripts/theory-receipts.sh`, for the chain-of-trust model | TESTED | discharged by a test or run that is in the repository and reproducible | ASSUMED | relied on without being checked here | DESIGNED | built and reasoned about, but not exercised by a test @@ -73,18 +74,24 @@ validator's own logic is proved yet. wildcard without proof, positive answer relabelled NXDOMAIN, ...) | Failures are never reported as insecure -| TESTED (for the cases above) / DESIGNED (in general) -| the mutation tests assert `bogus`; the type of `Verdict` makes the answer unreachable - from failure arms, and at the C ABI seam the Idris2 model makes it unrepresentable - (PROVEN row above). A proof about the validator's own decisions is OPEN (see the - estate note below). +| PROVEN (for the chain-of-trust model) / TESTED (for the code) +| For the decision procedure (added 2026-11-09, after this report's snapshot): + `verification/proofs/agda/ChainOfTrust.agda` proves that + `secure` and `insecure` require a fully verified chain from the anchor, and that + any chain that is not fully verified is `bogus` (`fail-closed`). The proof is + re-proved in Rocq and Lean, PWG-2ii (`docs/status/PROOF-STATUS.adoc`). For the code: + the mutation tests assert `bogus`; the type of `Verdict` makes the answer + unreachable from failure arms; and at the C ABI seam the Idris2 model makes it + unrepresentable (PROVEN row above). That `validator.zig` follows the model is + argued, not proved (see the estate note below). | Resource limits (fetches, signatures, failures per RRset, NSEC3 hashes) | TESTED | `tests/replay.zig` budget cases; `tests/denial.zig` hash budget -| C ABI seam, Idris2 model: every status, security and reason code round-trips; code 0 - decodes to no verdict; the verdict struct's fields are aligned, in order, not +| C ABI seam, Idris2 model: every status, security and reason code round-trips, and no + byte decodes to a constructor other than the one that encodes to it (all 256 values; + status codes 0..255); code 0 decodes to no verdict; the verdict struct's fields are aligned, in order, not overlapping, and its size is a multiple of its alignment; an `Outcome` for `Bogus` or `Indeterminate` cannot hold an answer, and `answerOf` cannot be applied to one | PROVEN @@ -290,11 +297,23 @@ bash scripts/check-variant-drift.sh ../parent-pin . The guarantee "answer data is only reachable with secure evidence or a proven-insecure reason" is the kind of invariant the estate's epistemic-types work is meant to state: a `secure` answer as knowledge, `insecure` as justified absence of authentication, and no -path from `bogus` to an answer. It is now stated as a type at the ABI seam -(`src/interface/Abi/`): an Idris2 caller cannot receive answer data with a bogus or -indeterminate verdict, even if the library wrote answer text for one (the FFI -marshalling and the library's memory safety are assumed). Inside the library the same -guarantee rests on the shape of a Zig tagged union and on tests. The next step towards -PROVEN is a model of the validator's decision procedure (the chain walk and the denial -proofs) in which "secure" can only be built from verified signatures up to an anchor; -that is a larger piece of work and is not started. +path from `bogus` to an answer. It is proved at two levels: + +* *At the ABI seam* (`src/interface/Abi/`, Idris2, engineering): an Idris2 caller cannot + receive answer data with a bogus or indeterminate verdict, even if the library wrote + answer text for one. The FFI marshalling and the library's memory safety are assumed. +* *For the decision procedure* (`verification/proofs/`, theory): for any signature + check, a validator that walks signed keys down from a trust anchor returns `secure` + only for a fully verified chain ending in a signed answer, and `insecure` only for a + fully verified chain ending in a verified denial. Any other chain is `bogus`. Agda is + the source of truth; Rocq and Lean re-prove it, and the statements are compared in + `verification/proofs/CORRESPONDENCE.adoc`. + +Still open: + +* that `src/dnssec/validator.zig` follows that procedure (an `argued` row in the ledger); +* the closest-anchor rule, the NSEC/NSEC3 denial semantics, wildcards and validity + windows, each tested but outside the model. + +Each one is a row in the proof ledger (`EXPLAINME.adoc#proof-ledger`), and +`docs/status/PROOF-NEEDS.adoc` lists them as needs. diff --git a/docs/status/PROOF-NEEDS.adoc b/docs/status/PROOF-NEEDS.adoc index 67dfc551..027407dc 100644 --- a/docs/status/PROOF-NEEDS.adoc +++ b/docs/status/PROOF-NEEDS.adoc @@ -1,122 +1,67 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 -// Copyright (c) Jonathan D.A. Jewell -// Template: rsr-template-repo/docs/status/PROOF-NEEDS.adoc -// Authoritative master list: ~/Desktop/PROOF-REQUIREMENTS-MASTER.adoc -= Proof Requirements — ZIG_DNSSEC +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Proof Needs — zig-dnssec -== Proof Tier +The proofs zig-dnssec still needs, in order of the risk they would retire. -// Assign one: T1 (Critical), T2 (High), T3 (Standard), T4 (Light), T5 (Exempt) -*Tier*: T3 — Standard +* What is already proved, tested or argued: the ledger in + link:../../EXPLAINME.adoc#proof-ledger[EXPLAINME.adoc]. +* Grades, receipts, assumptions and toolchain deviations: + link:PROOF-STATUS.adoc[PROOF-STATUS.adoc]. +* Which prover carries which obligation: PROOF-POLICY §1 (`hyperpolymath/standards`, + `3-practice/PROOF-POLICY.adoc`). In short, Idris2 for the C ABI and other + engineering properties of this repository, and Agda for theory, rechecked in Rocq and + Lean. No Mathlib. -== Proof Categories +*Tier*: T3 — Standard, as set at mint. It has not been reassessed for a security-relevant +validator; reassessing it is the owner's call. -[cols="1,3,1", options="header"] -|=== -| Code | Meaning | Applies? - -| *TP* | Typing Proofs (type soundness, type safety) | Yes -| *INV* | Invariant Proofs (state machines, monotonicity, bounds) | -| *SEC* | Security Proofs (crypto, injection freedom, access control) | -| *CONC* | Concurrency Proofs (linearizability, deadlock freedom) | -| *ALG* | Algorithm Proofs (termination, correctness, bounds) | -| *ABI* | ABI/FFI Proofs (memory layout, pointer safety, platform compat) | Yes -| *DOM* | Domain-Specific Proofs (bespoke to this project) | -|=== - -== Mandatory Proofs (All RSR Repos) - -These proofs come from the zig-dnssec and MUST be present in every repo: - -=== ABI/FFI Boundary Proofs (Idris2) - -[cols="1,3,1,3", options="header"] -|=== -| # | Proof | Status | File - -| ABI-1 | Non-null pointer proofs (`So (ptr /= 0)`) | Needed | `verification/proofs/idris2/ABI/Pointers.idr` -| ABI-2 | Memory layout correctness (`HasSize`, `HasAlignment`) | Needed | `verification/proofs/idris2/ABI/Layout.idr` -| ABI-3 | Platform type size proofs (per platform) | Needed | `verification/proofs/idris2/ABI/Platform.idr` -| ABI-4 | FFI function return type proofs | Needed | `verification/proofs/idris2/ABI/Foreign.idr` -| ABI-5 | C ABI compliance (`CABICompliant`, `FieldsAligned`) | Needed | `verification/proofs/idris2/ABI/Compliance.idr` -|=== - -=== Typing Proofs (Prover Varies) - -[cols="1,3,1,3", options="header"] -|=== -| # | Proof | Status | File - -| TP-1 | Core data type well-formedness | Needed | `verification/proofs/idris2/Types.idr` -| TP-2 | Public API type safety (exported functions) | Needed | `verification/proofs/lean4/ApiTypes.lean` -|=== - -== Project-Specific Proofs +== Needs -// Fill in proofs specific to this project. Copy from PROOF-REQUIREMENTS-MASTER.adoc -// Delete this section for T4/T5 repos - -[cols="1,3,1,1,1,2", options="header"] -|=== -| # | Proof Needed | Category | Prover | Priority | File(s) - -| | | | | | -|=== - -== Dangerous Patterns (BANNED) - -The following MUST NOT appear anywhere in proof files: - -[cols="2,2,3", options="header"] -|=== -| Pattern | Language | Meaning - -| `believe_me` | Idris2 | Unsafe cast / trust-me -| `assert_total` | Idris2 | Skip totality check -| `postulate` | Idris2/Agda | Unproven axiom -| `sorry` | Lean4 | Incomplete proof -| `Admitted` | Coq | Incomplete proof -| `unsafeCoerce` | Haskell | Unsafe type cast -| `Obj.magic` | OCaml/ | Unsafe type cast -| `unsafe` (unaudited) | Rust | Unsafe block without safety comment -|=== - -CI will reject any PR introducing these patterns (enforced by `panic-attack assail`). - -== Prover Selection Guide - -[cols="2,2,3", options="header"] +[cols="1,4,1,1,3",options="header"] |=== -| Use Case | Recommended Prover | Why - -| ABI/FFI boundaries | *Idris2* | Dependent types model layouts precisely -| Type system proofs | *Coq* or *Lean4* | Mature proof assistants for metatheory -| Algebraic properties | *Lean4* | Good mathlib support -| Inductive/coinductive | *Agda* | Native support for (co)induction -| Distributed systems | *TLA+* | Model checking for protocols -| Numerical properties | *Isabelle* | Strong real analysis library +| # | Proof needed | Kind | Prover | Notes + +| N1 +| `src/dnssec/validator.zig` follows the proved chain-of-trust procedure (model to code) +| engineering +| - +| `argued` today. One route: generate a table of verdicts from the model and check that the code agrees on it, as in the estate's worked ledger example ("the proved table is the code's table"). Zig has no mapped verifier (PROOF-POLICY §1). + +| N2 +| Closest anchor: insecurity proved at a zone does not apply below a closer trust anchor +| theory +| Agda, then Rocq and Lean +| `tested-only` today (four island-anchor replay tests). This is the property behind both P1 findings of the #4 review. + +| N3 +| NSEC and NSEC3 denial: a verified record set proves NXDOMAIN, NODATA and an insecure delegation exactly when RFC 4035 and RFC 5155 say it does +| theory +| Agda, then Rocq and Lean +| `tested-only` today (every RFC Appendix B example). The chain-of-trust model treats a denial as one signed object. + +| N4 +| RRSIG validity windows: the RFC 1982 serial-arithmetic comparison is correct, including wrap-around +| theory +| Agda, then Rocq and Lean +| `tested-only` today (`src/dnssec/rrset.zig` tests). Small and self-contained. + +| N5 +| The status decoder accepts no code outside 0..255 +| engineering +| Idris2 +| `argued` today (the catch-all clause). A proof needs reasoning over all of `Int`, which proof by evaluation cannot do. + +| N6 +| `PWG-1` for the chain-of-trust theorems +| process +| - +| Needs a current headless, pinned receipt on each commit. The `theory-proofs` CI job writes the receipts; the grade becomes derivable once one exists for the commit. |=== -== Proof File Locations - ----- -verification/proofs/ -├── idris2/ # Idris2 proofs (ABI, dependent types) -│ ├── ABI/ # ABI-specific proofs -│ └── *.idr # Project-specific Idris2 proofs -├── lean4/ # Lean4 proofs (algebra, lattices) -│ └── *.lean -├── agda/ # Agda proofs (induction, metatheory) -│ └── *.agda -├── coq/ # Coq proofs (type systems, compilation) -│ └── *.v -└── tlaplus/ # TLA+ specs (distributed protocols) - └── *.tla ----- - -== References +== Escape hatches -* Master list: `~/Desktop/PROOF-REQUIREMENTS-MASTER.adoc` -* Proof status tracking: `PROOF-STATUS.adoc` (this repo) -* Proven library: `proven` repo (Idris2 verified foundations) -* Template: `rsr-template-repo/docs/status/PROOF-NEEDS.adoc` +What counts as an escape hatch, and how any that are allowed are budgeted and recorded, +is set by `docs/TRUSTED-BASE-REDUCTION-POLICY.adoc` in `hyperpolymath/standards`. None +of zig-dnssec's own proof files uses one: no `believe_me`, `assert_total`, `postulate`, +`sorry`, `Admitted` or `axiom`. diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 49d53021..e31051be 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -1,101 +1,186 @@ // SPDX-License-Identifier: CC-BY-SA-4.0 -// Copyright (c) Jonathan D.A. Jewell -// Template: rsr-template-repo/docs/status/PROOF-STATUS.adoc -// Tracks proof completion. Requirements defined in PROOF-NEEDS.adoc -= Proof Status — ZIG_DNSSEC - -== Summary - -[cols="2,1,1,1,1,1", options="header"] -|=== -| Category | Total | Done | In Progress | Blocked | Remaining - -| ABI/FFI (ABI) | 5 | 0 | 0 | 0 | 5 -| Typing (TP) | 2 | 0 | 0 | 0 | 2 -| Invariant (INV) | 0 | 0 | 0 | 0 | 0 -| Security (SEC) | 0 | 0 | 0 | 0 | 0 -| Concurrency (CONC) | 0 | 0 | 0 | 0 | 0 -| Algorithm (ALG) | 0 | 0 | 0 | 0 | 0 -| Domain (DOM) | 0 | 0 | 0 | 0 | 0 -| *Total* | *7* | *0* | *0* | *0* | *7* +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Proof Status — zig-dnssec +:toc: + +This is zig-dnssec's proof-status file under PROOF-POLICY (`hyperpolymath/standards`, +`3-practice/PROOF-POLICY.adoc` at `9bdf864cc7f2c8e24b4df84bf00d04158eee3ad5`). + +* Every proof obligation is a row of the proof ledger in + link:../../EXPLAINME.adoc#proof-ledger[EXPLAINME.adoc]. This file does not repeat + those rows. +* This file holds what the policy asks for beyond the ledger: the theory theorems' + Proof Witness Grades with their receipts (§8), the import cone (§1.1), the assumptions + at the boundaries (§1.1), and the toolchain deviations (§6). +* What is still needed is in link:PROOF-NEEDS.adoc[PROOF-NEEDS.adoc]. + +== Engineering proofs (Idris2) + +The C ABI's interface contract is proved in Idris2 (PROOF-POLICY §1, "APIs, ABIs and +engineering properties"): + +* `src/interface/Abi/Types.idr`: codes, exact decoding, and no answer with a failed + verdict; +* `src/interface/Abi/Layout.idr`: the verdict struct's layout; +* `src/interface/Abi/Foreign.idr`: the safe wrapper. + +Engineering proofs carry §5 status tokens only and are not graded on the PWG ladder +(§8.1). + +* *Checker:* Idris2 0.7.0, built from the release commit + `27780073c8631826d846499840b3857d9b9a4fd5`. +* *Invocation:* `idris2 --typecheck src/interface/abi.ipkg`. The CI step also fails on any + `Error` line, because `idris2` can exit 0 with one. +* *Escape hatches:* every module is `%default total`. None contains `believe_me`, + `assert_total`, `assert_smaller`, `idris_crash`, `unsafePerformIO`, a hole or `partial` + (the scan uses the patterns of `mathesis/scripts/census/proof-holes.sh`). +* *Import cone:* the `base` package of Idris2 0.7.0. Its own primitives (including the + `Data.Buffer` FFI) are the Idris2 runtime's trusted base. That reliance is the `argued` + FFI-marshalling row in the ledger. + +== Theory proofs: chain-of-trust soundness + +The theorems `secure-sound`, `insecure-sound`, `complete` and `fail-closed` are theory +(§1). They are statements about the decision procedure of any validator that walks signed +keys down from a trust anchor, not about one repository's code. + +[cols="1,3",options="header"] |=== +| Field | Value -*Overall*: 0% proven +| Source of truth +| `verification/proofs/agda/ChainOfTrust.agda` (Agda) -== Proofs Done +| `pwg` +| `2ii` -// Format: -// | ID | Proof | Prover | File | Date | Verified By | -// | ABI-1 | Non-null pointer proofs | Idris2 | verification/proofs/idris2/ABI/Pointers.idr | 2026-XX-XX | idris2 --check | +| `foundation_diverse` +| `false` (Agda, Rocq and Lean are all dependent type theories, §8.3) -[cols="1,3,1,3,1,2", options="header"] -|=== -| ID | Proof | Prover | File | Date | Verified By +| Agda leg +| route: source; §5: `PROVEN`; §2.2: `AGDA-VERIFIED` -| — | No proofs completed yet | — | — | — | — -|=== +| Rocq leg +| route: `re-proved`; §5: `PROVEN`; §2.2: `RECONCILED` + (link:../../verification/proofs/CORRESPONDENCE.adoc[CORRESPONDENCE.adoc]) -== Proofs In Progress +| Lean leg +| route: `re-proved`; §5: `PROVEN`; §2.2: `RECONCILED` + (link:../../verification/proofs/CORRESPONDENCE.adoc[CORRESPONDENCE.adoc]) -[cols="1,3,1,2,1,2", options="header"] -|=== -| ID | Proof | Prover | Assignee | Started | Blocker +| Axioms +| none in any leg: Agda `--safe` with no postulates; Rocq `Print Assumptions`: + "Closed under the global context" for each theorem; Lean `#print axioms`: "does not + depend on any axioms" for each theorem -| — | — | — | — | — | — +| Residual assumptions +| `verify` is a parameter: unforgeability of the signature algorithms is outside the + proof. The model's scope, and the model-to-code link (`argued`), are as listed in + CORRESPONDENCE.adoc. |=== -== Proofs Blocked +The grade is `PWG-2ii`. `PWG-1` additionally needs a current receipt for every witness +from a headless pinned run on each commit. The `theory-proofs` CI job writes those +receipts (`scripts/theory-receipts.sh`). Until a CI receipt exists for the commit in +question, the grade stated here is `PWG-2ii`. -[cols="1,3,2,3", options="header"] -|=== -| ID | Proof | Blocked By | Notes +=== Import cone (§1.1) -| — | — | — | — -|=== +* *Agda:* root module `ChainOfTrust`; flags `--safe --without-K --cubical-compatible`; no + imports; postulate count 0 (`--safe`, plus the comment-aware scan in + `scripts/theory-receipts.sh`); no library. +* *Rocq:* the prelude only; no `Require`. +* *Lean:* core only; no imports, no Mathlib. + +=== Receipts -== Proofs Remaining +Session run, `scripts/theory-receipts.sh`, on source commit +`d283ab6da5519ae37b7ec534728472d328bd7b0a` with the proof files clean: -[cols="1,3,1,1,1,1", options="header"] +[cols="1,2,1,3",options="header"] |=== -| ID | Proof | Category | Prover | Priority | Est. Effort - -| ABI-1 | Non-null pointer proofs | ABI | Idris2 | P1 | 2h -| ABI-2 | Memory layout correctness | ABI | Idris2 | P1 | 4h -| ABI-3 | Platform type size proofs | ABI | Idris2 | P1 | 2h -| ABI-4 | FFI function return type proofs | ABI | Idris2 | P1 | 2h -| ABI-5 | C ABI compliance | ABI | Idris2 | P1 | 4h -| TP-1 | Core data type well-formedness | TP | Idris2 | P1 | 4h -| TP-2 | Public API type safety | TP | Lean4 | P2 | 4h +| Leg | Checker and version | Result | Input digest + +| agda +| Agda version 2.6.3; `agda --safe --without-K --cubical-compatible ChainOfTrust.agda` +| proven, axioms: none +| `sha256:a9968f659fafdd0ca596f73fb5fbb99da803520703e8556fb7ba89cf2e168101` + +| rocq +| The Coq Proof Assistant, version 8.18.0; `coqc ChainOfTrust.v` +| proven, axioms: none +| `sha256:aefaaee247da5ab4e2fc5ff51fb4d5ff60fe13ae7780e9d3c209410d8a5eb2e9` + +| lean +| Lean (version 4.15.0, commit 11651562caae, Release); `lean ChainOfTrust.lean` +| proven, axioms: none +| `sha256:f66ec2f17458d246cfd1ab92231425a98c9d084175e890e3d2a39f089a7041fc` |=== -== Verification Commands +That run was not headless or isolated. It is a working receipt, not a `PWG-1` one. The +negative controls run with it (a fail-open `check` in each prover, a postulate under +`--safe`, a planted Lean `axiom` and a planted Rocq `Axiom`) were each rejected. -[source,bash] ----- -# Check all Idris2 proofs -just proof-check-idris2 +== Assumptions at the boundaries (§1.1) -# Check all Lean4 proofs -just proof-check-lean4 +Each assumption is an `argued` row in the ledger: -# Check all Agda proofs -just proof-check-agda +* *Idris2 FFI marshalling:* the Chez backend of Idris2 0.7.0 + (`27780073c8631826d846499840b3857d9b9a4fd5`) passes values as the `%foreign` types in + `src/interface/Abi/Foreign.idr` say. +* *Signature verification:* Zig 0.17.0's `std.crypto`. The RFC known-answer vectors in + `tests/vectors.zig` test the calls, not the primitives. +* *TLS:* Zig 0.17.0's `std.crypto.tls.Client`, used by the DoH transport. -# Check all Coq proofs -just proof-check-coq +== Toolchain deviations (§6) -# Run all proof checks -just proof-check-all +None of the proof toolchains is installed through the Guix manifest or the container. +The CI runners have no Guix, and `build/container/Containerfile` does not include the +provers. Each install asserts the version it got, and fails on a mismatch. -# Scan for dangerous patterns -panic-attack assail --proofs-only ----- +[cols="1,2,2,1",options="header"] +|=== +| Leg | Tool, version, digest | Installed how | State + +| Idris2 ABI model +| Idris2 0.7.0, release commit `27780073c8631826d846499840b3857d9b9a4fd5` (asserted by `git rev-parse`) +| built from source in `zig-ci.yml`, job `abi-seam` +| `open` + +| Agda theory leg +| `agda-bin 2.6.3-1build1`; `/usr/bin/agda` sha256 `852806142a15951f667df303c73cfce5f4123218ce6e1f1b29acaddc242af00d` (Ubuntu 24.04) +| apt, `zig-ci.yml`, job `theory-proofs` +| `open` + +| Rocq leg +| `coq 8.18.0+dfsg-1build2`; `/usr/bin/coqc` sha256 `f14ab0c140bdfdb31c7e7e1f20379703973376480a4eea2d43d0fa56ddae03ec` (Ubuntu 24.04) +| apt, `zig-ci.yml`, job `theory-proofs` +| `open` + +| Lean leg +| Lean 4.15.0 release tarball, sha256 `af71a2569a9f68337de2434829b3008cd8e32c436e9cb6bd8c84a2c2ba3585c9` (verified before unpacking) +| GitHub release download, `zig-ci.yml`, job `theory-proofs` +| `open` +|=== -== Changelog +Each deviation closes when the provers are reachable through `build/guix.scm` or the +container and CI installs them from there. -[cols="1,3,1", options="header"] -|=== -| Date | Change | By +== Template proof files -| 2026-04-04 | Initial proof status tracking | Template -|=== +The template ships example proofs under `verification/proofs/`: `agda/Properties.agda`, +`coq/TypeSafety.v`, `lean4/ApiTypes.lean`, `idris2/` and `tlaplus/`. They are not +zig-dnssec obligations and have no ledger rows. `scripts/check-proofs.sh` still checks +them against their MANIFEST entries, so a change in their state shows up. + +== Checking + +[source,bash] +---- +idris2 --typecheck src/interface/abi.ipkg # engineering proofs +just abi-e2e # Idris2 -> C ABI -> Zig +scripts/theory-receipts.sh # theory: Agda, Rocq, Lean, with receipts +scripts/check-proofs.sh agda # every MANIFEST entry, per prover +scripts/check-proofs.sh coq +scripts/check-proofs.sh lean4 +---- diff --git a/docs/status/ROADMAP.adoc b/docs/status/ROADMAP.adoc index 7f05ed3e..7bb7a39f 100644 --- a/docs/status/ROADMAP.adoc +++ b/docs/status/ROADMAP.adoc @@ -28,6 +28,21 @@ ABI seam) are complete and tested, and have *not* been independently reviewed. S * [x] Tests keeping header, Zig and Idris2 in step; C-ABI behaviour tests * [x] Idris2 -> C ABI -> Zig end-to-end test, in CI +== Milestone 3 — proofs to the estate policy (done, 2026-11-09) + +* [x] Chain-of-trust soundness as theory: `secure` and `insecure` only from a fully + verified chain from the anchor, everything else `bogus`. Agda source of truth, + re-proved in Rocq and Lean, statement correspondence recorded: PWG-2ii + (`verification/proofs/`) +* [x] Idris2 ABI model: exact code decoding, proved by evaluation over all 256 byte + values; the wrapper refuses a mismatched ABI version and an oversized text length +* [x] Proof ledger (`EXPLAINME.adoc#proof-ledger`), proof-status file with receipts and + toolchain deviations, and a `theory-proofs` CI job writing per-commit receipts +* [x] `scripts/check-proofs.sh` uses the canonical Agda invocation. The template's + `agda/Properties.agda` is quarantined (it needs agda-stdlib, which is not pinned + here), and its `lean4/ApiTypes.lean` is promoted to gated (it compiles on + Lean 4.15.0) + == Next . *Independent review* of the validator, the proof logic, the parsers and the DoH @@ -42,9 +57,10 @@ ABI seam) are complete and tested, and have *not* been independently reviewed. S Zig-library archetype so `build.zig` and `build.zig.zon` are expected at the root. . A live transport for Idris2 callers: a DNS-over-HTTPS entry point in the C ABI, or an Idris2 callback for `zig_dnssec_validate`. -. A model of the validator's decision procedure in which "secure" can only be built - from verified signatures up to an anchor (`docs/reports/VERIFICATION.adoc`, estate - note). +. The remaining proof needs, in `docs/status/PROOF-NEEDS.adoc`: model to code for the + validator (N1), then the closest-anchor rule (N2), NSEC/NSEC3 denial (N3) and validity + windows (N4) as theory. Estate work that applies is tracked in + `hyperpolymath/zig-dnssec`#9. == Later diff --git a/scripts/check-proofs.sh b/scripts/check-proofs.sh index c06d0862..5eba30f3 100755 --- a/scripts/check-proofs.sh +++ b/scripts/check-proofs.sh @@ -82,7 +82,7 @@ check_one() { case "$PROVER" in idris2) out="$(cd "$ROOT/$root" && idris2 --check "$rel" 2>&1)"; rc=$? ;; lean4) out="$(cd "$ROOT/$root" && lean "$rel" 2>&1)"; rc=$? ;; - agda) out="$(cd "$ROOT/$root" && agda --safe "$rel" 2>&1)"; rc=$? ;; + agda) out="$(cd "$ROOT/$root" && agda --safe --without-K --cubical-compatible "$rel" 2>&1)"; rc=$? ;; coq) out="$(cd "$ROOT/$root" && coqc "$rel" 2>&1)"; rc=$? ;; esac set -e diff --git a/scripts/theory-receipts.sh b/scripts/theory-receipts.sh new file mode 100755 index 00000000..4471ad88 --- /dev/null +++ b/scripts/theory-receipts.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# +# theory-receipts.sh [OUT] +# +# Checks the chain-of-trust theorems in all three provers and writes one proof +# receipt per leg, as PROOF-POLICY §8.2 (PWG-1) describes. Each receipt holds: +# - the checker and its version, and the invocation; +# - a SHA-256 digest of the input file; +# - the observed result, and the axioms the checker reports (§8.4); +# - the source repository and its full 40-character commit. +# +# Receipts are written to OUT (default: theory-receipts.jsonl), one JSON record +# per line, keys sorted and no whitespace (jq -cS), per the estate JSON policy. +# +# Fails closed. The script exits 1 if any of these happens: +# - a checker is missing; +# - a leg does not compile; +# - Agda's comment-aware postulate scan finds a postulate; +# - Rocq's `Print Assumptions` reports anything but "Closed under the global +# context" for each of the four theorems; +# - Lean's `#print axioms` reports anything but "does not depend on any +# axioms" for each of the four theorems. +# A missing tool is a failure, never a skip. + +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +OUT="${1:-theory-receipts.jsonl}" +: >"$OUT" +COMMIT="$(git rev-parse HEAD)" +REPO="hyperpolymath/zig-dnssec" +THEOREMS=4 +fail=0 + +need() { command -v "$1" >/dev/null 2>&1 || { echo "FAIL: $1 not on PATH" >&2; exit 1; }; } +need agda; need coqc; need lean; need jq; need sha256sum + +receipt() { + # $1 leg, $2 checker, $3 version, $4 invocation, $5 input, $6 result, $7 axioms (JSON array) + jq -cnS --arg leg "$1" --arg checker "$2" --arg version "$3" --arg invocation "$4" \ + --arg input "$5" --arg digest "sha256:$(sha256sum "$5" | cut -d' ' -f1)" \ + --arg result "$6" --argjson axioms "$7" --arg repo "$REPO" --arg commit "$COMMIT" \ + '{leg:$leg, checker:$checker, version:$version, invocation:$invocation, + input:$input, input_digest:$digest, result:$result, axioms:$axioms, + repo:$repo, commit:$commit}' >>"$OUT" +} + +# --- Agda (source of truth) ---------------------------------------------------- +AGDA_IN=verification/proofs/agda/ChainOfTrust.agda +AGDA_CMD="agda --safe --without-K --cubical-compatible ChainOfTrust.agda" +# Comment-aware postulate scan of the import cone (this one file: it imports +# nothing). Agda block comments {- -} nest (pragmas {-# #-} use the same +# delimiters), so they are removed with a depth counter, then -- line comments +# outside them. +strip_agda_comments() { + awk '{ + line = $0; out = ""; i = 1; n = length(line) + while (i <= n) { + two = substr(line, i, 2) + if (two == "{-") { depth++; i += 2; continue } + if (depth > 0 && two == "-}") { depth--; i += 2; continue } + if (depth == 0 && two == "--") break + if (depth == 0) out = out substr(line, i, 1) + i++ + } + print out + }' "$1" +} +postulates="$(strip_agda_comments "$AGDA_IN" | grep -cE '(^|[[:space:]])postulate([[:space:]]|$)' || true)" +if (cd verification/proofs/agda && $AGDA_CMD >/dev/null 2>&1) && [ "$postulates" = 0 ]; then + receipt agda agda "$(agda --version | head -1)" "$AGDA_CMD" "$AGDA_IN" proven '[]' + echo "agda: PROVEN (postulates: 0, import cone: $AGDA_IN only)" +else + receipt agda agda "$(agda --version | head -1)" "$AGDA_CMD" "$AGDA_IN" failed '[]' + echo "agda: FAILED (postulates: $postulates)" >&2; fail=1 +fi + +# --- Rocq leg -------------------------------------------------------------------- +COQ_IN=verification/proofs/coq/ChainOfTrust.v +if out="$(cd verification/proofs/coq && coqc ChainOfTrust.v 2>&1)"; then + closed="$(grep -c '^Closed under the global context$' <<<"$out" || true)" + other="$(grep -v '^Closed under the global context$' <<<"$out" | grep -c . || true)" + if [ "$closed" = "$THEOREMS" ] && [ "$other" = 0 ]; then + receipt rocq coqc "$(coqc --version | head -1)" "coqc ChainOfTrust.v" "$COQ_IN" proven '[]' + echo "rocq: PROVEN (Print Assumptions: closed x$closed)" + else + receipt rocq coqc "$(coqc --version | head -1)" "coqc ChainOfTrust.v" "$COQ_IN" axioms "$(jq -cn --arg o "$out" '[$o]')" + echo "rocq: AXIOMS REPORTED" >&2; echo "$out" >&2; fail=1 + fi +else + receipt rocq coqc "$(coqc --version | head -1)" "coqc ChainOfTrust.v" "$COQ_IN" failed '[]' + echo "rocq: FAILED" >&2; echo "$out" >&2; fail=1 +fi +rm -f verification/proofs/coq/ChainOfTrust.{vo,vok,vos,glob} verification/proofs/coq/.ChainOfTrust.aux + +# --- Lean leg -------------------------------------------------------------------- +LEAN_IN=verification/proofs/lean4/ChainOfTrust.lean +if out="$(cd verification/proofs/lean4 && lean ChainOfTrust.lean 2>&1)"; then + clean="$(grep -c "does not depend on any axioms$" <<<"$out" || true)" + other="$(grep -v "does not depend on any axioms$" <<<"$out" | grep -c . || true)" + if [ "$clean" = "$THEOREMS" ] && [ "$other" = 0 ]; then + receipt lean lean "$(lean --version | head -1)" "lean ChainOfTrust.lean" "$LEAN_IN" proven '[]' + echo "lean: PROVEN (#print axioms: none x$clean)" + else + receipt lean lean "$(lean --version | head -1)" "lean ChainOfTrust.lean" "$LEAN_IN" axioms "$(jq -cn --arg o "$out" '[$o]')" + echo "lean: AXIOMS REPORTED" >&2; echo "$out" >&2; fail=1 + fi +else + receipt lean lean "$(lean --version | head -1)" "lean ChainOfTrust.lean" "$LEAN_IN" failed '[]' + echo "lean: FAILED" >&2; echo "$out" >&2; fail=1 +fi + +echo "receipts: $OUT ($(wc -l <"$OUT") legs, commit $COMMIT)" +exit "$fail" diff --git a/src/interface/Abi/Foreign.idr b/src/interface/Abi/Foreign.idr index b160123b..aafbc336 100644 --- a/src/interface/Abi/Foreign.idr +++ b/src/interface/Abi/Foreign.idr @@ -173,7 +173,14 @@ validateTrace trace anchors qname qtype now policy = do st <- call out text cap case statusFromCode st of Nothing => pure (Left (BrokenContract ("status code " ++ show st))) - Just Ok => decodeVerdict out (\n => getString text 0 (cast n)) + Just Ok => do + -- The library reports how much text it wrote; a library that claims + -- more than the buffer holds (text and its NUL) is broken, and its + -- length is not used to read past the buffer. + tlen <- getBits32 out (off 8 "text_len") + if cast tlen >= cap + then pure (Left (BrokenContract ("text_len " ++ show tlen ++ " does not fit the " ++ show cap ++ "-byte text buffer"))) + else decodeVerdict out (\n => getString text 0 (cast n)) Just BufferTooSmall => case retries of S k => do need <- getBits32 out (off 8 "text_len") diff --git a/src/interface/Abi/Types.idr b/src/interface/Abi/Types.idr index ed92aef0..ca61b42c 100644 --- a/src/interface/Abi/Types.idr +++ b/src/interface/Abi/Types.idr @@ -329,3 +329,59 @@ policyBitsDisjoint = (Refl, Refl, Refl) public export policyWord : List PolicyFlag -> Bits32 policyWord = foldr (\f, acc => prim__or_Bits32 (policyBit f) acc) 0 + +-------------------------------------------------------------------------------- +-- Exact decoding +-------------------------------------------------------------------------------- + +-- The round trips above say decoding an encoded constructor gives it back. +-- They do not rule out a decoder that also accepts a code no constructor +-- encodes to (say `securityFromCode 9 = Just Secure`), which would read a +-- corrupted verdict as SECURE. The converse closes that: every code the +-- decoder accepts is the code of the constructor it returns. +-- +-- For the byte-wide codes the domain has 256 values, so the converse is proved +-- by evaluating it at every one of them: the type checker computes the check +-- for each byte and the proof is Refl. Its trust base is the type checker and +-- Idris2's primitive Bits8 equality, as for any proof by evaluation. + +||| `dec` accepts `c` only if `enc` of the result is `c`. +public export +decodesExactly : (Bits8 -> Maybe a) -> (a -> Bits8) -> Bits8 -> Bool +decodesExactly dec enc c = case dec c of + Nothing => True + Just x => enc x == c + +||| Every byte, 255 down to 0. +public export +allBytes : List Bits8 +allBytes = go 255 + where + go : Nat -> List Bits8 + go Z = [0] + go (S k) = cast (S k) :: go k + +||| `allBytes` really is all 256 of them. +export +allBytesCount : length Abi.Types.allBytes = 256 +allBytesCount = Refl + +||| No byte decodes to a Security other than the one that encodes to it. +export +securityDecodeExact : all (decodesExactly Abi.Types.securityFromCode Abi.Types.securityCode) Abi.Types.allBytes = True +securityDecodeExact = Refl + +||| No byte decodes to a Reason other than the one that encodes to it. +export +reasonDecodeExact : all (decodesExactly Abi.Types.reasonFromCode Abi.Types.reasonCode) Abi.Types.allBytes = True +reasonDecodeExact = Refl + +||| Over status codes 0 to 255, no code decodes to a Status other than the one +||| that encodes to it. A proof by evaluation cannot range over all of `Int`: +||| codes outside 0..255 reach `statusFromCode`'s catch-all clause, which +||| returns Nothing. That part is argued from the definition, not proved here. +export +statusDecodeExact : all (\c => case Abi.Types.statusFromCode (cast c) of + Nothing => True + Just s => Abi.Types.statusCode s == cast c) Abi.Types.allBytes = True +statusDecodeExact = Refl diff --git a/verification/proofs/CORRESPONDENCE.adoc b/verification/proofs/CORRESPONDENCE.adoc new file mode 100644 index 00000000..07ac11b4 --- /dev/null +++ b/verification/proofs/CORRESPONDENCE.adoc @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell += Chain-of-trust theory: statement correspondence +:toc: + +This is the PROOF-POLICY §2.2 record for the chain-of-trust theorems. It ties +the Agda source of truth to its two recheck legs, item by item: + +* Agda: `verification/proofs/agda/ChainOfTrust.agda` +* Rocq: `verification/proofs/coq/ChainOfTrust.v` +* Lean: `verification/proofs/lean4/ChainOfTrust.lean` + +Both legs are *re-proved*: each prover's proof was written by hand, and no +translator is involved. A re-proof was used rather than a Dedukti transport +because no Agda→Dedukti→Rocq/Lean toolchain is pinned in this repository, +in its CI, or in the session that wrote the proofs. §2 also has the Lean leg +re-proved until a released Lambdapi Lean exporter is pinned. Whether one now +exists was not checked here. + +The comparison below was made by reading the three files side by side. Every +definition and every theorem statement is listed, together with each +difference and why it does not change what is claimed. + +== What the theorems claim + +For any types `Key`, `Data` and `Sig`, any signature check +`verify : Key → Data → Sig → Bool`, and any encoding `keyData : Key → Data` +of a key as signed data, the procedure `validate` makes these four claims +about the chain from a trust anchor's key `k`: + +[cols="1,3",options="header"] +|=== +| Theorem | Statement + +| `secure-sound` / `secure_sound` +| `validate k ls l = secure` implies `Verified k ls l` and `l` is an answer. + +| `insecure-sound` / `insecure_sound` +| `validate k ls l = insecure` implies `Verified k ls l` and `l` is a denial. + +| `complete` +| `Verified k ls l` implies `validate k ls l = earned l`. + +| `fail-closed` / `fail_closed` +| `¬ Verified k ls l` implies `validate k ls l = bogus`. +|=== + +`Verified k ls l` means: each `delegate c s` link verifies under the key +above it (`verify k (keyData c) s = true`), and the leaf verifies under the +last key. + +== Definition by definition + +[cols="2,3,3,3",options="header"] +|=== +| Item | Agda | Rocq | Lean + +| Verdicts +| `data Verdict = secure \| insecure \| bogus` +| `Inductive verdict := secure \| insecure \| bogus` +| `inductive Verdict \| secure \| insecure \| bogus` + +| `check` +| `check true v = v`; `check false _ = bogus` +| same, by `match` +| same, by pattern matching + +| Model parameters +| module parameters `Key Data Sig : Set`, `verify`, `keyData` +| section `Variables Key Data Sig : Type`, `verify`, `keyData` +| `variable {Key Data Sig : Type}`, `verify`, `keyData` + +| `Link` +| `delegate : Key → Sig → Link` +| `delegate : Key -> Sig -> link` +| `Link Key Sig`, `delegate : Key → Sig → Link Key Sig` + +| `Leaf` +| `answer`, `denial : Data → Sig → Leaf` +| same +| `Leaf Data Sig` with the same two constructors + +| `validate` +| three clauses: empty chain with an answer leaf, empty chain with a denial leaf, `delegate` link +| the same three cases, by `Fixpoint` on the list +| the same three clauses + +| `LeafVerified`, `Verified` +| inductive families in `Set` +| inductive predicates in `Prop` +| inductive predicates in `Prop` + +| `IsAnswer`, `IsDenial`, `earned` +| as listed above +| same +| same + +| Conjunction, negation, equality +| local `_×_` (record), `¬ A = A → ⊥`, local `_≡_` (indexed `data`, `--without-K`) +| `/\`, `~` (`-> False`), `eq` +| `∧`, `¬` (`→ False`), `Eq` +|=== + +== Differences, and why they do not change the claim + +* *Universes.* Agda quantifies over `Set` (`Set₀`), Lean over `Type` (`Type 0`), and + Rocq over a section `Type` whose universe Rocq fixes at use. The theorems + quantify uniformly over these types and never inspect them, so each + statement holds at every level the prover allows. No theorem depends on + impredicativity: Rocq's and Lean's `Prop` is used only for the predicates + and connectives, and their proof terms are ordinary inductive constructions. +* *Proof relevance.* Agda's `Verified` lives in `Set`, so a proof is data; + Rocq's and Lean's live in `Prop`. The theorems state existence of a + derivation (soundness) and an equality of verdicts (completeness, fail-closed), + so this does not change what is claimed. +* *Equality.* Agda's `_≡_` is defined locally and used under `--without-K`; + no proof uses UIP or K. Rocq's `eq` and Lean's `Eq` are their kernels' + built-in equality. Every equality in the statements is between + constructors of `Verdict` or `Bool`, which are decidable, so the three + readings agree. +* *Implicit arguments.* Lean makes `Key`, `Data` and `Sig` implicit and + passes `verify` and `keyData` explicitly to `validate`, `Verified` and the + theorems. Agda and Rocq bind them once for the module or section. The + bound variables are the same; only their syntax differs. + +== Residual assumptions + +* *The cryptography.* `verify` is arbitrary. Each theorem holds for every + signature check, so the theorems say only that the verdict reflects + `verify`'s answers. That a `true` from `verify` means a holder of the key + signed the data (unforgeability) is a cryptographic assumption about the + algorithms, outside all three proofs. +* *The model.* The chain is a list of single-key delegations. DS/DNSKEY + splitting, key sets, closest-anchor selection, NSEC/NSEC3 semantics, + wildcards and validity windows are outside the model. Each is its own row in + `docs/status/PROOF-STATUS.adoc`. +* *The code.* Nothing here proves that `src/dnssec/validator.zig` follows + `validate`. That link is a separate `argued` row in the proof-status file. + +== Correspondence states (§2.2) + +[cols="2,1,1,2",options="header"] +|=== +| Leg | Route | §5 token | §2.2 state + +| Agda (source) +| - +| `PROVEN` +| `AGDA-VERIFIED` + +| Rocq +| `re-proved` +| `PROVEN` +| `RECONCILED`, by the reading above + +| Lean +| `re-proved` +| `PROVEN` +| `RECONCILED`, by the reading above +|=== + +== Checking + +[source,shell] +---- +agda --safe --without-K --cubical-compatible verification/proofs/agda/ChainOfTrust.agda +(cd verification/proofs/coq && coqc ChainOfTrust.v) # prints Print Assumptions +(cd verification/proofs/lean4 && lean ChainOfTrust.lean) # prints #print axioms +---- + +The versions, digests and observed results of each run are kept as receipts +in `docs/status/PROOF-STATUS.adoc`. The `theory-proofs` CI job writes fresh +receipts on every commit. diff --git a/verification/proofs/agda/ChainOfTrust.agda b/verification/proofs/agda/ChainOfTrust.agda new file mode 100644 index 00000000..665858f5 --- /dev/null +++ b/verification/proofs/agda/ChainOfTrust.agda @@ -0,0 +1,185 @@ +{-# OPTIONS --safe --without-K --cubical-compatible #-} +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- Chain-of-trust soundness for a DNSSEC validator, as theory. +-- +-- The statement is about the decision procedure, not about zig-dnssec's +-- code: it holds for any validator that walks a chain of signed keys down +-- from a trust anchor and decides on the last link the way `validate` does. +-- That makes it theory under PROOF-POLICY §1, so Agda is its source of truth +-- and it is re-proved in Rocq (verification/proofs/coq/ChainOfTrust.v) and in +-- Lean (verification/proofs/lean4/ChainOfTrust.lean). How the three +-- statements correspond is recorded in verification/proofs/CORRESPONDENCE.adoc. +-- +-- The module is self-contained: no standard library, no postulates, so its +-- import cone is this file and Agda's primitives. The cryptography is a +-- module parameter, not an assumption smuggled in: `verify` is whatever the +-- signature check is, and every theorem below holds for every `verify`. +-- +-- What the theorems say, in words: +-- +-- secure-sound A `secure` verdict means every key on the path from the +-- anchor was signed by the key above it, and the answer was +-- signed by the last key. +-- insecure-sound An `insecure` verdict means the same chain, ending in a +-- *verified* proof that the next delegation is unsigned. +-- complete A fully verified chain is accepted: `secure` for an +-- answer, `insecure` for a denial. +-- fail-closed A chain that is not fully verified is `bogus`: a failure +-- can never come out as `secure` or `insecure`. +-- +-- Not in this model (each is a separate row in docs/status/PROOF-STATUS.adoc): +-- choosing the closest trust anchor, NSEC/NSEC3 denial semantics, wildcard +-- expansion, validity windows, and that zig-dnssec's validator.zig follows +-- this procedure. + +module ChainOfTrust where + +------------------------------------------------------------------------------ +-- Prelude: just what the theorems need. + +data Bool : Set where + false true : Bool + +data _≡_ {A : Set} (x : A) : A → Set where + refl : x ≡ x + +infix 4 _≡_ + +trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z +trans refl q = q + +data ⊥ : Set where + +⊥-elim : {A : Set} → ⊥ → A +⊥-elim () + +¬_ : Set → Set +¬ A = A → ⊥ + +data List (A : Set) : Set where + [] : List A + _∷_ : A → List A → List A + +infixr 5 _∷_ + +record _×_ (A B : Set) : Set where + constructor _,_ + field + fst : A + snd : B + +open _×_ + +------------------------------------------------------------------------------ +-- Verdicts + +data Verdict : Set where + secure insecure bogus : Verdict + +-- A step that passed keeps the verdict computed below it; a step that failed +-- is bogus, whatever is below it. +check : Bool → Verdict → Verdict +check true v = v +check false _ = bogus + +------------------------------------------------------------------------------ +-- The model, for any keys, signed data, signatures and signature check. + +module Model + (Key Data Sig : Set) + (verify : Key → Data → Sig → Bool) -- the signature check + (keyData : Key → Data) -- a key as data another key signs + where + + -- One delegation step: the current key signs the child zone's key. + data Link : Set where + delegate : Key → Sig → Link + + -- What the last key signs: the answer, or a proof that the next delegation + -- is unsigned. + data Leaf : Set where + answer : Data → Sig → Leaf + denial : Data → Sig → Leaf + + -- The decision procedure, started from a trust anchor's key. + validate : Key → List Link → Leaf → Verdict + validate k [] (answer d s) = check (verify k d s) secure + validate k [] (denial d s) = check (verify k d s) insecure + validate k (delegate c s ∷ ls) l = check (verify k (keyData c) s) (validate c ls l) + + -- What a fully verified chain is: every signature on the path checks. + data LeafVerified (k : Key) : Leaf → Set where + answer-ok : {d : Data} {s : Sig} → verify k d s ≡ true → LeafVerified k (answer d s) + denial-ok : {d : Data} {s : Sig} → verify k d s ≡ true → LeafVerified k (denial d s) + + data Verified : Key → List Link → Leaf → Set where + here : {k : Key} {l : Leaf} → LeafVerified k l → Verified k [] l + step : {k c : Key} {s : Sig} {ls : List Link} {l : Leaf} → + verify k (keyData c) s ≡ true → Verified c ls l → + Verified k (delegate c s ∷ ls) l + + data IsAnswer : Leaf → Set where + is-answer : {d : Data} {s : Sig} → IsAnswer (answer d s) + + data IsDenial : Leaf → Set where + is-denial : {d : Data} {s : Sig} → IsDenial (denial d s) + + -- The verdict a fully verified chain earns. + earned : Leaf → Verdict + earned (answer _ _) = secure + earned (denial _ _) = insecure + + ---------------------------------------------------------------------------- + -- Lemmas about `check` + + check-secure : (b : Bool) (v : Verdict) → check b v ≡ secure → (b ≡ true) × (v ≡ secure) + check-secure true v p = refl , p + check-secure false v () + + check-insecure : (b : Bool) (v : Verdict) → check b v ≡ insecure → (b ≡ true) × (v ≡ insecure) + check-insecure true v p = refl , p + check-insecure false v () + + check-pass : {b : Bool} (v : Verdict) → b ≡ true → check b v ≡ v + check-pass v refl = refl + + ---------------------------------------------------------------------------- + -- Theorems + + secure-sound : (k : Key) (ls : List Link) (l : Leaf) → + validate k ls l ≡ secure → Verified k ls l × IsAnswer l + secure-sound k [] (answer d s) p = here (answer-ok (fst (check-secure (verify k d s) secure p))) , is-answer + secure-sound k [] (denial d s) p with snd (check-secure (verify k d s) insecure p) + ... | () + secure-sound k (delegate c s ∷ ls) l p = + let r = check-secure (verify k (keyData c) s) (validate c ls l) p + rest = secure-sound c ls l (snd r) + in step (fst r) (fst rest) , snd rest + + insecure-sound : (k : Key) (ls : List Link) (l : Leaf) → + validate k ls l ≡ insecure → Verified k ls l × IsDenial l + insecure-sound k [] (answer d s) p with snd (check-insecure (verify k d s) secure p) + ... | () + insecure-sound k [] (denial d s) p = here (denial-ok (fst (check-insecure (verify k d s) insecure p))) , is-denial + insecure-sound k (delegate c s ∷ ls) l p = + let r = check-insecure (verify k (keyData c) s) (validate c ls l) p + rest = insecure-sound c ls l (snd r) + in step (fst r) (fst rest) , snd rest + + complete : {k : Key} {ls : List Link} {l : Leaf} → + Verified k ls l → validate k ls l ≡ earned l + complete (here (answer-ok p)) = check-pass secure p + complete (here (denial-ok p)) = check-pass insecure p + complete (step {c = c} {ls = ls} {l = l} p rest) = + trans (check-pass (validate c ls l) p) (complete rest) + + fail-closed : (k : Key) (ls : List Link) (l : Leaf) → + ¬ Verified k ls l → validate k ls l ≡ bogus + fail-closed k ls l nv = go (validate k ls l) refl + where + go : (v : Verdict) → validate k ls l ≡ v → validate k ls l ≡ bogus + go secure eq = ⊥-elim (nv (fst (secure-sound k ls l eq))) + go insecure eq = ⊥-elim (nv (fst (insecure-sound k ls l eq))) + go bogus eq = eq diff --git a/verification/proofs/agda/MANIFEST b/verification/proofs/agda/MANIFEST index 2e18dc33..dac49ce1 100644 --- a/verification/proofs/agda/MANIFEST +++ b/verification/proofs/agda/MANIFEST @@ -1,4 +1,5 @@ # Agda proof manifest — read by scripts/check-proofs.sh agda # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with agda (agda --safe). -verification/proofs/agda|Properties.agda|gated| compiles under `agda --safe` +verification/proofs/agda|Properties.agda|quarantine| template example, not a zig-dnssec obligation: imports agda-stdlib (Data.Nat), which this repo does not pin; fails "Failed to find source of module Data.Nat" +verification/proofs/agda|ChainOfTrust.agda|gated| chain-of-trust soundness, theory source of truth (PROOF-POLICY §1, §2.1 invocation) diff --git a/verification/proofs/coq/ChainOfTrust.v b/verification/proofs/coq/ChainOfTrust.v new file mode 100644 index 00000000..7a2c132b --- /dev/null +++ b/verification/proofs/coq/ChainOfTrust.v @@ -0,0 +1,125 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +(* + Chain-of-trust soundness: the Rocq leg (re-proved). + + The source of truth is verification/proofs/agda/ChainOfTrust.agda. This file + restates its definitions and theorems in Rocq and proves them by hand: no + translator is involved, so the route is `re-proved` (PROOF-POLICY §2). The + statement-by-statement comparison with the Agda source is recorded in + verification/proofs/CORRESPONDENCE.adoc. + + Only the Rocq prelude is used: no Require, no Axiom, no Admitted. The final + `Print Assumptions` lines report each theorem's axioms; they must report + "Closed under the global context". + + Check with: coqc ChainOfTrust.v +*) + +Inductive verdict : Type := secure | insecure | bogus. + +Definition check (b : bool) (v : verdict) : verdict := + match b with + | true => v + | false => bogus + end. + +Section Model. + + Variables Key Data Sig : Type. + Variable verify : Key -> Data -> Sig -> bool. + Variable keyData : Key -> Data. + + Inductive link : Type := delegate : Key -> Sig -> link. + + Inductive leaf : Type := + | answer : Data -> Sig -> leaf + | denial : Data -> Sig -> leaf. + + Fixpoint validate (k : Key) (ls : list link) (l : leaf) : verdict := + match ls with + | nil => + match l with + | answer d s => check (verify k d s) secure + | denial d s => check (verify k d s) insecure + end + | cons (delegate c s) rest => check (verify k (keyData c) s) (validate c rest l) + end. + + Inductive leaf_verified (k : Key) : leaf -> Prop := + | answer_ok : forall d s, verify k d s = true -> leaf_verified k (answer d s) + | denial_ok : forall d s, verify k d s = true -> leaf_verified k (denial d s). + + Inductive verified : Key -> list link -> leaf -> Prop := + | here : forall k l, leaf_verified k l -> verified k nil l + | step : forall k c s ls l, + verify k (keyData c) s = true -> verified c ls l -> + verified k (cons (delegate c s) ls) l. + + Inductive is_answer : leaf -> Prop := is_answer_i : forall d s, is_answer (answer d s). + Inductive is_denial : leaf -> Prop := is_denial_i : forall d s, is_denial (denial d s). + + Definition earned (l : leaf) : verdict := + match l with + | answer _ _ => secure + | denial _ _ => insecure + end. + + Lemma check_secure : forall b v, check b v = secure -> b = true /\ v = secure. + Proof. intros [|] v H; simpl in H; [ split; [reflexivity | exact H] | discriminate H ]. Qed. + + Lemma check_insecure : forall b v, check b v = insecure -> b = true /\ v = insecure. + Proof. intros [|] v H; simpl in H; [ split; [reflexivity | exact H] | discriminate H ]. Qed. + + Lemma check_pass : forall b v, b = true -> check b v = v. + Proof. intros b v H; rewrite H; reflexivity. Qed. + + Theorem secure_sound : forall k ls l, + validate k ls l = secure -> verified k ls l /\ is_answer l. + Proof. + intros k ls; revert k; induction ls as [| [c s] ls IH]; intros k l H. + - destruct l as [d s | d s]; simpl in H. + + destruct (check_secure _ _ H) as [Hv _]. + split; [ apply here, answer_ok; exact Hv | apply is_answer_i ]. + + destruct (check_secure _ _ H) as [_ Hx]. discriminate Hx. + - simpl in H. destruct (check_secure _ _ H) as [Hv Hr]. + destruct (IH c l Hr) as [Hc Ha]. + split; [ apply step; assumption | exact Ha ]. + Qed. + + Theorem insecure_sound : forall k ls l, + validate k ls l = insecure -> verified k ls l /\ is_denial l. + Proof. + intros k ls; revert k; induction ls as [| [c s] ls IH]; intros k l H. + - destruct l as [d s | d s]; simpl in H. + + destruct (check_insecure _ _ H) as [_ Hx]. discriminate Hx. + + destruct (check_insecure _ _ H) as [Hv _]. + split; [ apply here, denial_ok; exact Hv | apply is_denial_i ]. + - simpl in H. destruct (check_insecure _ _ H) as [Hv Hr]. + destruct (IH c l Hr) as [Hc Hd]. + split; [ apply step; assumption | exact Hd ]. + Qed. + + Theorem complete : forall k ls l, verified k ls l -> validate k ls l = earned l. + Proof. + intros k ls l H; induction H as [k l Hl | k c s ls l Hv Hr IH]. + - destruct Hl as [d s Hv | d s Hv]; simpl; apply check_pass; exact Hv. + - simpl. rewrite (check_pass _ _ Hv). exact IH. + Qed. + + Theorem fail_closed : forall k ls l, + ~ verified k ls l -> validate k ls l = bogus. + Proof. + intros k ls l Hn. + destruct (validate k ls l) eqn:E. + - exfalso. apply Hn. exact (proj1 (secure_sound k ls l E)). + - exfalso. apply Hn. exact (proj1 (insecure_sound k ls l E)). + - reflexivity. + Qed. + +End Model. + +Print Assumptions secure_sound. +Print Assumptions insecure_sound. +Print Assumptions complete. +Print Assumptions fail_closed. diff --git a/verification/proofs/coq/MANIFEST b/verification/proofs/coq/MANIFEST index aa71524e..22dc4104 100644 --- a/verification/proofs/coq/MANIFEST +++ b/verification/proofs/coq/MANIFEST @@ -2,3 +2,4 @@ # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with coqc. verification/proofs/coq|TypeSafety.v|gated| compiles under `coqc` +verification/proofs/coq|ChainOfTrust.v|gated| chain-of-trust soundness, Rocq leg (re-proved; see ../CORRESPONDENCE.adoc) diff --git a/verification/proofs/lean4/ChainOfTrust.lean b/verification/proofs/lean4/ChainOfTrust.lean new file mode 100644 index 00000000..81e13b3f --- /dev/null +++ b/verification/proofs/lean4/ChainOfTrust.lean @@ -0,0 +1,118 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +-- +-- Chain-of-trust soundness: the Lean leg (re-proved). +-- +-- The source of truth is verification/proofs/agda/ChainOfTrust.agda. This file +-- restates its definitions and theorems in Lean 4 and proves them by hand. No +-- translator is involved, so the route is `re-proved` (PROOF-POLICY §2). The +-- statement-by-statement comparison with the Agda source is recorded in +-- verification/proofs/CORRESPONDENCE.adoc. +-- +-- Core Lean only: no imports, no Mathlib (PROOF-POLICY §2), no `axiom`, no +-- `sorry`. The `#print axioms` lines at the end must each report that the +-- theorem "does not depend on any axioms". +-- +-- Check with: lean ChainOfTrust.lean (toolchain: ./lean-toolchain) + +namespace ChainOfTrust + +inductive Verdict where + | secure | insecure | bogus + deriving DecidableEq + +def check : Bool → Verdict → Verdict + | true, v => v + | false, _ => .bogus + +section Model + +variable {Key Data Sig : Type} (verify : Key → Data → Sig → Bool) (keyData : Key → Data) + +inductive Link (Key Sig : Type) where + | delegate : Key → Sig → Link Key Sig + +inductive Leaf (Data Sig : Type) where + | answer : Data → Sig → Leaf Data Sig + | denial : Data → Sig → Leaf Data Sig + +def validate : Key → List (Link Key Sig) → Leaf Data Sig → Verdict + | k, [], .answer d s => check (verify k d s) .secure + | k, [], .denial d s => check (verify k d s) .insecure + | k, .delegate c s :: ls, l => check (verify k (keyData c) s) (validate c ls l) + +inductive LeafVerified (k : Key) : Leaf Data Sig → Prop where + | answer_ok {d : Data} {s : Sig} : verify k d s = true → LeafVerified k (.answer d s) + | denial_ok {d : Data} {s : Sig} : verify k d s = true → LeafVerified k (.denial d s) + +inductive Verified : Key → List (Link Key Sig) → Leaf Data Sig → Prop where + | here {k : Key} {l : Leaf Data Sig} : LeafVerified verify k l → Verified k [] l + | step {k c : Key} {s : Sig} {ls : List (Link Key Sig)} {l : Leaf Data Sig} : + verify k (keyData c) s = true → Verified c ls l → Verified k (.delegate c s :: ls) l + +inductive IsAnswer : Leaf Data Sig → Prop where + | is_answer {d : Data} {s : Sig} : IsAnswer (.answer d s) + +inductive IsDenial : Leaf Data Sig → Prop where + | is_denial {d : Data} {s : Sig} : IsDenial (.denial d s) + +def earned : Leaf Data Sig → Verdict + | .answer _ _ => .secure + | .denial _ _ => .insecure + +theorem check_secure : ∀ (b : Bool) (v : Verdict), check b v = .secure → b = true ∧ v = .secure + | true, _, h => ⟨rfl, h⟩ + | false, _, h => nomatch h + +theorem check_insecure : ∀ (b : Bool) (v : Verdict), check b v = .insecure → b = true ∧ v = .insecure + | true, _, h => ⟨rfl, h⟩ + | false, _, h => nomatch h + +theorem check_pass : ∀ {b : Bool} (v : Verdict), b = true → check b v = v + | _, _, rfl => rfl + +theorem secure_sound : ∀ (k : Key) (ls : List (Link Key Sig)) (l : Leaf Data Sig), + validate verify keyData k ls l = .secure → + Verified verify keyData k ls l ∧ IsAnswer l + | k, [], .answer d s, h => + ⟨.here (.answer_ok (check_secure (verify k d s) .secure h).1), .is_answer⟩ + | k, [], .denial d s, h => nomatch (check_secure (verify k d s) .insecure h).2 + | k, .delegate c s :: ls, l, h => + have r := check_secure (verify k (keyData c) s) (validate verify keyData c ls l) h + have rest := secure_sound c ls l r.2 + ⟨.step r.1 rest.1, rest.2⟩ + +theorem insecure_sound : ∀ (k : Key) (ls : List (Link Key Sig)) (l : Leaf Data Sig), + validate verify keyData k ls l = .insecure → + Verified verify keyData k ls l ∧ IsDenial l + | k, [], .answer d s, h => nomatch (check_insecure (verify k d s) .secure h).2 + | k, [], .denial d s, h => + ⟨.here (.denial_ok (check_insecure (verify k d s) .insecure h).1), .is_denial⟩ + | k, .delegate c s :: ls, l, h => + have r := check_insecure (verify k (keyData c) s) (validate verify keyData c ls l) h + have rest := insecure_sound c ls l r.2 + ⟨.step r.1 rest.1, rest.2⟩ + +theorem complete : ∀ {k : Key} {ls : List (Link Key Sig)} {l : Leaf Data Sig}, + Verified verify keyData k ls l → validate verify keyData k ls l = earned l + | _, _, _, .here (.answer_ok p) => check_pass .secure p + | _, _, _, .here (.denial_ok p) => check_pass .insecure p + | _, _, _, .step (c := c) (ls := ls) (l := l) p rest => + (check_pass (validate verify keyData c ls l) p).trans (complete rest) + +theorem fail_closed : ∀ (k : Key) (ls : List (Link Key Sig)) (l : Leaf Data Sig), + ¬ Verified verify keyData k ls l → validate verify keyData k ls l = .bogus := by + intro k ls l hn + cases e : validate verify keyData k ls l with + | secure => exact absurd (secure_sound verify keyData k ls l e).1 hn + | insecure => exact absurd (insecure_sound verify keyData k ls l e).1 hn + | bogus => rfl + +end Model + +end ChainOfTrust + +#print axioms ChainOfTrust.secure_sound +#print axioms ChainOfTrust.insecure_sound +#print axioms ChainOfTrust.complete +#print axioms ChainOfTrust.fail_closed diff --git a/verification/proofs/lean4/MANIFEST b/verification/proofs/lean4/MANIFEST index 0f3adc27..2279311a 100644 --- a/verification/proofs/lean4/MANIFEST +++ b/verification/proofs/lean4/MANIFEST @@ -1,4 +1,5 @@ # Lean4 proof manifest — read by scripts/check-proofs.sh lean4 # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with Lean leanprover/lean4:v4.15.0 (via elan). -verification/proofs/lean4|ApiTypes.lean|quarantine| ApiTypes.lean:44 `Nat.zero_le max` application type mismatch — `max` used where Nat is expected; has never compiled +verification/proofs/lean4|ApiTypes.lean|gated| template example, not a zig-dnssec obligation; compiles on Lean 4.15.0 (lean-toolchain), so promoted from quarantine +verification/proofs/lean4|ChainOfTrust.lean|gated| chain-of-trust soundness, Lean leg (re-proved; see ../CORRESPONDENCE.adoc) diff --git a/zig-dnssec_chora.deed b/zig-dnssec_chora.deed index a9aeb880..b917d4b6 100644 --- a/zig-dnssec_chora.deed +++ b/zig-dnssec_chora.deed @@ -30,9 +30,9 @@ ; equal canon.lock [canon.artifacts]; canon.lock [canon.lockstep].order is ; spine-adopts-then-canon-releases, so this clause moves FIRST. (canon - :version "2.1.3" + :version "2.1.5" :criteria-sha256 "6a5aa8857bd0d0d58ef48827938ca17c251b6b854dacf59d306388d61694d82a" - :gates-sha256 "2f31f46d4753432e0aa8c9c28f339e18e062c98dc6e6ef4ecbb76993cf37638b" + :gates-sha256 "5c510bba025be718deebb12d0333bfe7db2da43c66578b728b1a334df65290b1" :lockstep-since "2026-09-17" ; A canon change this repo cannot satisfy is a change made in the WRONG ; ORDER, not a rejected change: land the spine's adoption first, then the @@ -1085,6 +1085,7 @@ (paths :added ( ".github/workflows/zig-ci.yml" + "EXPLAINME.adoc" "build.zig" "build.zig.zon" "docs/architecture.adoc" @@ -1095,6 +1096,7 @@ "docs/reports/VERIFICATION.adoc" "docs/troubleshooting.adoc" "docs/usage.adoc" + "scripts/theory-receipts.sh" "src/cli/" "src/dnssec/" "src/interface/E2e/" @@ -1113,7 +1115,11 @@ "tests/fuzz_validator.zig" "tests/replay.zig" "tests/testdata/" - "tests/vectors.zig") + "tests/vectors.zig" + "verification/proofs/CORRESPONDENCE.adoc" + "verification/proofs/agda/ChainOfTrust.agda" + "verification/proofs/coq/ChainOfTrust.v" + "verification/proofs/lean4/ChainOfTrust.lean") :removed ( ".github/workflows/rust-ci.yml" ".machine_readable/ai/PLACEHOLDERS.adoc" @@ -1215,6 +1221,7 @@ "mise.lock" "scripts/campaigns/www-bundle.campaign" "scripts/check-no-placeholders.sh" + "scripts/check-proofs.sh" "scripts/validate-template.sh" "src/README.adoc" "src/interface/Abi/Foreign.idr" @@ -1230,6 +1237,9 @@ "tests/e2e.sh" "tests/e2e/template_instantiation_test.sh" "tests/fuzz/README.adoc" + "verification/proofs/agda/MANIFEST" + "verification/proofs/coq/MANIFEST" + "verification/proofs/lean4/MANIFEST" "www/.well-known/aibdp.json" "www/.well-known/humans.txt" "www/.well-known/security.txt"