aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-closure / README.md
| 1 | # aien-closure (`verify-closure`) |
| 2 | |
| 3 | Verified Crumb, stage 5. This is a CI bridge: it makes today's Rust and C |
| 4 | code obey the rule "every internal dependency has verified evidence" before |
| 5 | Omega's compiler owns dependency resolution. When Omega's `import` resolves |
| 6 | dependencies through the verified library, this tool is retired or reduced to |
| 7 | a cross-check. |
| 8 | |
| 9 | It reuses aien-proof for the receipt format. Receipt identity is |
| 10 | `aien_proof::evidence::receipt_id` (BLAKE3 over the canonical encoding), and |
| 11 | chains are checked with `aien_proof::chain::verify_chain`. Nothing here |
| 12 | re-implements the hash. |
| 13 | |
| 14 | ## What it checks |
| 15 | |
| 16 | `verify-closure --root <repo> [--store <receipt dir>] [--write-lock]` |
| 17 | |
| 18 | 1. Rebuild the internal graph with `cargo metadata --offline --locked |
| 19 | --no-deps`. Edges are path dependencies between workspace members (normal |
| 20 | and build kinds; dev dependencies are not part of the built artifact). |
| 21 | 2. Read `closure.toml` from each crate directory that has one. |
| 22 | 3. Every edge must be declared in the manifest and pinned to the receipt id of |
| 23 | the dependency, which must itself have a manifest with that receipt. |
| 24 | 4. Each component receipt must exist in `<store>/receipts/<id>.json`, hash to |
| 25 | its id, and the whole receipt chain must verify as PASS. |
| 26 | 5. The receipt must have been taken at the source digest the manifest records, |
| 27 | and the current source must still have that digest. |
| 28 | 6. No cycles. No dirty or TEST_ONLY_TRUST receipts anywhere in the chain. |
| 29 | 7. `closure.lock` must equal the closure rebuilt from the manifests. |
| 30 | |
| 31 | If no manifest exists at all, the run fails (UNVERIFIED_DEPENDENCY). The store |
| 32 | defaults to `$AIEN_PROOF_DIR`, else `~/.local/state/aien-proof`. |
| 33 | |
| 34 | ## The nine codes |
| 35 | |
| 36 | Output is one line per finding, `FINDING <CODE> component=<name> detail=<text>`, |
| 37 | then `SUMMARY status=<PASS|FAIL> findings=<n> components=<n>`. Exit code is 0 |
| 38 | on PASS, 1 on an internal error, 2 on a usage error, and otherwise the code of |
| 39 | the first finding (sorted by the order below, then component). |
| 40 | |
| 41 | | Exit | Code | Raised when | |
| 42 | | --- | --- | --- | |
| 43 | | 10 | UNVERIFIED_DEPENDENCY | a dependency has no manifest, a manifest is malformed, a declared dep is not a real edge, `closure.lock` pins a dependency the component does not have, the chain does not verify as PASS, the receipt tier is below the profile, or no manifest exists | |
| 44 | | 11 | MISSING_RECEIPT | a receipt id (component or any chain member) is not in the store | |
| 45 | | 12 | RECEIPT_HASH_MISMATCH | a receipt file does not hash to its id, or is not a valid receipt | |
| 46 | | 13 | DEPENDENCY_NOT_PINNED | a dep has no receipt pin, the pin differs from the dep's receipt, the receipt does not depend on the pinned receipt, or `closure.lock` is missing or has a missing or wrong line | |
| 47 | | 14 | DEPENDENCY_CYCLE | the internal graph or the receipt graph has a cycle | |
| 48 | | 15 | STALE_RECEIPT | current source digest differs from the manifest, or the receipt does not record the manifest's source digest | |
| 49 | | 16 | UNDECLARED_IMPORT | the graph has an edge the manifest does not declare (only this direction; an extra declaration is UNVERIFIED_DEPENDENCY) | |
| 50 | | 17 | TAINTED_ARTIFACT | a receipt in the chain was recorded from a dirty tree or is TEST_ONLY_TRUST | |
| 51 | | 18 | UNKNOWN_VERIFIER_PROFILE | the manifest names a profile this verifier does not know | |
| 52 | |
| 53 | Profiles: `host-v1` needs tier HOST_TEST or better, `qemu-v1` needs QEMU or |
| 54 | better, `production-v1` needs PRODUCTION. Tier comparison is |
| 55 | `aien_proof::chain::tier_satisfies`, so a QEMU receipt never satisfies a |
| 56 | physical requirement. |
| 57 | |
| 58 | ## How a component gets a manifest |
| 59 | |
| 60 | Put a `closure.toml` in the crate directory. Strict, line based, no comments, |
| 61 | no blank lines, no tabs, one trailing newline: |
| 62 | |
| 63 | ```text |
| 64 | closure-manifest v1 |
| 65 | component aien-scheduler |
| 66 | profile host-v1 |
| 67 | receipt <64 hex: receipt id that qualifies this component> |
| 68 | source blake3:<64 hex: source digest the receipt was taken at> |
| 69 | dep aien-kv-cache <64 hex: receipt id of aien-kv-cache> |
| 70 | dep aien-platform <64 hex> |
| 71 | ``` |
| 72 | |
| 73 | Steps: |
| 74 | |
| 75 | 1. Qualify every dependency first (leaves up), each with its own manifest. |
| 76 | 2. Compute the source digest of the crate. It is BLAKE3 over all regular files |
| 77 | in the crate directory in sorted path order, excluding `target`, `.git`, |
| 78 | `closure.toml` and `closure.lock` (see `src/digest.rs` for the exact byte |
| 79 | layout). Symlinks in a crate directory are an error. |
| 80 | 3. Record an aien-proof receipt whose `input_artifacts` contains |
| 81 | `blake3:<source digest>`, whose `dependencies` contain the receipt ids of |
| 82 | the dependencies, and whose result is PASS from a clean tree. |
| 83 | 4. Write the manifest, then run `verify-closure --root . --write-lock` to |
| 84 | produce `closure.lock`, and commit both. |
| 85 | |
| 86 | Any source change makes the receipt stale on purpose. Re-qualify, then update |
| 87 | the manifest. |
| 88 | |
| 89 | ## C components (for Omega, not wired to CI yet) |
| 90 | |
| 91 | `graph::scan_c_includes(src_dir, include_root)` builds a file level graph from |
| 92 | quoted `#include "..."` lines. An include resolves against the including |
| 93 | file's directory, then against `include_root` (the `-I` directory, `src` for |
| 94 | Omega). Unresolved quoted includes are returned, not dropped. Limitation: block |
| 95 | comments and `#if 0` regions are not understood, so a commented out include |
| 96 | still counts, which errs on the strict side. It is unit tested on a fixture |
| 97 | directory only. |
| 98 | |
| 99 | ## Tests |
| 100 | |
| 101 | `cargo test -p aien-closure` seeds a fixture workspace (`tests/fixtures/seeded`) |
| 102 | into a temp directory with receipts built through aien-proof's own API, then |
| 103 | checks one PASS case and at least one failing case per code, each asserting the |
| 104 | exact finding and the binary's exit code. The committed seeded fixture (with |
| 105 | store) is what `.github/workflows/verify-closure.yml` runs against. To rewrite |
| 106 | it: `cargo test -p aien-closure -- --ignored regenerate_committed_fixture`. |
| 107 | |
| 108 | ## One meaning per declaration code |
| 109 | |
| 110 | The meanings follow `aien-protocols` `specs/verified-crumb/SPEC.md` section 6.2 |
| 111 | (contract 0.2.0), implemented in `src/declare.rs`: |
| 112 | |
| 113 | | Situation | Code | |
| 114 | | --- | --- | |
| 115 | | an edge (or import) with no receipt pin, or a pin that is not the dependency's receipt | DEPENDENCY_NOT_PINNED | |
| 116 | | a `closure.lock` line for a dependency the component does not have | UNVERIFIED_DEPENDENCY | |
| 117 | | a declared dep that is not an actual edge | UNVERIFIED_DEPENDENCY | |
| 118 | | an actual edge the manifest does not declare | UNDECLARED_IMPORT | |
| 119 | | a VC's stored source imports a program not in `dependencies[]` (SPEC step 8) | UNDECLARED_IMPORT | |
| 120 | | a `dependencies[]` entry the VC's stored source does not import (SPEC step 8) | UNVERIFIED_DEPENDENCY | |
| 121 | |
| 122 | This crate reads no VCs, so the last two rows are covered by a unit test of the |
| 123 | shared set comparison (`declare::compare`), not by the binary. |
| 124 | `tests/declaration_codes.rs` has one test per row plus a negative twin that |
| 125 | fails if the row's code is swapped for a neighbouring code. |
| 126 | |
| 127 | ## Receipt cross-check fixtures |
| 128 | |
| 129 | `tests/fixtures/receipts/` holds receipts minted with aien-proof for cases the |
| 130 | Omega C reader's three fixtures do not cover. See the README there. |