interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-closure / README.md

130 lines · 6989 bytes Raw Blame History Rendered
1# aien-closure (`verify-closure`)
2
3Verified Crumb, stage 5. This is a CI bridge: it makes today's Rust and C
4code obey the rule "every internal dependency has verified evidence" before
5Omega's compiler owns dependency resolution. When Omega's `import` resolves
6dependencies through the verified library, this tool is retired or reduced to
7a cross-check.
8
9It reuses aien-proof for the receipt format. Receipt identity is
10`aien_proof::evidence::receipt_id` (BLAKE3 over the canonical encoding), and
11chains are checked with `aien_proof::chain::verify_chain`. Nothing here
12re-implements the hash.
13
14## What it checks
15
16`verify-closure --root <repo> [--store <receipt dir>] [--write-lock]`
17
181. 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).
212. Read `closure.toml` from each crate directory that has one.
223. 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.
244. Each component receipt must exist in `<store>/receipts/<id>.json`, hash to
25 its id, and the whole receipt chain must verify as PASS.
265. The receipt must have been taken at the source digest the manifest records,
27 and the current source must still have that digest.
286. No cycles. No dirty or TEST_ONLY_TRUST receipts anywhere in the chain.
297. `closure.lock` must equal the closure rebuilt from the manifests.
30
31If no manifest exists at all, the run fails (UNVERIFIED_DEPENDENCY). The store
32defaults to `$AIEN_PROOF_DIR`, else `~/.local/state/aien-proof`.
33
34## The nine codes
35
36Output is one line per finding, `FINDING <CODE> component=<name> detail=<text>`,
37then `SUMMARY status=<PASS|FAIL> findings=<n> components=<n>`. Exit code is 0
38on PASS, 1 on an internal error, 2 on a usage error, and otherwise the code of
39the 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
53Profiles: `host-v1` needs tier HOST_TEST or better, `qemu-v1` needs QEMU or
54better, `production-v1` needs PRODUCTION. Tier comparison is
55`aien_proof::chain::tier_satisfies`, so a QEMU receipt never satisfies a
56physical requirement.
57
58## How a component gets a manifest
59
60Put a `closure.toml` in the crate directory. Strict, line based, no comments,
61no blank lines, no tabs, one trailing newline:
62
63```text
64closure-manifest v1
65component aien-scheduler
66profile host-v1
67receipt <64 hex: receipt id that qualifies this component>
68source blake3:<64 hex: source digest the receipt was taken at>
69dep aien-kv-cache <64 hex: receipt id of aien-kv-cache>
70dep aien-platform <64 hex>
71```
72
73Steps:
74
751. Qualify every dependency first (leaves up), each with its own manifest.
762. 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.
803. 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.
834. Write the manifest, then run `verify-closure --root . --write-lock` to
84 produce `closure.lock`, and commit both.
85
86Any source change makes the receipt stale on purpose. Re-qualify, then update
87the 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
92quoted `#include "..."` lines. An include resolves against the including
93file's directory, then against `include_root` (the `-I` directory, `src` for
94Omega). Unresolved quoted includes are returned, not dropped. Limitation: block
95comments and `#if 0` regions are not understood, so a commented out include
96still counts, which errs on the strict side. It is unit tested on a fixture
97directory only.
98
99## Tests
100
101`cargo test -p aien-closure` seeds a fixture workspace (`tests/fixtures/seeded`)
102into a temp directory with receipts built through aien-proof's own API, then
103checks one PASS case and at least one failing case per code, each asserting the
104exact finding and the binary's exit code. The committed seeded fixture (with
105store) is what `.github/workflows/verify-closure.yml` runs against. To rewrite
106it: `cargo test -p aien-closure -- --ignored regenerate_committed_fixture`.
107
108## One meaning per declaration code
109
110The 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
122This crate reads no VCs, so the last two rows are covered by a unit test of the
123shared set comparison (`declare::compare`), not by the binary.
124`tests/declaration_codes.rs` has one test per row plus a negative twin that
125fails 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
130Omega C reader's three fixtures do not cover. See the README there.