diff --git a/AGENTS.md b/AGENTS.md index 99c009a..faac019 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,7 +8,8 @@ Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds - Applies to the whole repository. - `//bundle.json` directories are published data. `` is the repository name under `aien-dev`; `` is the full 40-character commit hash that was verified. A commit that has not been verified has no directory. -- Hand-written files are only `README.md`, `docs/verify-one-bundle.md`, `LICENSE`, `NOTICE` and this file. Documentation changes to those are the only changes an agent may propose. +- Hand-written files are only `README.md`, `docs/verify-one-bundle.md`, `docs/receipt-index.md`, `tools/replay_receipt.py`, `tests/test_replay.py`, `LICENSE`, `NOTICE` and this file. Documentation changes to those are the only changes an agent may propose. +- `index/receipt_index.json` is written only by `tools/replay_receipt.py admit` (see `docs/receipt-index.md`). Never type a digest, commit or verdict into it by hand. - Bundles are written only by the AIEN verification pipeline on the DGX Spark (commits titled `publish N bundle(s)`). An agent never adds, edits, moves, reformats or deletes a bundle, not even to fix a typo or pretty-print JSON. ## Installation @@ -29,6 +30,11 @@ python3 -c "import json,glob; fs=glob.glob('*/*/bundle.json'); [json.load(open(f # Fingerprint of the bundle used in the walkthrough sha256sum aien-architecture/1a3594340c70969c245554b07062efd8ead8a026/bundle.json # expected: cac84aa17376d4349e13d16ba935e349a24db421eaf44cb2bb6be2be5263612a + +# Replay the receipt index (needs GitHub access, Git and OpenSSL 3); last line is the result +python3 tools/replay_receipt.py replay --all +# expected last line: INDEX receipt_index.json v2: 16/16 entries reproduce as indexed rc=0 +python3 -m unittest discover -s tests -v # offline ``` A bundle's top-level fields are `schema`, `repository`, `commit`, `executor`, `plan`, `checks`, `verdict`, `started_utc`, `finished_utc`, `tree_digest`, `graph_digest`, `receipt_id_scheme` and `signature`. Each entry in `checks` carries `check_id`, `gate`, `backend`, `exactness`, `required`, `status`, `verdict` and `receipt`. @@ -55,5 +61,6 @@ To verify a bundle, follow `docs/verify-one-bundle.md`: it clones the shelf, the - `README.md`: layout, how a bundle is checked, rules. - `docs/verify-one-bundle.md`: step-by-step verification of one real bundle, with a tamper refusal case. +- `docs/receipt-index.md`: the receipt index, its admission check (correction precedence, signature, source provenance) and how to replay or admit an entry. - ADR 0033, the verification pipeline design: https://github.com/aien-dev/aien-architecture/blob/efbba982f5c095e3ae71c057b22faaafc11ed84d/docs/adr/0033-aien-verification-pipeline.md - Verifier source (`bundle.rs`): https://github.com/aien-dev/aien-sovereign-core/blob/c26f4d7ac3156088469b27462390f5b08ef4f436/tools/aien-test/src/bundle.rs diff --git a/README.md b/README.md index 13ab19d..2ed1755 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,17 @@ The consuming repository verifies the bundle with `aien-test verify-bundle`, usi The signing key never leaves the verification machine. This repository only receives the signed output, so anyone can read and re-verify a bundle with the public key. +## Receipt index + +[`index/receipt_index.json`](index/receipt_index.json) lists the receipts that may be cited, from +this shelf and from `aien-dev/omega-evidence`, with pinned commits, live SHA-256 digests, the +correction that applies and the effective verdict. `tools/replay_receipt.py replay --all` +refetches every entry, checks the shelf HEAD for a correction added later, and refuses any +drift or any field it does not check. A correction file outranks the historical status, so the +omega-evidence M8 and M9 receipts are indexed as `REFUSED_UNSUPPORTED_PROVENANCE`. The admission +check, and the few values taken on trust, are described in +[`docs/receipt-index.md`](docs/receipt-index.md). + ## How it works / How I built it The [pipeline design record](https://github.com/aien-dev/aien-architecture/blob/efbba982f5c095e3ae71c057b22faaafc11ed84d/docs/adr/0033-aien-verification-pipeline.md) diff --git a/docs/receipt-index.md b/docs/receipt-index.md new file mode 100644 index 0000000..3cf9ae5 --- /dev/null +++ b/docs/receipt-index.md @@ -0,0 +1,220 @@ +# Receipt index and replay + +Linear DRA-167. Status: proposed on branch `feat/dra-167-receipt-index` as a draft pull request. +It changes the layout of this repository, so under `AGENTS.md` ("Safety and approvals") it needs +explicit maintainer approval and a change to the ADR 0033 doctrine in `aien-architecture`. +Drake Stapleton has delegated merge judgment to Queen, the Completion Hive coordinator (DRA-162, +59767dce); Queen's approval of this pull request is the maintainer approval. The ADR 0033 +amendment is drafted [below](#adr-0033-amendment-draft) and lands in `aien-architecture` +before this pull request merges. Neither has happened yet. + +`index/receipt_index.json` lists receipts that may be cited as evidence. For each one it pins +where the bytes live, what they hash to, which correction applies and what verdict follows. +`tools/replay_receipt.py` rebuilds every entry from the pinned commits, checks the shelf HEAD +for a later correction, and refuses an entry whose recomputed fields differ from the file or +that carries a field the tool does not check. + +## What an entry records + +| Field | Meaning | +|---|---| +| `id` | Entry name (no `:`). | +| `issue_or_gate` | The issue or gate the receipt evidences: `value`, `basis` and `verified`. Derived from the receipt where it names one: for signed bundles the repository and the gate of every required check, for Omega receipts `milestone` and `contract_id`. A receipt that names neither carries operator text with `verified: false`, and replay prints it as UNVERIFIED. | +| `kind` | `signed-bundle` (this shelf) or `omega-qualification-receipt` (`aien-dev/omega-evidence`). | +| `shelf` | Repository, commit, path, SHA-256 and byte length of the receipt bytes at that commit. | +| `source` | The verified repository and commit. For Omega receipts also: the field that named the commit, whether it resolves upstream, and the result for every artifact digest (`match`, `mismatch`, `absent`, `commit-unresolved`, `not-recoverable (build output)`). | +| `trust_anchor` | Signed bundles: the first parent of the source commit, with its `.aien/verify.pub` and `.aien/always`. | +| `correction` | The adjacent `.correction.json` at the shelf commit, which must be byte-identical at the shelf HEAD: path, SHA-256, id, `supersedes_historical_status_for_admission`, `qualification_claim`. `null` when none exists at either. | +| `historical_verdict`, `effective_verdict`, `effective_basis` | The status the receipt states, the verdict after the admission check, and which rule decided it. | +| `replay` | The command that replays the entry: exactly `python3 tools/replay_receipt.py replay `. | + +Any other field, in an entry or at the top level of the index, is REJECTED (`UNKNOWN_FIELD`): +a claim the tool does not check cannot sit in the index. The descriptive top-level fields +(`issue`, `generated_by`, `independence`, `admission_check`, `precedence`, `exit_codes`, `scope`, +`excluded`, `generated_utc`) are known but not recomputed; see "Values taken on trust". + +## The admission check + +Applied in this order. The first rule that decides wins. + +1. **Bytes.** The file at `shelf.repository@shelf.commit:shelf.path` must hash to `shelf.sha256`. + Otherwise the entry is REJECTED (`DIGEST_MISMATCH`). +2. **Correction.** The adjacent `.correction.json` must be byte-identical at the shelf + commit and at the current HEAD of the shelf repository; a correction added or changed after + the indexed commit is REJECTED (`STALE_CORRECTION`) until the entry is re-admitted at the + HEAD. If the correction exists, its `corrects` member must name this repository, path and + SHA-256. Otherwise REJECTED (`CORRECTION_UNBOUND`). When it sets + `supersedes_historical_status_for_admission`, its `qualification_claim` is the effective + verdict. The receipt bytes are never changed. Signed bundles have no correction rule yet, so + a `bundle.correction.json` is REJECTED (`CORRECTION_UNSUPPORTED`) rather than ignored. Each + kind lives on one shelf (`signed-bundle` in this repository, `omega-qualification-receipt` + in `aien-dev/omega-evidence`); any other shelf is REJECTED (`SHELF_REPOSITORY`). +3. **Signed bundles.** The key must equal `.aien/verify.pub` from the first parent of the source + commit, never a key found only in the bundle. The Ed25519 signature must verify over the + canonical bytes without `signature`. The repository and commit must match the shelf path, + `executor.id` must be the SHA-256 of the key, every gate in `.aien/always` must be present and + required, and the declared verdict must equal the computed one (FAIL if any required check + failed; PASS if every required check ran or was cached with PASS; NOT_RUN otherwise). Any + failure is REJECTED with the `aien-test` reason code. Otherwise the bundle verdict stands. +4. **Omega receipts without a superseding correction.** The named implementation commit + (`qualified_implementation_commit`, else `git_commit`) must exist in the source repository, + and every recoverable source artifact must hash to its recorded digest at that commit. + Otherwise the effective verdict is `REFUSED_SOURCE_PROVENANCE`. `build/` outputs cannot be + recovered and are not counted. The `receipt_commit` field is recorded but does not decide. +5. **Index drift.** Every field except `id` and `replay` is recomputed, `issue_or_gate` + included, and `replay` must be the exact command for the `id`. Any difference from the + index is REJECTED (`INDEX_DRIFT`); an unknown field is REJECTED (`UNKNOWN_FIELD`). An index + whose entry was edited to claim, say, "hardware qualified on GB10" fails here. + +The shelf HEAD is printed on every replay but not stored, so a new publish on the shelf does not +change the index unless it touches a correction. + +A historical `QUALIFIED / PASS` is therefore never admitted on its own text. + +## Replaying + +Needs network access to GitHub, Python 3, Git and OpenSSL 3. Each run uses a fresh temporary Git +cache unless `--cache DIR` is given. + +```bash +python3 tools/replay_receipt.py replay spark-rsi@f72209e6 # one entry +python3 tools/replay_receipt.py replay --all # the whole index +python3 tools/replay_receipt.py replay spark-rsi@f72209e6 --bytes /tmp/copy.json # control +``` + +The last line is the result, for example `REPLAY omega-evidence/M8: REFUSED_UNSUPPORTED_PROVENANCE rc=4`. + +| Exit | Meaning | +|---|---| +| 0 | PASS | +| 1 | FAIL: an authenticated FAIL verdict | +| 2 | NOT_RUN: an input could not be reached, or a usage error | +| 3 | REJECTED: bytes, signature, binding, correction binding, stale correction, unknown field or index drift | +| 4 | REFUSED: by a shelf correction or by the source-provenance check | + +`replay --all` exits 0 only when every entry reproduces exactly as indexed, whatever its verdict. +Never treat a nonzero exit of a single replay as a pass. + +Keep negative controls outside this checkout. `--bytes` replays a local copy instead of the +fetched file, so a byte-corrupted copy must end in `REJECTED DIGEST_MISMATCH` with exit 3. + +The offline tests build disposable repositories and serve them over `file://`: + +```bash +python3 -m unittest discover -s tests -v +``` + +## Admitting a new receipt + +Every later receipt goes through the same check. `admit` computes the entry from pinned commits +and prints it; it exits 3 instead when rule 1, 2 or 3 rejects the receipt. Admit at the shelf +HEAD: an older commit fails rule 2 whenever a correction has landed since. + +```bash +python3 tools/replay_receipt.py admit --kind signed-bundle \ + --shelf aien-dev/aien-receipts@://bundle.json --id @ +python3 tools/replay_receipt.py admit --kind omega-qualification-receipt \ + --shelf aien-dev/omega-evidence@:.json --source-repo aien-dev/omega-mv \ + --id omega-evidence/ +``` + +`--issue-or-gate ""` is accepted only for a receipt that names no issue or gate; the text +is recorded with `verified: false`. For a receipt that names one, the option is a usage error +(exit 2). + +Append the printed object to `entries`, increase `index_version` when the schema changes, and run +`replay --all`. Never write an entry by hand: a hand-typed digest, verdict or issue fails rule 5. + +## Values taken on trust + +The tool cannot recompute these from the pinned bytes. A reader relies on them as stated: + +- **`source.repository` of an Omega receipt.** The receipts do not name their implementation + repository, so it comes from the index (`--source-repo` at admission). The tool checks only + that it is an `aien-dev/` repository and that the named commit and artifact digests + hold there. A wrong repository shows as `REFUSED_SOURCE_PROVENANCE`, but the index cannot + prove that the receipt meant that repository. +- **The signed-bundle basis "this shelf has no correction records".** `effective_basis` of a + signed bundle reads `authenticated bundle verdict (this shelf has no correction records)`. + The tool checks the part it can see: no `bundle.correction.json` beside the bundle at the + pinned commit or at the shelf HEAD. It cannot see corrections recorded anywhere else, such as + issues, ADRs or `audit/` stamps. +- **Descriptive top-level fields** (`issue`, `generated_by`, `independence`, `precedence`, + `exit_codes`, `scope`, `excluded`, `generated_utc`). They describe the index and are not + recomputed; `precedence` and `exit_codes` restate this document. +- **An `issue_or_gate` marked `verified: false`.** Operator text. Version 2 has none. + +## Version 2 contents + +Version 1 was generated on 2026-11-06 by Receipts167. Version 2 was regenerated by `admit` at +the same pinned shelf commits; only `issue_or_gate` changed, every digest and verdict is +identical. Replayed on the Spark on 2026-11-06: `replay --all` 16/16 entries reproduce, and +every `issue_or_gate` is derived from its receipt. + +| Entry | Effective verdict | Basis | +|---|---|---| +| `spark-rsi@68528eca` | FAIL | Signed bundle; RSI-TEST FAIL. DRA-167 source anchor (recorded here, not in the index). | +| `spark-rsi@f72209e6`, `aien-architecture@1a359434` | PASS | Signed bundles. | +| `omega-evidence/M4`, `M10`, `M11`, `M12`, `M13`, `M14`, `M15`, `M17` | PASS | Named commit resolves; source digests match. | +| `omega-evidence/M8`, `M9` | REFUSED_UNSUPPORTED_PROVENANCE | Shelf corrections recorded 2026-10-26. | +| `omega-evidence/M5` | REFUSED_SOURCE_PROVENANCE | `git_commit` does not exist in `aien-dev/omega-mv`. No shelf correction yet. | +| `omega-evidence/M6` | REFUSED_SOURCE_PROVENANCE | At the named commit, `src/omega_self_host.c` is absent and both AArch64 sources differ. No shelf correction yet. | +| `omega-evidence/M7` | REFUSED_SOURCE_PROVENANCE | At the named commit, `src/omega_verify.c` is absent and `src/omega_validate.c` differs. No shelf correction yet. | + +Also recorded, not deciding: +- M12's `receipt_commit` does not resolve, as its non-superseding correction says. +- M14's `receipt_commit` does not resolve either, and no correction says so yet. +- M10, M11 and M13 carry the placeholder `pending-receipt-commit`. + +`index.excluded` lists the omega-evidence receipts in other layouts, which are not yet covered. + +## Limits + +- **Not independent.** The author of the index and the author of the tool are the same agent. An + independent replay needs a different operator, or `aien-test verify-bundle` for signed bundles + as in `docs/verify-one-bundle.md`. +- **Not `aien-test`.** The signature check uses OpenSSL Ed25519, not `ed25519-dalek` + `verify_strict`. The canonical encoder is a Python port of `evidence::canonical` + (aien-sovereign-core@c26f4d7ac3156088469b27462390f5b08ef4f436); the tests use that file's + golden cases. +- **Omega PASS is narrow.** Omega receipts carry no signature. PASS here means the pinned bytes, + a resolving named commit and matching source digests. The binary and the run were not + recovered, and nothing here is hardware qualification. +- **Signed PASS is narrow.** A valid signature authenticates the recorded statement, not the + sufficiency of the tests behind it. All three bundles in version 2 ran on the `host` backend. +- **Host dependencies.** Observed on the Spark: Python 3.12.3, Git 2.43.0, OpenSSL 3.0.13. + They fetch commits, compute SHA-256 and verify Ed25519. No Omega replacement exists; porting + the check to seeded Omega is an open proposal, in line with `audit/tools`, which is also Python. + +## ADR 0033 amendment (draft) + +To be added to `docs/adr/0033-aien-verification-pipeline.md` in `aien-dev/aien-architecture` +(drafted against ad8d1eb), after the 2026-10-26 amendment and before "Not decided here": + +> ## Amendment 2026-11-06 (receipt index on the receipts shelf) +> +> Approved for the maintainer by Queen, the Completion Hive coordinator, under Drake +> Stapleton's delegation of merge judgment (DRA-162, 59767dce), with aien-dev/aien-receipts#12 +> (DRA-167). Nothing in Decisions 1 to 14 or in the earlier amendments changes, and published +> `//bundle.json` files keep their bytes, layout and meaning. +> +> 1. **A receipt index on the same shelf.** `aien-dev/aien-receipts` gains `index/receipt_index.json`, +> the replay tool `tools/replay_receipt.py`, its offline tests `tests/test_replay.py` and the +> description `docs/receipt-index.md`. The index lists the receipts that may be cited: +> signed bundles from this shelf and Omega qualification receipts from +> `aien-dev/omega-evidence`, each with the pinned shelf commit, SHA-256, the correction that +> applies and the effective verdict. +> 2. **Written only by the tool.** Entries are written only by `tools/replay_receipt.py admit`. +> Replay recomputes every entry except its name and command, and rejects any difference, any +> field it does not check, and any correction that differs between the indexed commit and the +> shelf HEAD. +> 3. **Corrections outrank historical status.** A `.correction.json` that supersedes a receipt's +> historical status decides the effective verdict; a historical `QUALIFIED / PASS` is never +> admitted on its own text. Omega receipts without a superseding correction must also match +> their named source commit. +> 4. **Bundles unchanged.** Signed bundles are checked as in Decision 6 (key from the source +> commit's first parent, verdict algebra of Decision 7). The index does not re-sign or move +> them, and a bundle correction file is refused until a rule for it is decided. +> 5. **Not a gate.** The index is a citation aid. It is not an input to `aien-test +> verify-bundle`, the AIEN Alpha job or any merge gate, and a replay by the index's author is +> not an independent review. diff --git a/index/receipt_index.json b/index/receipt_index.json new file mode 100644 index 0000000..1be8ec3 --- /dev/null +++ b/index/receipt_index.json @@ -0,0 +1,997 @@ +{ + "schema": "aien.receipt-index.v2", + "index_version": 2, + "issue": "DRA-167", + "generated_by": "python3 tools/replay_receipt.py admit, one call per entry, run on the Spark by SiReleaseCoord2/Receipts167 (v1) and regenerated by FixReceipts12 (v2) at the same pinned shelf commits; every digest, signature check, source check, correction check and issue_or_gate was computed at generation time", + "independence": "The author of this index and the author of tools/replay_receipt.py are the same agent. A replay with this tool by that agent is not an independent review. An independent replay is a different operator following docs/receipt-index.md, or `aien-test verify-bundle` for signed bundles.", + "admission_check": "docs/receipt-index.md", + "precedence": [ + "1. Shelf bytes: the file at shelf.repository@shelf.commit:shelf.path must hash to shelf.sha256, else REJECTED.", + "2. Shelf correction: the adjacent .correction.json must be byte-identical at shelf.commit and at the current HEAD of the shelf repository, else REJECTED (STALE_CORRECTION; re-admit the entry at the HEAD). A correction that is present must name these exact bytes (repository, path, sha256), else REJECTED. When it sets supersedes_historical_status_for_admission, its qualification_claim is the effective verdict. Signed bundles admit no correction file (CORRECTION_UNSUPPORTED).", + "3. Signed bundles: key from the source commit's first-parent .aien/verify.pub, Ed25519 signature, repository, commit, executor, required gates from .aien/always and verdict algebra must all hold, else REJECTED; the effective verdict is the bundle verdict.", + "4. Omega receipts without a superseding correction: the named source commit must resolve upstream and every recoverable source artifact must hash to the recorded digest; otherwise the effective verdict is REFUSED_SOURCE_PROVENANCE. build/ outputs are never recoverable and are not counted.", + "5. Replay recomputes every field except id and replay, and replay must read `python3 tools/replay_receipt.py replay `. issue_or_gate is derived from the receipt (bundle repository and required gates; Omega milestone and contract_id); a receipt that names none carries operator text marked verified false, and replay prints it as UNVERIFIED. Any difference from this file is REJECTED (INDEX_DRIFT); an index or entry field this tool does not know is REJECTED (UNKNOWN_FIELD)." + ], + "exit_codes": { + "0": "PASS", + "1": "FAIL (authenticated FAIL verdict)", + "2": "NOT_RUN (input unreachable or usage error)", + "3": "REJECTED (integrity, binding, correction binding, stale correction, unknown field or index drift)", + "4": "REFUSED (shelf correction or source-provenance check)" + }, + "scope": { + "omega-evidence": "Root-level receipts with status \"QUALIFIED / PASS\" at aien-dev/omega-evidence@1da6a283d24895ddc1337fb3696c4e2997cd8c56 (M4-M15, M17).", + "aien-receipts": "Three signed bundles: the DRA-167 source anchor and the two PASS bundles used as replay references." + }, + "excluded": [ + { + "path": "aien-dev/omega-evidence:omega_accelerator_world_qualification_receipt.json", + "reason": "status SILICON_QUALIFIED with a different receipt layout; needs its own admission rule" + }, + { + "path": "aien-dev/omega-evidence:omega_blackwell_matmul_stage1_receipt.json", + "reason": "no status member; different receipt layout" + }, + { + "path": "aien-dev/omega-evidence:omega_blackwell_matmul_stage2_receipt.json", + "reason": "no status member; different receipt layout" + }, + { + "path": "aien-dev/omega-evidence:m19_m18_stage2_regression.json", + "reason": "no status member; regression record, not a qualification receipt" + }, + { + "path": "aien-dev/omega-evidence:m19r_gate5_omega_numeric_evidence.json", + "reason": "status PASS with a different receipt layout; needs its own admission rule" + }, + { + "path": "aien-dev/aien-receipts: other bundles", + "reason": "not yet admitted; add each with `tools/replay_receipt.py admit`" + } + ], + "generated_utc": "2026-11-06T21:36:04Z", + "entries": [ + { + "id": "spark-rsi@68528eca", + "issue_or_gate": { + "value": "aien-dev/spark-rsi required gates: CRUMB-VERIFY, RSI-CHECK, RSI-FMT, RSI-TEST, RSI-ZERO-DISK-SECRETS", + "basis": "bundle repository and the gate of every required check", + "verified": true + }, + "kind": "signed-bundle", + "shelf": { + "repository": "aien-dev/aien-receipts", + "commit": "3d4e338887954a54ca236bc101e37d027167ba84", + "path": "spark-rsi/68528eca128ed0f77cde3df7a17d94c7a7e0e1dc/bundle.json", + "sha256": "07cf064d63ffd1eefe6fe60393d03e3dd18d6bbe0625e833e8f69ad04558aeb8", + "bytes": 2308 + }, + "source": { + "repository": "aien-dev/spark-rsi", + "commit": "68528eca128ed0f77cde3df7a17d94c7a7e0e1dc" + }, + "trust_anchor": { + "repository": "aien-dev/spark-rsi", + "commit": "7e8bf7da7f2adc0bea7938cc042d8a7873619cc1", + "rule": "first parent of the source commit", + "verify_pub": "01368e0b02dc1113ae7425ad6ab00fdf5aa7dd97e0690745918a52f051d5cf68", + "always": [ + "CRUMB-VERIFY", + "RSI-ZERO-DISK-SECRETS" + ] + }, + "signature": "VERIFIED (OpenSSL Ed25519 over canonical bytes without the signature member)", + "gates": [ + { + "gate": "CRUMB-VERIFY", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-CHECK", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-FMT", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-TEST", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "FAIL" + }, + { + "gate": "RSI-ZERO-DISK-SECRETS", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + } + ], + "correction": null, + "historical_verdict": "FAIL", + "effective_verdict": "FAIL", + "effective_basis": "authenticated bundle verdict (this shelf has no correction records)", + "replay": "python3 tools/replay_receipt.py replay spark-rsi@68528eca" + }, + { + "id": "spark-rsi@f72209e6", + "issue_or_gate": { + "value": "aien-dev/spark-rsi required gates: CRUMB-VERIFY, RSI-CHECK, RSI-FMT, RSI-TEST, RSI-ZERO-DISK-SECRETS", + "basis": "bundle repository and the gate of every required check", + "verified": true + }, + "kind": "signed-bundle", + "shelf": { + "repository": "aien-dev/aien-receipts", + "commit": "e4f0256f1da4e60cd2e808b830cb65473fc5331c", + "path": "spark-rsi/f72209e6da318f4ed36d772cea89f332c68fb9cf/bundle.json", + "sha256": "497a18b2232fbd686fa2911ae71ff437242a201343c84bce31e87cce0ade7bd1", + "bytes": 2286 + }, + "source": { + "repository": "aien-dev/spark-rsi", + "commit": "f72209e6da318f4ed36d772cea89f332c68fb9cf" + }, + "trust_anchor": { + "repository": "aien-dev/spark-rsi", + "commit": "5cd6263ff2ed59ead8507bb87efadc18cc6c1738", + "rule": "first parent of the source commit", + "verify_pub": "01368e0b02dc1113ae7425ad6ab00fdf5aa7dd97e0690745918a52f051d5cf68", + "always": [ + "CRUMB-VERIFY", + "RSI-ZERO-DISK-SECRETS" + ] + }, + "signature": "VERIFIED (OpenSSL Ed25519 over canonical bytes without the signature member)", + "gates": [ + { + "gate": "CRUMB-VERIFY", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-CHECK", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-FMT", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-TEST", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "RSI-ZERO-DISK-SECRETS", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + } + ], + "correction": null, + "historical_verdict": "PASS", + "effective_verdict": "PASS", + "effective_basis": "authenticated bundle verdict (this shelf has no correction records)", + "replay": "python3 tools/replay_receipt.py replay spark-rsi@f72209e6" + }, + { + "id": "aien-architecture@1a359434", + "issue_or_gate": { + "value": "aien-dev/aien-architecture required gates: ARCH-DOCTRINE, ARCH-QUALIFICATION-STATUS, CRUMB-VERIFY", + "basis": "bundle repository and the gate of every required check", + "verified": true + }, + "kind": "signed-bundle", + "shelf": { + "repository": "aien-dev/aien-receipts", + "commit": "09368f488d228736f8fd2a271a4a691dc3e8cf85", + "path": "aien-architecture/1a3594340c70969c245554b07062efd8ead8a026/bundle.json", + "sha256": "cac84aa17376d4349e13d16ba935e349a24db421eaf44cb2bb6be2be5263612a", + "bytes": 1768 + }, + "source": { + "repository": "aien-dev/aien-architecture", + "commit": "1a3594340c70969c245554b07062efd8ead8a026" + }, + "trust_anchor": { + "repository": "aien-dev/aien-architecture", + "commit": "efbba982f5c095e3ae71c057b22faaafc11ed84d", + "rule": "first parent of the source commit", + "verify_pub": "01368e0b02dc1113ae7425ad6ab00fdf5aa7dd97e0690745918a52f051d5cf68", + "always": [ + "CRUMB-VERIFY", + "ARCH-DOCTRINE", + "ARCH-QUALIFICATION-STATUS" + ] + }, + "signature": "VERIFIED (OpenSSL Ed25519 over canonical bytes without the signature member)", + "gates": [ + { + "gate": "ARCH-DOCTRINE", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "ARCH-QUALIFICATION-STATUS", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + }, + { + "gate": "CRUMB-VERIFY", + "backend": "host", + "exactness": "EXACT", + "required": true, + "status": "run", + "verdict": "PASS" + } + ], + "correction": null, + "historical_verdict": "PASS", + "effective_verdict": "PASS", + "effective_basis": "authenticated bundle verdict (this shelf has no correction records)", + "replay": "python3 tools/replay_receipt.py replay aien-architecture@1a359434" + }, + { + "id": "omega-evidence/M4", + "issue_or_gate": { + "value": "Omega MILESTONE 4 — OMEGA_SEMANTICS qualification (CONTRACT-OMEGA-SEMANTICS-M4)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_qualification_receipt.json", + "sha256": "1ababfd5c80f6604a3d1a4704a614e906e0666ad3cb3be27e8208485c66f03ab", + "bytes": 2570 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "git_commit", + "commit": "30bb116cc0ae882668bc09bbd650adc50f28ee8b", + "commit_resolves": true, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "0bd205b5e475ca3af0eca4583bae11da411c23ed5c972f0a5807cf771629beb3", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "spec/canonical-encoding.md", + "sha256": "a5ca176ee1aa60db2df607d6ba5f20be37137922bfab43e5f4a11653d63795e1", + "at_source_commit": "match" + }, + { + "path": "spec/semantic-object.md", + "sha256": "c9bc90206508082de365a2244a5f41e2e37c3e7fc7e23754c78e710058303067", + "at_source_commit": "match" + }, + { + "path": "spec/type-system.md", + "sha256": "8bed4af3a71278e7ef8d0ccf8964ca157376fc3305d4efee146f8db270306d3c", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M4" + }, + { + "id": "omega-evidence/M5", + "issue_or_gate": { + "value": "Omega MILESTONE 5 — OMEGA_AARCH64 qualification (CONTRACT-OMEGA-AARCH64-M5)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_aarch64_qualification_receipt.json", + "sha256": "c095f34c74585e604a91b1f73ebb5199010c49260344e3cfcad94871571a4ad1", + "bytes": 3426 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "git_commit", + "commit": "2dd41024345d207d57f59d4c7940176b6697b099", + "commit_resolves": false, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "8060d19b4de3db643715cfac407246bd5f6747db34639984b64afea7f8d8524d", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/aarch64_decoder.c", + "sha256": "d7326177b00094c174822fc128529461293d4f1c44bbe7e11e2668b759262230", + "at_source_commit": "commit-unresolved" + }, + { + "path": "src/aarch64_encoder.c", + "sha256": "da787a2c0b80d83c9c395170c0b4b2dd6e46dc726203608b1c6a73cf53f9b8da", + "at_source_commit": "commit-unresolved" + }, + { + "path": "src/omega_exec.c", + "sha256": "ccd6f43bd5f137b83ff537d874ba220a0dbd2921577d8c9f577f5504cd9890df", + "at_source_commit": "commit-unresolved" + }, + { + "path": "src/omega_realize.c", + "sha256": "d916dea77a6c84be0a705c7781039023f2b76f9e8667fba0692417f77d5e09d0", + "at_source_commit": "commit-unresolved" + } + ], + "source_check": "FAIL" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "REFUSED_SOURCE_PROVENANCE", + "effective_basis": "index source check (no superseding shelf correction)", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M5" + }, + { + "id": "omega-evidence/M6", + "issue_or_gate": { + "value": "Omega MILESTONE 6 — OMEGA_SELF_HOST qualification (CONTRACT-OMEGA-SELF-HOST-M6)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_self_host_qualification_receipt.json", + "sha256": "f637f81568cc8b19c6ca8c45a77cb62c6fe666b26ba1a41659bdbe5e99d057f7", + "bytes": 2459 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "git_commit", + "commit": "34dbe93c3a3e0260e8ca381e6212c648384f8738", + "commit_resolves": true, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "c000315b91a489d33e5c180e426a0263e24ae575549bb478ab62a47c4d214b93", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/aarch64_decoder.c", + "sha256": "ac543a0582ba165b7795502f45a0542aef3900cf0485f31b873a85ec00ade37f", + "at_source_commit": "mismatch" + }, + { + "path": "src/aarch64_encoder.c", + "sha256": "adc110ae80aabb94290337c549f3e038cc1b6f2375043700cb5327641f357c3f", + "at_source_commit": "mismatch" + }, + { + "path": "src/omega_self_host.c", + "sha256": "c1090ec33c102e0a655ae11e57bdf0d6f8596c45e96195a21f77f072f01df028", + "at_source_commit": "absent" + } + ], + "source_check": "FAIL" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "REFUSED_SOURCE_PROVENANCE", + "effective_basis": "index source check (no superseding shelf correction)", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M6" + }, + { + "id": "omega-evidence/M7", + "issue_or_gate": { + "value": "Omega MILESTONE 7 — OMEGA_VERIFY qualification (CONTRACT-OMEGA-VERIFY-M7)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_verify_qualification_receipt.json", + "sha256": "5665637e1df96309d457aa464dbf6475b97a298e67e1709dc02800a350b65ff2", + "bytes": 2441 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "git_commit", + "commit": "8033c3805ce953d111c58c4da33a60678e15401d", + "commit_resolves": true, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "7eca510b09da41f10b798e2efb7028da97409240f759c984f5a2da8ac466cf8d", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/aarch64_decoder.c", + "sha256": "ac543a0582ba165b7795502f45a0542aef3900cf0485f31b873a85ec00ade37f", + "at_source_commit": "match" + }, + { + "path": "src/omega_validate.c", + "sha256": "ec0e6a629171140302f56474481b5986bf4bee315a621aa7c8584b2cd116d790", + "at_source_commit": "mismatch" + }, + { + "path": "src/omega_verify.c", + "sha256": "b7b3addb2bcad248e1e3e53196745861a918b78239632426b8942fa452438179", + "at_source_commit": "absent" + } + ], + "source_check": "FAIL" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "REFUSED_SOURCE_PROVENANCE", + "effective_basis": "index source check (no superseding shelf correction)", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M7" + }, + { + "id": "omega-evidence/M8", + "issue_or_gate": { + "value": "Omega MILESTONE 8 — OMEGA_PROGRAM_CORE qualification (CONTRACT-OMEGA-PROGRAM-CORE-M8)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_program_core_qualification_receipt.json", + "sha256": "2e5febd99ec0bf572f1feb7e0e3a3ce30e3dea3393ec0af944cfd3a7b285e6bd", + "bytes": 2708 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "d25349e4bf4a820dbcff0dd6a593d1db7b454a0b", + "commit_resolves": true, + "receipt_commit": { + "value": "d25349e4bf4a820dbcff0dd6a593d1db7b454a0b", + "resolves": true + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "c5f00e435e4f5f9e7b50f37cc0a4c66c919864c696a05639a29197b7bef3e886", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_program.c", + "sha256": "04bc92eb3b498a71f5225f1b409cc55309953365d0a990959ec142a452755ccf", + "at_source_commit": "mismatch" + }, + { + "path": "src/omega_verify.c", + "sha256": "b7b3addb2bcad248e1e3e53196745861a918b78239632426b8942fa452438179", + "at_source_commit": "match" + } + ], + "source_check": "FAIL" + }, + "correction": { + "path": "omega_program_core_qualification_receipt.correction.json", + "sha256": "668f1c94ed5bf5e96df1b430afea74b6e927525ae64ed0173dcebcea2a634777", + "correction_id": "M8-source-commit-mismatch-2026-10-26", + "recorded_on": "2026-10-26", + "supersedes_historical_status_for_admission": true, + "qualification_claim": "REFUSED_UNSUPPORTED_PROVENANCE" + }, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "REFUSED_UNSUPPORTED_PROVENANCE", + "effective_basis": "shelf correction M8-source-commit-mismatch-2026-10-26", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M8" + }, + { + "id": "omega-evidence/M9", + "issue_or_gate": { + "value": "Omega MILESTONE 9 — OMEGA_SYNTHESIS_V0 qualification (CONTRACT-OMEGA-SYNTHESIS-V0-M9)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_synthesis_v0_qualification_receipt.json", + "sha256": "efa154f1967df640157bff9047e28f3fc1504570a0d5cdd2e0243f6350bd51b0", + "bytes": 3467 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "39905a3eebc3f25c7e3f89d380b06b00539b233a", + "commit_resolves": false, + "receipt_commit": { + "value": "39905a3eebc3f25c7e3f89d380b06b00539b233a", + "resolves": false + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "c5f00e435e4f5f9e7b50f37cc0a4c66c919864c696a05639a29197b7bef3e886", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_program.c", + "sha256": "04bc92eb3b498a71f5225f1b409cc55309953365d0a990959ec142a452755ccf", + "at_source_commit": "commit-unresolved" + }, + { + "path": "src/omega_synthesis.c", + "sha256": "e02992fad763b8814c7c174fa8601d6881548f5afae5d6c5fab3b3415f222311", + "at_source_commit": "commit-unresolved" + } + ], + "source_check": "FAIL" + }, + "correction": { + "path": "omega_synthesis_v0_qualification_receipt.correction.json", + "sha256": "fcc4d972180eae4db4d98a7d259c8f41acd97340ab7aa49e7b1b6b53575e3489", + "correction_id": "M9-named-commit-absent-2026-10-26", + "recorded_on": "2026-10-26", + "supersedes_historical_status_for_admission": true, + "qualification_claim": "REFUSED_UNSUPPORTED_PROVENANCE" + }, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "REFUSED_UNSUPPORTED_PROVENANCE", + "effective_basis": "shelf correction M9-named-commit-absent-2026-10-26", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M9" + }, + { + "id": "omega-evidence/M10", + "issue_or_gate": { + "value": "Omega MILESTONE 10 — OMEGA_LIBRARY_V1 qualification (CONTRACT-OMEGA-LIBRARY-V1-M10)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_library_v1_qualification_receipt.json", + "sha256": "ed145343ccf7537195cc2596b2e89bdb222daa9e38c2657329bde145427a3c61", + "bytes": 2254 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "1808ed8663569cececfe4b89bb0f0dc9d023ee4a", + "commit_resolves": true, + "receipt_commit": { + "value": "pending-receipt-commit", + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "8297770b1050b8dc612b647c49c35ab0b980c2b64196d376d42c2d2b79ad2018", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_library.c", + "sha256": "a5a37f73b5eb7f0c69ae92ae9fd3744c31aa228dc212ad49721d7f744501e941", + "at_source_commit": "match" + }, + { + "path": "src/omega_library.h", + "sha256": "adc279c5a895cc9ad53a48a77e2bffa0c56a2362f1b1b64486f61f4960e8bfee", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M10" + }, + { + "id": "omega-evidence/M11", + "issue_or_gate": { + "value": "Omega MILESTONE 11 — OMEGA_LIBRARY_DISCOVERY qualification (CONTRACT-OMEGA-LIBRARY-DISCOVERY-M11)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_library_discovery_qualification_receipt.json", + "sha256": "193bfce34119a66d7b8b739347a9ddd910b91348359ef59f61d3f2cad579638d", + "bytes": 2439 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "1ee43fbf1c7d588734b80bd0743e5d054aea750b", + "commit_resolves": true, + "receipt_commit": { + "value": "pending-receipt-commit", + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "eb0f54a5d4ed55343946a65ee0a8472f04e972d3d2a20c96f12158acd88e835c", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_discovery.c", + "sha256": "2ac1a2515c884e148b1d3ff6396438777abd931012659bc2cf52f98289606153", + "at_source_commit": "match" + }, + { + "path": "src/omega_discovery.h", + "sha256": "4d607ec8f6ecb45c3f12cc1b0923fd09a8dc92bb9b7983c8c200d7f2555338b0", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M11" + }, + { + "id": "omega-evidence/M12", + "issue_or_gate": { + "value": "Omega MILESTONE 12 — OMEGA_LIVING_MATVEC qualification (CONTRACT-OMEGA-LIVING-MATVEC-M12)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_living_matvec_qualification_receipt.json", + "sha256": "227536387d6bb49683773308c390008b7deed79953fdf0d731aa405fa1916e5b", + "bytes": 2351 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "44f645f176f634fdb4b5aac950d31423b2946664", + "commit_resolves": true, + "receipt_commit": { + "value": "d1e67c4a6cee7cabc0db789fbd8689a616b334ab", + "resolves": false + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "c66a3360f7f113566fb6bb83b0926c49be1b753914483563f8cbe14b972db522", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_matvec.c", + "sha256": "bf679e9bbadf6a3e02d7d692661f7b1e336370e2e41998f5d88ad860f408a4a1", + "at_source_commit": "match" + }, + { + "path": "src/omega_matvec.h", + "sha256": "804a19643dbd3e123150e0bd610bab6faa54068710b9ec6ad7cf0bda2523c58c", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": { + "path": "omega_living_matvec_qualification_receipt.correction.json", + "sha256": "777b4ddef31121710a49b3b18b3b4bd6bde1cd456f897fc7019428c5f4b7ce25", + "correction_id": "M12-receipt-commit-absent-2026-10-26", + "recorded_on": "2026-10-26", + "supersedes_historical_status_for_admission": false, + "qualification_claim": "SOURCE_MATCHES_NAMED_COMMIT; RECEIPT_COMMIT_FIELD_FALSE" + }, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M12" + }, + { + "id": "omega-evidence/M13", + "issue_or_gate": { + "value": "Omega MILESTONE 13 — OMEGA_MACHINE_GRAPH qualification (CONTRACT-OMEGA-MACHINE-GRAPH-M13)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_machine_graph_qualification_receipt.json", + "sha256": "d5f154cc31283ea50b1e6e907ffa47e52ef7b45548e306667e4a4d5276e17a10", + "bytes": 2371 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "9413558ae113b02484548d1b6cd0d71bf61981b6", + "commit_resolves": true, + "receipt_commit": { + "value": "pending-receipt-commit", + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "28df863127c8a353bcae8b2721f177d7d40091eacdc4886f65541d3dfe0795ca", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_machine.c", + "sha256": "1a64e448237a42a05c82ed8e0c8910f4c5b2dbb5010cb522f683aaceba7f17b7", + "at_source_commit": "match" + }, + { + "path": "src/omega_machine.h", + "sha256": "ad091205bfbd5f5fa9044602cfbb346f2362534ce7ba5b75d195661c29ac5b10", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M13" + }, + { + "id": "omega-evidence/M14", + "issue_or_gate": { + "value": "Omega MILESTONE 14 — OMEGA_REALIZATION_SYNTHESIS qualification (CONTRACT-OMEGA-REALIZATION-SYNTHESIS-M14)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_realization_synthesis_qualification_receipt.json", + "sha256": "9074be81976d39fc43e12c2854cae7ac3f59291c295c5f7c4f1ccd9732529d43", + "bytes": 2384 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "c0c8102ecc7f36cb86ab8686e5f1ee08eb59762d", + "commit_resolves": true, + "receipt_commit": { + "value": "7c07acae88ebeb32e62608bb30bc659a61297943", + "resolves": false + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "104410d3569adcefbe642a4d20b5fc7a80518d826c63c1f9b032cdd335f7f52d", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_realize_synth.c", + "sha256": "0744c9a709e0e0869c0f8a9d5e2e3a129c4c0df850dfe8e77626ef69bbf83a3c", + "at_source_commit": "match" + }, + { + "path": "src/omega_realize_synth.h", + "sha256": "bb62ef9d078f2f8efa550f9a4941330b86d4f997d1d8c79bd17282ce7c905d74", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M14" + }, + { + "id": "omega-evidence/M15", + "issue_or_gate": { + "value": "Omega MILESTONE 15 — PHYSICS_ACCELERATOR_LINK qualification (CONTRACT-OMEGA-ACCELERATOR-LINK-M15)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_accelerator_link_qualification_receipt.json", + "sha256": "6d18480c4eb6c3f571acd10939bf7f5a99639dccdd17ee1794a7653039dccd2f", + "bytes": 2575 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "625640f612aee55be0d7cf67d744c27d904c6bc3", + "commit_resolves": true, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "545d4c61acbb9db5f767c630cfe57a23471515def897db38d626518f42489e9e", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_accelerator.c", + "sha256": "8399927e9d0c73fe033d705703bf1207f198e4c0f218cf7dfb435404b0741a0e", + "at_source_commit": "match" + }, + { + "path": "src/omega_accelerator.h", + "sha256": "ed2bada853ae4411872fc79dce381ff7d4db1077294d1717d03d26e2462ecab4", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M15" + }, + { + "id": "omega-evidence/M17", + "issue_or_gate": { + "value": "Omega MILESTONE 17: OMEGA_BLACKWELL_VECTOR qualification (CONTRACT-OMEGA-BLACKWELL-VECTOR-M17)", + "basis": "receipt fields milestone and contract_id", + "verified": true + }, + "kind": "omega-qualification-receipt", + "shelf": { + "repository": "aien-dev/omega-evidence", + "commit": "1da6a283d24895ddc1337fb3696c4e2997cd8c56", + "path": "omega_blackwell_vector_qualification_receipt.json", + "sha256": "b22542bbdbba349b878e9e177cf6053959706df7d3effccf7ad5a7002bc994a5", + "bytes": 4011 + }, + "source": { + "repository": "aien-dev/omega-mv", + "commit_field": "qualified_implementation_commit", + "commit": "27971cda951800c6c6d42201890de67dea0d532e", + "commit_resolves": true, + "receipt_commit": { + "value": null, + "resolves": null + }, + "artifacts": [ + { + "path": "build/omegatool", + "sha256": "cbc0bda516b0375c4332a081ed742e3bb593dc167e5e030a06f608d0683fa697", + "at_source_commit": "not-recoverable (build output)" + }, + { + "path": "src/omega_blackwell_encoder.c", + "sha256": "07246381b752ca92cc2d027302a01cdf5eee7c12d5754ee368b42185f49bd784", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_encoder.h", + "sha256": "c1117f24d3a146ffb9ed9ece80ec6a5d248da64ca5a2f1aaed73b84133372f40", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_qmd.c", + "sha256": "853005916a1a76c82601d2ab19e30bfe9c6a6ac7b5cacd4a157abb83316d9e57", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_qmd.h", + "sha256": "4e4d8413d960c102a2f9310e0b8602622e3fe278a946a8bcd878baecc1b02c68", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_realize.c", + "sha256": "9a5949d2a53b2623c592a116df6d9102a8f5e66dbe058d58d07283b5bec57cef", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_realize.h", + "sha256": "54723c3473f8dfd4b0f565cbcf2239822a1b3a75e5760ffac921bd3bbd28c71f", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_submit.c", + "sha256": "42173cb81eeb3cc97dbdd22215ed6c17a43bd04cc68e5b70717d67ee17dc9991", + "at_source_commit": "match" + }, + { + "path": "src/omega_blackwell_submit.h", + "sha256": "605149c9ef0b90d553f38852e1458aac4e30c892c74ad21532728268ab200fac", + "at_source_commit": "match" + }, + { + "path": "src/omega_vector.c", + "sha256": "9e4f4622080494b1cf701f0d1c220979785c630cf8317ce44d68bdf58b5b47b5", + "at_source_commit": "match" + }, + { + "path": "src/omega_vector.h", + "sha256": "7526e6849f33dcffc3c6420f0cdc2c86022a094117f57062d8f4f92886496698", + "at_source_commit": "match" + } + ], + "source_check": "PASS" + }, + "correction": null, + "historical_verdict": "QUALIFIED / PASS", + "effective_verdict": "PASS", + "effective_basis": "historical status; named source commit resolves and source digests match", + "replay": "python3 tools/replay_receipt.py replay omega-evidence/M17" + } + ] +} diff --git a/tests/test_replay.py b/tests/test_replay.py new file mode 100644 index 0000000..d9aad0b --- /dev/null +++ b/tests/test_replay.py @@ -0,0 +1,422 @@ +"""Offline tests for tools/replay_receipt.py (DRA-167). + +Every test builds disposable Git repositories under a temporary directory and +serves them through file:// URLs, so the suite needs no network and never +touches the shelf in this checkout. Run from the repository root: + + python3 -m unittest discover -s tests -v +""" +import hashlib +import json +import os +import subprocess +import sys +import tempfile +import unittest + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +TOOL = os.path.join(ROOT, "tools", "replay_receipt.py") +sys.path.insert(0, os.path.join(ROOT, "tools")) +import replay_receipt as rr # noqa: E402 + +GIT_ID = ["-c", "user.name=fixture", "-c", "user.email=fixture@example.invalid", "-c", "commit.gpgsign=false"] + + +def sha(b): + return hashlib.sha256(b).hexdigest() + + +def sh(*args, cwd=None, data=None): + return subprocess.run(args, cwd=cwd, check=True, capture_output=True, input=data).stdout + + +class Key: + def __init__(self, d, name): + self.pem = os.path.join(d, name + ".pem") + sh("openssl", "genpkey", "-algorithm", "ed25519", "-out", self.pem) + der = sh("openssl", "pkey", "-in", self.pem, "-pubout", "-outform", "DER") + self.pub = der[-32:].hex() + self.dir = d + + def sign(self, msg): + m, s = os.path.join(self.dir, "m.bin"), os.path.join(self.dir, "s.bin") + with open(m, "wb") as f: + f.write(msg) + sh("openssl", "pkeyutl", "-sign", "-inkey", self.pem, "-rawin", "-in", m, "-out", s) + with open(s, "rb") as f: + return f.read().hex() + + +class Remotes: + def __init__(self, root): + self.root = root + + def commit(self, name, files, msg="fixture"): + d = os.path.join(self.root, name) + if not os.path.isdir(d): + os.makedirs(d) + sh("git", "init", "-q", "-b", "main", cwd=d) + sh("git", "config", "uploadpack.allowFilter", "true", cwd=d) + sh("git", "config", "uploadpack.allowAnySHA1InWant", "true", cwd=d) + for path, data in files.items(): + p = os.path.join(d, path) + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(p, "wb") as f: + f.write(data) + sh("git", "add", "-A", cwd=d) + sh("git", *GIT_ID, "commit", "-q", "--allow-empty", "-m", msg, cwd=d) + return sh("git", "rev-parse", "HEAD", cwd=d).decode().strip() + + +def bundle(key, repo, commit, checks, verdict, signer=None): + b = { + "schema": rr.BUNDLE_SCHEMA, "repository": "github.com/" + repo, "commit": commit, + "executor": {"class": "spark", "id": sha(bytes.fromhex(key.pub)), "machine_digest": "a" * 64}, + "tree_digest": "b" * 64, "graph_digest": "c" * 64, "receipt_id_scheme": "sha256-canonical-json", + "started_utc": "2026-11-06T00:00:00Z", "finished_utc": "2026-11-06T00:01:00Z", + "checks": [{"backend": "host", "check_id": "d" * 64, "exactness": "EXACT", "gate": g, "receipt": "e" * 64, + "required": True, "status": "run", "verdict": v} for g, v in checks], + "verdict": verdict, + } + signer = signer or key + b["signature"] = {"alg": "ed25519", "pubkey": signer.pub, "sig": signer.sign(rr.canonical(b))} + return b + + +def receipt(commit, **fields): + d = {"status": "QUALIFIED / PASS", "milestone": "MILESTONE T", "contract_id": "CONTRACT-T", "git_commit": commit, + "artifacts": {"build/omegatool": {"sha256": "0" * 64}, "src/a.c": {"sha256": sha(b"int a;\n")}}} + d.update(fields) + return json.dumps({k: v for k, v in d.items() if v is not None}, indent=2).encode() + + +def correction(path, digest, cid="T-1"): + return json.dumps({"schema": rr.CORRECTION_SCHEMA, "correction_id": cid, "recorded_on": "2026-11-06", + "corrects": {"repository": "aien-dev/omega-evidence", "path": path, "sha256": digest}, + "disposition": {"supersedes_historical_status_for_admission": True, + "qualification_claim": "REFUSED_UNSUPPORTED_PROVENANCE"}}).encode() + + +OMEGA_ISSUE = {"value": "Omega MILESTONE T qualification (CONTRACT-T)", + "basis": "receipt fields milestone and contract_id", "verified": True} + + +class ReplayTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.tmp = tempfile.TemporaryDirectory() + t = cls.tmp.name + cls.base = "file://" + os.path.join(t, "remotes") + "/" + cls.cache = os.path.join(t, "cache") + r = Remotes(os.path.join(t, "remotes")) + trusted, other = Key(t, "trusted"), Key(t, "other") + # Source repository: the base commit carries the trust anchor. + r.commit("aien-dev/demo", {".aien/verify.pub": (trusted.pub + "\n").encode(), + ".aien/always": b"# required\nG-ONE\n"}, "base") + c = [r.commit("aien-dev/demo", {"f": str(i).encode()}, f"c{i}") for i in range(6)] + good = bundle(trusted, "aien-dev/demo", c[0], [("G-ONE", "PASS"), ("G-TWO", "PASS")], "PASS") + fail = bundle(trusted, "aien-dev/demo", c[1], [("G-ONE", "FAIL")], "FAIL") + tampered = bundle(trusted, "aien-dev/demo", c[2], [("G-ONE", "FAIL")], "FAIL") + tampered["checks"][0]["verdict"], tampered["verdict"] = "PASS", "PASS" + alien = bundle(trusted, "aien-dev/demo", c[3], [("G-ONE", "PASS")], "PASS", signer=other) + missing = bundle(trusted, "aien-dev/demo", c[4], [("G-TWO", "PASS")], "PASS") + corrected = bundle(trusted, "aien-dev/demo", c[5], [("G-ONE", "PASS")], "PASS") + cls.good_bytes = rr.canonical(good) + cls.bundles = {} + files = {} + for name, b in (("good", good), ("fail", fail), ("tampered", tampered), ("alien", alien), + ("missing", missing), ("corrected", corrected)): + path = f"demo/{b['commit']}/bundle.json" + files[path] = rr.canonical(b) + cls.bundles[name] = path + files[f"demo/{c[5]}/bundle.correction.json"] = b"{}\n" + cls.shelf = r.commit("aien-dev/aien-receipts", files, "shelf") + # Omega receipts: source commits, then a shelf without and with corrections. + o1 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a;\n"}, "o1") + o2 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a2;\n"}, "o2") + cls.receipts = {"ok.json": receipt(o1), "mismatch.json": receipt(o2), "unresolved.json": receipt("f" * 40), + "unbound.json": receipt(o1), "nameless.json": receipt(o1, milestone=None, contract_id=None)} + cls.e1 = r.commit("aien-dev/omega-evidence", dict(cls.receipts), "receipts") + cls.e2 = r.commit("aien-dev/omega-evidence", { + "ok.correction.json": correction("ok.json", sha(cls.receipts["ok.json"])), + "unbound.correction.json": correction("unbound.json", "1" * 64)}, "corrections") + + @classmethod + def tearDownClass(cls): + cls.tmp.cleanup() + + def tool(self, *args, base=None, cache=None): + p = subprocess.run([sys.executable, TOOL, "--remote-base", base or self.base, "--cache", cache or self.cache, + *args], capture_output=True, text=True) + lines = p.stdout.strip().splitlines() + return p.returncode, (lines[-1] if lines else p.stderr.strip()), p.stdout + + def admit(self, eid, kind, repo, commit, path, source=None, issue=None, **where): + args = ["admit", "--kind", kind, "--shelf", f"{repo}@{commit}:{path}", "--id", eid] + if source: + args += ["--source-repo", source] + if issue is not None: + args += ["--issue-or-gate", issue] + rc, last, out = self.tool(*args, **where) + return rc, (json.loads(out) if rc == 0 else last) + + def index(self, *entries, **extra): + path = os.path.join(self.tmp.name, f"index-{len(os.listdir(self.tmp.name))}.json") + with open(path, "w") as f: + json.dump({"schema": rr.INDEX_SCHEMA, "index_version": 2, "entries": list(entries), **extra}, f) + return path + + def bundle_entry(self, name): + return self.admit(f"demo-{name}", "signed-bundle", "aien-dev/aien-receipts", self.shelf, self.bundles[name]) + + def omega_entry(self, path, shelf_commit, issue=None, **where): + return self.admit(f"omega-{path}", "omega-qualification-receipt", "aien-dev/omega-evidence", + shelf_commit, path, "aien-dev/omega-mv", issue, **where) + + # -- canonical encoder: golden cases from evidence.rs (aien-sovereign-core@c26f4d7a) + def test_canonical_sorts_keys_and_is_compact(self): + v = {"b": [1, True, None], "a": {"z": "x", "y": -3}} + self.assertEqual(rr.canonical(v), b'{"a":{"y":-3,"z":"x"},"b":[1,true,null]}') + + def test_canonical_escapes(self): + v = "a\"b\\c\nd\r\te\x1ff\x7f\xe9" + self.assertEqual(rr.canonical(v), '"a\\"b\\\\c\\nd\\r\\te\\u001ff\x7f\xe9"'.encode("utf-8")) + + def test_canonical_rejects_floats(self): + for v in ({"x": 1.5}, [0.0]): + with self.assertRaises(ValueError): + rr.canonical(v) + + def test_verdict_algebra(self): + self.assertEqual(rr.compute_verdict([("A", True, "run", "PASS"), ("B", False, "run", "FAIL")]), "PASS") + self.assertEqual(rr.compute_verdict([("A", True, "run", "PASS"), ("B", True, "run", "FAIL")]), "FAIL") + self.assertEqual(rr.compute_verdict([("A", True, "not_run", "NOT_RUN")]), "NOT_RUN") + + # -- signed bundles + def test_signed_pass_bundle_replays_pass(self): + rc, entry = self.bundle_entry("good") + self.assertEqual(rc, 0, entry) + self.assertEqual(set(entry), rr.ENTRY_FIELDS["signed-bundle"]) + self.assertEqual(entry["shelf"]["sha256"], sha(self.good_bytes)) + self.assertEqual(entry["issue_or_gate"], {"value": "aien-dev/demo required gates: G-ONE, G-TWO", + "basis": "bundle repository and the gate of every required check", + "verified": True}) + rc, last, out = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual((rc, last), (0, "REPLAY demo-good: PASS rc=0")) + self.assertIn("correction: none at the shelf commit or at shelf HEAD", out) + + def test_corrupted_copy_is_rejected(self): + rc, entry = self.bundle_entry("good") + corrupt = bytearray(self.good_bytes) + corrupt[corrupt.index(b'"verdict":"PASS"') + 11] ^= 0x01 + p = os.path.join(self.tmp.name, "corrupt.json") + with open(p, "wb") as f: + f.write(corrupt) + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"], "--bytes", p) + self.assertEqual(rc, 3) + self.assertIn("REJECTED DIGEST_MISMATCH", last) + + def test_authenticated_fail_bundle_replays_fail(self): + rc, entry = self.bundle_entry("fail") + self.assertEqual(rc, 0, entry) + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual((rc, last), (1, "REPLAY demo-fail: FAIL rc=1")) + + def test_tampered_bundle_bad_signature(self): + rc, last = self.bundle_entry("tampered") + self.assertEqual(rc, 3) + self.assertIn("BAD_SIGNATURE", last) + + def test_key_not_on_base_branch(self): + rc, last = self.bundle_entry("alien") + self.assertEqual(rc, 3) + self.assertIn("UNKNOWN_KEY", last) + + def test_missing_required_gate(self): + rc, last = self.bundle_entry("missing") + self.assertEqual(rc, 3) + self.assertIn("MISSING_REQUIRED_CHECK: G-ONE", last) + + def test_bundle_with_a_correction_file_is_rejected(self): + rc, last = self.bundle_entry("corrected") + self.assertEqual(rc, 3) + self.assertIn("CORRECTION_UNSUPPORTED", last) + + def test_kind_on_the_wrong_shelf_is_rejected(self): + rc, last = self.admit("x", "signed-bundle", "aien-dev/omega-evidence", self.e2, "ok.json") + self.assertEqual(rc, 3) + self.assertIn("SHELF_REPOSITORY", last) + + # -- omega receipts and correction precedence + def test_correction_supersedes_historical_pass(self): + self.assertEqual(sh("git", "-C", os.path.join(self.tmp.name, "remotes/aien-dev/omega-evidence"), + "show", f"{self.e2}:ok.json"), self.receipts["ok.json"]) + rc, entry = self.omega_entry("ok.json", self.e2) + self.assertEqual(rc, 0, entry) + self.assertEqual(set(entry), rr.ENTRY_FIELDS["omega-qualification-receipt"]) + self.assertEqual(entry["historical_verdict"], "QUALIFIED / PASS") + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual((rc, last), (4, "REPLAY omega-ok.json: REFUSED_UNSUPPORTED_PROVENANCE rc=4")) + # The commit before the correction is not admissible while the HEAD carries one. + rc, last = self.omega_entry("ok.json", self.e1) + self.assertEqual(rc, 3) + self.assertIn(f"REJECTED STALE_CORRECTION: ok.correction.json at aien-dev/omega-evidence HEAD {self.e2}", last) + + def test_index_that_misses_a_correction_drifts(self): + rc, entry = self.omega_entry("ok.json", self.e2) + stale = json.loads(json.dumps(entry)) + stale["correction"] = None + stale["effective_verdict"] = "PASS" + rc, last, _ = self.tool("replay", "--index", self.index(stale), stale["id"]) + self.assertEqual(rc, 3) + self.assertIn("INDEX_DRIFT", last) + self.assertIn("correction", last) + + def test_correction_landing_after_the_indexed_commit_fails(self): + # The index stays on the old commit while a correction lands one commit later. + root = os.path.join(self.tmp.name, "late") + where = {"base": "file://" + root + "/", "cache": os.path.join(self.tmp.name, "late-cache")} + r = Remotes(root) + o1 = r.commit("aien-dev/omega-mv", {"src/a.c": b"int a;\n"}, "o1") + data = receipt(o1) + s1 = r.commit("aien-dev/omega-evidence", {"late.json": data}, "receipt") + rc, entry = self.omega_entry("late.json", s1, **where) + self.assertEqual(rc, 0, entry) + index = self.index(entry) + rc, last, out = self.tool("replay", "--index", index, entry["id"], **where) + self.assertEqual((rc, last), (0, "REPLAY omega-late.json: PASS rc=0"), out) # positive control + s2 = r.commit("aien-dev/omega-evidence", {"late.correction.json": correction("late.json", sha(data))}, "corr") + rc, last, _ = self.tool("replay", "--index", index, entry["id"], **where) + self.assertEqual(rc, 3, last) + self.assertIn(f"REJECTED STALE_CORRECTION: late.correction.json at aien-dev/omega-evidence HEAD {s2} " + f"has sha256", last) + rc, last, _ = self.tool("replay", "--all", "--index", index, **where) + self.assertEqual(rc, 3, last) + self.assertTrue(last.endswith("0/1 entries reproduce as indexed rc=3"), last) + # Re-admitted at the HEAD, the correction decides. + rc, fresh = self.omega_entry("late.json", s2, **where) + self.assertEqual(rc, 0, fresh) + self.assertEqual(fresh["effective_verdict"], "REFUSED_UNSUPPORTED_PROVENANCE") + # A correction rewritten after the pinned commit fails the same way. + r.commit("aien-dev/omega-evidence", {"late.correction.json": correction("late.json", sha(data), "T-2")}, "c2") + rc, last, _ = self.tool("replay", "--index", self.index(fresh), fresh["id"], **where) + self.assertEqual(rc, 3, last) + self.assertIn("STALE_CORRECTION", last) + + def test_unbound_correction_is_rejected(self): + rc, last = self.omega_entry("unbound.json", self.e2) + self.assertEqual(rc, 3) + self.assertIn("CORRECTION_UNBOUND", last) + + def test_source_mismatch_is_refused(self): + rc, entry = self.omega_entry("mismatch.json", self.e1) + self.assertEqual(rc, 0, entry) + self.assertEqual(entry["source"]["artifacts"][1]["at_source_commit"], "mismatch") + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual((rc, last), (4, "REPLAY omega-mismatch.json: REFUSED_SOURCE_PROVENANCE rc=4")) + + def test_unresolved_source_commit_is_refused(self): + rc, entry = self.omega_entry("unresolved.json", self.e1) + self.assertEqual(rc, 0, entry) + self.assertFalse(entry["source"]["commit_resolves"]) + self.assertEqual(entry["effective_verdict"], "REFUSED_SOURCE_PROVENANCE") + + # -- issue_or_gate and unknown fields + def test_edited_issue_or_gate_fails(self): + rc, entry = self.omega_entry("mismatch.json", self.e1) + self.assertEqual(entry["issue_or_gate"], OMEGA_ISSUE) + for edit in ({"value": "hardware qualified on GB10"}, + {"basis": rr.UNVERIFIED_ISSUE_BASIS, "verified": False}): + edited = json.loads(json.dumps(entry)) + edited["issue_or_gate"].update(edit) + rc, last, _ = self.tool("replay", "--index", self.index(edited), edited["id"]) + self.assertEqual(rc, 3, last) + self.assertTrue(last.endswith("INDEX_DRIFT: recomputed fields differ from the index: issue_or_gate rc=3"), + last) + + def test_unknown_entry_field_fails(self): + rc, entry = self.bundle_entry("good") + entry["qualification"] = "hardware qualified on GB10" + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual(rc, 3, last) + self.assertIn("REJECTED UNKNOWN_FIELD", last) + self.assertIn("qualification", last) + + def test_unknown_index_field_fails(self): + rc, entry = self.bundle_entry("good") + rc, last, _ = self.tool("replay", "--all", "--index", self.index(entry, hardware="qualified on GB10")) + self.assertEqual(rc, 3, last) + self.assertIn("REJECTED", last) + self.assertIn("UNKNOWN_FIELD", last) + + def test_edited_replay_command_fails(self): + rc, entry = self.bundle_entry("good") + entry["replay"] = "true" + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual(rc, 3, last) + self.assertIn("INDEX_DRIFT", last) + + def test_issue_not_in_receipt_is_marked_unverified(self): + rc, last = self.omega_entry("nameless.json", self.e2) + self.assertEqual(rc, 3) + self.assertIn("names no issue or gate", last) + rc, entry = self.omega_entry("nameless.json", self.e2, issue="DRA-0 test gate") + self.assertEqual(rc, 0, entry) + self.assertEqual(entry["issue_or_gate"], {"value": "DRA-0 test gate", "basis": rr.UNVERIFIED_ISSUE_BASIS, + "verified": False}) + rc, last, out = self.tool("replay", "--index", self.index(entry), entry["id"]) + self.assertEqual((rc, last), (0, "REPLAY omega-nameless.json: PASS rc=0 issue_or_gate=UNVERIFIED")) + self.assertIn("issue_or_gate: UNVERIFIED", out) + # A receipt that names its own issue does not take operator text. + rc, last = self.omega_entry("ok.json", self.e2, issue="DRA-0 test gate") + self.assertEqual(rc, 2) + self.assertIn("drop the option", last) + + # -- whole index and unreachable inputs + def test_replay_all(self): + entries = [self.bundle_entry("good")[1], self.bundle_entry("fail")[1], self.omega_entry("ok.json", self.e2)[1]] + rc, last, _ = self.tool("replay", "--all", "--index", self.index(*entries)) + self.assertEqual(rc, 0, last) + self.assertTrue(last.endswith("3/3 entries reproduce as indexed rc=0"), last) + + def test_unreachable_remote_is_not_run(self): + rc, entry = self.bundle_entry("good") + rc, last, _ = self.tool("replay", "--index", self.index(entry), entry["id"], + base="file://" + os.path.join(self.tmp.name, "nowhere") + "/") + self.assertEqual(rc, 2) + self.assertIn("NOT_RUN cannot reach", last) + + +class ShippedIndexTests(unittest.TestCase): + """Structure of index/receipt_index.json; replaying it needs the network (docs/receipt-index.md).""" + + def test_shipped_index_shape(self): + idx = rr.load_index(rr.DEFAULT_INDEX) + self.assertEqual(idx["index_version"], 2) + for e in idx["entries"]: + self.assertEqual(set(e), rr.ENTRY_FIELDS[e["kind"]]) + self.assertNotIn(":", e["id"]) + self.assertEqual(e["shelf"]["repository"], rr.SHELF_REPOS[e["kind"]]) + self.assertEqual(e["replay"], rr.replay_command(e["id"])) + self.assertTrue(rr.is_hex(e["shelf"]["sha256"], 64) and rr.is_hex(e["shelf"]["commit"], 40)) + self.assertTrue(e["issue_or_gate"]["verified"], e["id"]) + self.assertIn(rr.exit_for(e["effective_verdict"]), (0, 1, 4)) + c = e["correction"] + if c and c["supersedes_historical_status_for_admission"]: + self.assertEqual(e["effective_verdict"], c["qualification_claim"]) + + def test_shipped_index_refuses_m8_and_m9(self): + idx = rr.load_index(rr.DEFAULT_INDEX) + by_id = {e["id"]: e for e in idx["entries"]} + for m in ("omega-evidence/M8", "omega-evidence/M9"): + self.assertEqual(by_id[m]["historical_verdict"], "QUALIFIED / PASS") + self.assertEqual(by_id[m]["effective_verdict"], "REFUSED_UNSUPPORTED_PROVENANCE") + + def test_shipped_m4_issue_comes_from_the_receipt(self): + by_id = {e["id"]: e for e in rr.load_index(rr.DEFAULT_INDEX)["entries"]} + self.assertEqual(by_id["omega-evidence/M4"]["issue_or_gate"]["value"], + "Omega MILESTONE 4 — OMEGA_SEMANTICS qualification (CONTRACT-OMEGA-SEMANTICS-M4)") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/replay_receipt.py b/tools/replay_receipt.py new file mode 100755 index 0000000..74fd5e0 --- /dev/null +++ b/tools/replay_receipt.py @@ -0,0 +1,695 @@ +#!/usr/bin/env python3 +"""Admit and replay receipts listed in index/receipt_index.json (DRA-167). + +`admit` computes one index entry live from pinned commits. `replay` fetches an +indexed entry again by its pinned commits, checks the shelf bytes against the +recorded SHA-256, recomputes every other field (correction precedence, bundle +signature and trust anchor, source provenance, issue_or_gate) and compares it +with the index. Both also read the current HEAD of the shelf repository and +refuse an entry when the correction file there differs from the one at the +pinned commit, and replay refuses any entry or index field it does not know. +The last line printed is the verdict. Rules: docs/receipt-index.md. + +Exit codes for one entry: 0 PASS, 1 FAIL (an authenticated FAIL verdict), +2 NOT_RUN (an input could not be reached, or a usage error), 3 REJECTED (bytes, +signature, binding, correction binding, a newer correction at the shelf HEAD, +an unknown field or index drift), 4 REFUSED (admission refused by a shelf +correction or by the source-provenance check). +`replay --all` exits 0 only when every entry reproduces exactly as indexed. + +Needs Python 3, Git and OpenSSL 3 (Ed25519). Repository convention: the only +other tooling in this repository (audit/tools) is Python with unittest. +""" +import argparse +import hashlib +import json +import os +import subprocess +import sys +import tempfile + +INDEX_SCHEMA = "aien.receipt-index.v2" +BUNDLE_SCHEMA = "aien-verification-bundle/1" +CORRECTION_SCHEMA = "aien.omega-evidence.receipt-correction.v1" +SHELF_OWNER = "aien-dev" +# Each kind lives on exactly one shelf; the index cannot point a kind elsewhere. +SHELF_REPOS = {"signed-bundle": "aien-dev/aien-receipts", "omega-qualification-receipt": "aien-dev/omega-evidence"} +KINDS = tuple(SHELF_REPOS) +# Every field an index may carry. Replay rejects anything else (UNKNOWN_FIELD / SCHEMA). +INDEX_FIELDS = {"schema", "index_version", "issue", "generated_by", "independence", "admission_check", + "precedence", "exit_codes", "scope", "excluded", "generated_utc", "entries"} +_ENTRY_COMMON = {"id", "kind", "issue_or_gate", "shelf", "source", "correction", "historical_verdict", + "effective_verdict", "effective_basis", "replay"} +ENTRY_FIELDS = {"signed-bundle": _ENTRY_COMMON | {"trust_anchor", "signature", "gates"}, + "omega-qualification-receipt": _ENTRY_COMMON} +# Effective basis of a signed bundle. Taken on trust: see docs/receipt-index.md, "Values taken on trust". +BUNDLE_BASIS = "authenticated bundle verdict (this shelf has no correction records)" +UNVERIFIED_ISSUE_BASIS = "UNVERIFIED: not derivable from the receipt; text supplied at admission" +EXIT = {"PASS": 0, "FAIL": 1, "NOT_RUN": 2, "REJECTED": 3, "REFUSED": 4} +# DER SubjectPublicKeyInfo prefix for a raw 32-byte Ed25519 public key. +SPKI_ED25519 = bytes.fromhex("302a300506032b6570032100") +# Bundle vocabulary of aien-sovereign-core@c26f4d7a tools/aien-test/src/bundle.rs. +STATUSES = ("run", "cached", "not_run", "blocked") +VERDICTS = ("PASS", "FAIL", "NOT_RUN", "BLOCKED_HARDWARE", "BLOCKED_OPERATOR", "MISSING_IMPLEMENTATION") +EXACTNESS = ("EXACT", "BOUNDED", "APPROXIMATE", "ADVISORY") +RECEIPT_ID_SCHEMES = ("sha256-canonical-json", "aien-proof-blake3") +# Omega receipts name their implementation commit in one of these fields, first match wins. +SOURCE_COMMIT_FIELDS = ("qualified_implementation_commit", "git_commit") +ADMITTED_HISTORICAL_STATUS = "QUALIFIED / PASS" +DEFAULT_INDEX = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "index", "receipt_index.json") + + +class Rejected(Exception): + def __init__(self, code, detail): + super().__init__(f"{code}: {detail}") + self.code = code + + +class NotRun(Exception): + pass + + +def sha256(data): + return hashlib.sha256(data).hexdigest() + + +def is_hex(s, n): + return isinstance(s, str) and len(s) == n and all(c in "0123456789abcdef" for c in s) + + +# ------------------------------------------------------------- canonical JSON +# Port of evidence::canonical (aien-sovereign-core@c26f4d7a): sorted keys by +# UTF-8 bytes, compact, integers only, minimal escapes. + +def _canon_str(s, out): + out.append('"') + for ch in s: + if ch == '"': + out.append('\\"') + elif ch == "\\": + out.append("\\\\") + elif ch == "\n": + out.append("\\n") + elif ch == "\r": + out.append("\\r") + elif ch == "\t": + out.append("\\t") + elif ord(ch) < 0x20: + out.append("\\u%04x" % ord(ch)) + else: + out.append(ch) + out.append('"') + + +def _canon_val(v, out): + if v is None: + out.append("null") + elif v is True: + out.append("true") + elif v is False: + out.append("false") + elif isinstance(v, int): + if not -(1 << 63) <= v < (1 << 64): + raise ValueError(f"integer out of range: {v}") + out.append(str(v)) + elif isinstance(v, float): + raise ValueError(f"floating point not allowed: {v!r}") + elif isinstance(v, str): + _canon_str(v, out) + elif isinstance(v, list): + out.append("[") + for i, x in enumerate(v): + if i: + out.append(",") + _canon_val(x, out) + out.append("]") + elif isinstance(v, dict): + out.append("{") + for i, k in enumerate(sorted(v, key=lambda k: k.encode("utf-8"))): + if i: + out.append(",") + _canon_str(k, out) + out.append(":") + _canon_val(v[k], out) + out.append("}") + else: + raise ValueError(f"not a JSON value: {type(v).__name__}") + + +def canonical(v): + out = [] + _canon_val(v, out) + return "".join(out).encode("utf-8") + + +def parse_json(raw, what): + def no_dupes(pairs): + d = {} + for k, v in pairs: + if k in d: + raise ValueError(f"duplicate key {k!r}") + d[k] = v + return d + + def no_constant(name): + raise ValueError(f"non-JSON constant {name}") + + try: + return json.loads(raw.decode("utf-8"), object_pairs_hook=no_dupes, parse_constant=no_constant) + except (UnicodeDecodeError, ValueError) as e: + raise Rejected("SCHEMA", f"{what} is not valid JSON: {e}") + + +# ------------------------------------------------------------- git fetching + +class Git: + """Blobless, shallow fetches of exact commits into a local cache.""" + + def __init__(self, cache, remote_base): + self.cache = cache + self.base = remote_base.rstrip("/") + "/" + self.heads = {} # repository -> HEAD commit, read once per run by ls-remote + + def _git(self, d, *args): + try: + return subprocess.run(["git", "-C", d, *args], capture_output=True) + except FileNotFoundError: + raise NotRun("git is not installed") + + def _repo(self, repository): + d = os.path.join(self.cache, repository.replace("/", "__") + ".git") + if not os.path.isdir(d): + os.makedirs(d) + for args in (("init", "-q", "--bare"), + ("remote", "add", "origin", self.base + repository), + ("config", "remote.origin.promisor", "true"), + ("config", "remote.origin.partialclonefilter", "blob:none")): + if self._git(d, *args).returncode: + raise NotRun(f"cannot initialise cache {d}") + if repository not in self.heads: + # A reused cache must still talk to the remote named on this run. + if self._git(d, "remote", "set-url", "origin", self.base + repository).returncode: + raise NotRun(f"cannot configure cache {d}") + r = self._git(d, "ls-remote", "origin", "HEAD") + if r.returncode: + raise NotRun(f"cannot reach {self.base + repository}: {_last(r.stderr)}") + head = r.stdout.decode().split("\t", 1)[0].strip() + if not is_hex(head, 40): + raise NotRun(f"{self.base + repository} reports no HEAD commit") + self.heads[repository] = head + return d + + def head(self, repository): + """The commit the remote's HEAD names at the moment this run first reached it.""" + self._repo(repository) + return self.heads[repository] + + def _present(self, d, commit, depth): + if self._git(d, "cat-file", "-e", commit + "^{commit}").returncode: + return False + return depth == 1 or self._git(d, "rev-parse", "--verify", "-q", commit + "^1^{commit}").returncode == 0 + + def has_commit(self, repository, commit, depth=1): + """True if the commit exists upstream; False only on an explicit 'not our ref'.""" + if not is_hex(commit, 40): + return False + d = self._repo(repository) + if self._present(d, commit, depth): + return True + r = self._git(d, "fetch", "-q", f"--depth={depth}", "--filter=blob:none", "origin", commit) + if r.returncode == 0: + return self._git(d, "cat-file", "-e", commit + "^{commit}").returncode == 0 + if b"not our ref" in r.stderr or b"couldn't find remote ref" in r.stderr: + return False + raise NotRun(f"cannot fetch {repository}@{commit}: {_last(r.stderr)}") + + def read(self, repository, commit, path): + """Bytes of path at commit, or None when the path is absent there.""" + if not self.has_commit(repository, commit): + raise Rejected("COMMIT_ABSENT", f"{repository}@{commit} does not exist upstream") + d = self._repo(repository) + tree = self._git(d, "ls-tree", "--name-only", commit, "--", path) + if tree.returncode: + raise NotRun(f"cannot list {repository}@{commit}: {_last(tree.stderr)}") + if tree.stdout.decode().strip() != path: + return None + blob = self._git(d, "cat-file", "blob", f"{commit}:{path}") + if blob.returncode: + raise NotRun(f"cannot fetch {repository}@{commit}:{path}: {_last(blob.stderr)}") + return blob.stdout + + def first_parent(self, repository, commit): + if not self.has_commit(repository, commit, depth=2): + raise Rejected("COMMIT_ABSENT", f"{repository}@{commit} does not exist upstream") + r = self._git(self._repo(repository), "rev-parse", "--verify", "-q", commit + "^1") + return r.stdout.decode().strip() if r.returncode == 0 else None + + +def _last(stderr): + lines = stderr.decode(errors="replace").strip().splitlines() + return lines[-1] if lines else "no diagnostic" + + +# ------------------------------------------------------------- signed bundles + +def ed25519_verify(pubkey_hex, sig_hex, message): + with tempfile.TemporaryDirectory() as t: + paths = {n: os.path.join(t, n) for n in ("pub.der", "sig.bin", "msg.bin")} + for name, data in (("pub.der", SPKI_ED25519 + bytes.fromhex(pubkey_hex)), + ("sig.bin", bytes.fromhex(sig_hex)), ("msg.bin", message)): + with open(paths[name], "wb") as f: + f.write(data) + try: + r = subprocess.run(["openssl", "pkeyutl", "-verify", "-pubin", "-keyform", "DER", + "-inkey", paths["pub.der"], "-rawin", "-in", paths["msg.bin"], + "-sigfile", paths["sig.bin"]], capture_output=True) + except FileNotFoundError: + raise NotRun("openssl is not installed") + if r.returncode == 0 and b"Signature Verified Successfully" in r.stdout: + return True + if r.returncode == 1 and b"Signature Verification Failure" in r.stdout: + return False + raise NotRun(f"openssl could not run the Ed25519 check: {_last(r.stderr)}") + + +def _schema(cond, detail): + if not cond: + raise Rejected("SCHEMA", detail) + + +def validate_bundle(b): + """Shape check of bundle.rs validate(); returns [(gate, required, status, verdict)].""" + _schema(isinstance(b, dict), "bundle must be an object") + _schema(b.get("schema") == BUNDLE_SCHEMA, f"schema must be {BUNDLE_SCHEMA}") + _schema(isinstance(b.get("repository"), str), "repository must be a string") + for k, n in (("commit", 40), ("tree_digest", 64), ("graph_digest", 64)): + _schema(is_hex(b.get(k), n), f"{k} must be {n} lower-case hex characters") + _schema(b.get("receipt_id_scheme") in RECEIPT_ID_SCHEMES, "receipt_id_scheme is not allowed") + _schema(b.get("verdict") in ("PASS", "FAIL", "NOT_RUN"), "verdict is not allowed") + for k in ("started_utc", "finished_utc"): + _schema(isinstance(b.get(k), str), f"{k} must be a string") + ex = b.get("executor") + _schema(isinstance(ex, dict) and is_hex(ex.get("id"), 64) and isinstance(ex.get("class"), str) + and is_hex(ex.get("machine_digest"), 64), "executor is malformed") + checks = b.get("checks") + _schema(isinstance(checks, list), "checks must be an array") + entries = [] + for i, c in enumerate(checks): + _schema(isinstance(c, dict), f"checks[{i}] must be an object") + gate = c.get("gate") + _schema(isinstance(gate, str), f"checks[{i}].gate must be a string") + _schema(is_hex(c.get("check_id"), 64), f"checks[{i}].check_id malformed") + _schema(c.get("exactness") in EXACTNESS, f"checks[{i}].exactness not allowed") + _schema(isinstance(c.get("required"), bool), f"checks[{i}].required must be a bool") + _schema(not (c["required"] and c["exactness"] == "ADVISORY"), f"checks[{i}] ADVISORY cannot be required") + _schema(c.get("status") in STATUSES, f"checks[{i}].status not allowed") + _schema(c.get("verdict") in VERDICTS, f"checks[{i}].verdict not allowed") + _schema(isinstance(c.get("backend"), str), f"checks[{i}].backend must be a string") + if c["status"] == "run": + _schema(is_hex(c.get("receipt"), 64), f"checks[{i}].receipt malformed") + elif c["status"] == "cached": + r = c.get("resolution") + _schema(isinstance(r, dict) and is_hex(r.get("resolved_from"), 64), f"checks[{i}].resolution malformed") + else: + _schema(c["verdict"] != "PASS", f"checks[{i}] status {c['status']} cannot carry PASS") + entries.append((gate, c["required"], c["status"], c["verdict"])) + gates = [e[0] for e in entries] + _schema(len(gates) == len(set(gates)), "checks[] lists a gate twice") + return entries + + +def compute_verdict(entries): + required = [e for e in entries if e[1]] + if any(e[3] == "FAIL" for e in required): + return "FAIL" + if all(e[2] in ("run", "cached") and e[3] == "PASS" for e in required): + return "PASS" + return "NOT_RUN" + + +def evaluate_bundle(git, shelf, raw, craw): + parts = shelf["path"].split("/") + if len(parts) != 3 or parts[2] != "bundle.json" or not is_hex(parts[1], 40): + raise Rejected("PATH_BINDING", f"{shelf['path']} is not //bundle.json") + if craw is not None: + # BUNDLE_BASIS asserts that this shelf has no correction records; refuse rather than ignore one. + raise Rejected("CORRECTION_UNSUPPORTED", f"{correction_path(shelf['path'])} exists; bundle corrections" + " have no admission rule yet") + source = {"repository": f"{SHELF_OWNER}/{parts[0]}", "commit": parts[1]} + b = parse_json(raw, shelf["path"]) + entries = validate_bundle(b) + sig = b.get("signature") + _schema(isinstance(sig, dict) and sig.get("alg") == "ed25519", "signature.alg must be ed25519") + _schema(is_hex(sig.get("pubkey"), 64) and is_hex(sig.get("sig"), 128), "signature members malformed") + base = git.first_parent(source["repository"], source["commit"]) + if base is None: + raise Rejected("NO_TRUST_ANCHOR", f"{source['commit']} has no parent to read .aien/ from") + pub = git.read(source["repository"], base, ".aien/verify.pub") + always = git.read(source["repository"], base, ".aien/always") + if pub is None or always is None: + raise Rejected("NO_TRUST_ANCHOR", f"{source['repository']}@{base} lacks .aien/verify.pub or .aien/always") + pub = pub.decode().strip() + _schema(is_hex(pub, 64), ".aien/verify.pub must be 64 hex characters") + required = [ln.strip() for ln in always.decode().splitlines() if ln.strip() and not ln.startswith("#")] + # verify() order in bundle.rs: key known, signature, repository, commit, executor, required, verdict. + if sig["pubkey"] != pub: + raise Rejected("UNKNOWN_KEY", "bundle key is not the base-branch .aien/verify.pub") + try: + message = canonical({k: v for k, v in b.items() if k != "signature"}) + except ValueError as e: + raise Rejected("SCHEMA", f"not canonical-encodable: {e}") + if not ed25519_verify(pub, sig["sig"], message): + raise Rejected("BAD_SIGNATURE", "signature does not verify over the canonical bytes") + if b["repository"] != "github.com/" + source["repository"]: + raise Rejected("REPOSITORY_MISMATCH", f"bundle {b['repository']}, shelf path {source['repository']}") + if b["commit"] != source["commit"]: + raise Rejected("COMMIT_MISMATCH", f"bundle {b['commit']}, shelf path {source['commit']}") + if b["executor"]["id"] != sha256(bytes.fromhex(pub)): + raise Rejected("UNKNOWN_EXECUTOR", "executor.id is not sha256(verify.pub)") + for g in required: + found = [e for e in entries if e[0] == g] + if not found: + raise Rejected("MISSING_REQUIRED_CHECK", g) + if not found[0][1]: + raise Rejected("SCHEMA", f"{g} is required by the gate but marked optional in the bundle") + computed = compute_verdict(entries) + if computed != b["verdict"]: + raise Rejected("VERDICT_INCONSISTENT", f"declared {b['verdict']}, computed {computed}") + gates = [e[0] for e in entries if e[1]] + return { + "issue_or_gate": {"value": f"{source['repository']} required gates: {', '.join(gates) or 'none'}", + "basis": "bundle repository and the gate of every required check", "verified": True}, + "source": source, + "trust_anchor": {"repository": source["repository"], "commit": base, + "rule": "first parent of the source commit", "verify_pub": pub, "always": required}, + "signature": "VERIFIED (OpenSSL Ed25519 over canonical bytes without the signature member)", + "gates": [{k: c[k] for k in ("gate", "backend", "exactness", "required", "status", "verdict")} + for c in b["checks"]], + "correction": None, + "historical_verdict": b["verdict"], + "effective_verdict": b["verdict"], + "effective_basis": BUNDLE_BASIS, + } + + +# ------------------------------------------------------------- omega receipts + +def omega_issue_or_gate(d): + """Issue or gate named by the receipt itself, or None when the receipt names none.""" + milestone, contract = d.get("milestone"), d.get("contract_id") + if not isinstance(milestone, str) or not milestone.strip(): + return None + if isinstance(contract, str) and contract.strip(): + return {"value": f"Omega {milestone} qualification ({contract})", + "basis": "receipt fields milestone and contract_id", "verified": True} + return {"value": f"Omega {milestone} qualification", "basis": "receipt field milestone", "verified": True} + + +def evaluate_omega(git, shelf, raw, source_repository, craw): + d = parse_json(raw, shelf["path"]) + _schema(isinstance(d, dict), "receipt must be an object") + # The receipts do not name their source repository; it is taken from the index (docs, "Values taken on trust"). + _schema(isinstance(source_repository, str) and source_repository.startswith(SHELF_OWNER + "/") + and source_repository.count("/") == 1, f"source.repository must be {SHELF_OWNER}/") + historical = d.get("status") + if historical != ADMITTED_HISTORICAL_STATUS: + raise Rejected("UNSUPPORTED_STATUS", f"status {historical!r} is not {ADMITTED_HISTORICAL_STATUS!r}") + correction = None + if craw is not None: + cpath = correction_path(shelf["path"]) + c = parse_json(craw, cpath) + _schema(isinstance(c, dict) and c.get("schema") == CORRECTION_SCHEMA, f"{cpath} schema") + corr = c.get("corrects") or {} + if (corr.get("repository"), corr.get("path"), corr.get("sha256")) != ( + shelf["repository"], shelf["path"], sha256(raw)): + raise Rejected("CORRECTION_UNBOUND", f"{cpath} does not name these receipt bytes") + disp = c.get("disposition") or {} + _schema(isinstance(disp.get("supersedes_historical_status_for_admission"), bool) + and isinstance(disp.get("qualification_claim"), str), f"{cpath} disposition malformed") + correction = {"path": cpath, "sha256": sha256(craw), "correction_id": c.get("correction_id"), + "recorded_on": c.get("recorded_on"), + "supersedes_historical_status_for_admission": + disp["supersedes_historical_status_for_admission"], + "qualification_claim": disp["qualification_claim"]} + field = next((f for f in SOURCE_COMMIT_FIELDS if is_hex(d.get(f), 40)), None) + commit = d[field] if field else None + resolves = bool(commit) and git.has_commit(source_repository, commit) + artifacts = [] + arts = d.get("artifacts") if isinstance(d.get("artifacts"), dict) else {} + for path in sorted(arts): + v = arts[path] + digest = v.get("sha256") if isinstance(v, dict) else None + if not is_hex(digest, 64): + result = "no-digest" + elif path.startswith("build/"): + result = "not-recoverable (build output)" + elif not resolves: + result = "commit-unresolved" + else: + src = git.read(source_repository, commit, path) + result = "absent" if src is None else ("match" if sha256(src) == digest else "mismatch") + artifacts.append({"path": path, "sha256": digest, "at_source_commit": result}) + source_ok = (resolves and any(a["at_source_commit"] == "match" for a in artifacts) + and all(a["at_source_commit"] in ("match", "not-recoverable (build output)", "no-digest") + for a in artifacts)) + rc = d.get("receipt_commit") + receipt_commit = {"value": rc, "resolves": git.has_commit(source_repository, rc) if is_hex(rc, 40) else None} + if correction and correction["supersedes_historical_status_for_admission"]: + effective, basis = correction["qualification_claim"], f"shelf correction {correction['correction_id']}" + elif not source_ok: + effective, basis = "REFUSED_SOURCE_PROVENANCE", "index source check (no superseding shelf correction)" + else: + effective, basis = "PASS", "historical status; named source commit resolves and source digests match" + return { + "issue_or_gate": omega_issue_or_gate(d), + "source": {"repository": source_repository, "commit_field": field, "commit": commit, + "commit_resolves": resolves, "receipt_commit": receipt_commit, "artifacts": artifacts, + "source_check": "PASS" if source_ok else "FAIL"}, + "correction": correction, + "historical_verdict": historical, + "effective_verdict": effective, + "effective_basis": basis, + } + + +# ------------------------------------------------------------- admit / replay + +def correction_path(path): + return path[:-len(".json")] + ".correction.json" + + +def evaluate(git, kind, shelf_loc, source_repository, raw, stated_issue=None): + """Recompute an entry. stated_issue is used only when the receipt names no issue or gate.""" + if kind not in KINDS: + raise Rejected("SCHEMA", f"unknown kind {kind!r}") + repo, commit, path = shelf_loc["repository"], shelf_loc["commit"], shelf_loc["path"] + if repo != SHELF_REPOS[kind]: + raise Rejected("SHELF_REPOSITORY", f"{kind} receipts live in {SHELF_REPOS[kind]}, not {repo}") + _schema(isinstance(path, str) and path.endswith(".json"), "shelf.path must name a .json file") + shelf = {"repository": repo, "commit": commit, "path": path, "sha256": sha256(raw), "bytes": len(raw)} + # A correction may land after the pinned commit. The one at the shelf HEAD must be the one pinned. + cpath = correction_path(path) + craw = git.read(repo, commit, cpath) + head = git.head(repo) + at_head = craw if head == commit else git.read(repo, head, cpath) + if at_head != craw: + state = "is absent" if at_head is None else f"has sha256 {sha256(at_head)}" + pinned = "absent" if craw is None else f"sha256 {sha256(craw)}" + raise Rejected("STALE_CORRECTION", f"{cpath} at {repo} HEAD {head} {state}; at the indexed commit " + f"{commit} it is {pinned}. Re-admit the entry at the HEAD") + if kind == "signed-bundle": + out = evaluate_bundle(git, shelf, raw, craw) + else: + out = evaluate_omega(git, shelf, raw, source_repository, craw) + if out["issue_or_gate"] is None: + if not isinstance(stated_issue, str) or not stated_issue.strip(): + raise Rejected("SCHEMA", "the receipt names no issue or gate; supply one (it is recorded UNVERIFIED)") + out["issue_or_gate"] = {"value": stated_issue, "basis": UNVERIFIED_ISSUE_BASIS, "verified": False} + return {"kind": kind, "shelf": shelf, **out} + + +def fetch_shelf(git, shelf_loc): + raw = git.read(shelf_loc["repository"], shelf_loc["commit"], shelf_loc["path"]) + if raw is None: + raise Rejected("SHELF_PATH_ABSENT", f"{shelf_loc['path']} absent at {shelf_loc['repository']}@{shelf_loc['commit']}") + return raw + + +def exit_for(effective): + if effective in ("PASS", "FAIL", "NOT_RUN"): + return EXIT[effective] + if effective.startswith("REFUSED"): + return EXIT["REFUSED"] + return EXIT["NOT_RUN"] + + +def replay_command(eid): + return f"python3 tools/replay_receipt.py replay {eid}" + + +def replay_entry(git, entry, override=None): + """Returns (rc, last line, reproduced). Prints the evidence lines before it.""" + eid = entry.get("id", "?") + try: + kind = entry.get("kind") + if kind not in KINDS: + raise Rejected("SCHEMA", f"unknown kind {kind!r}") + unknown = sorted(set(entry) - ENTRY_FIELDS[kind]) + if unknown: + raise Rejected("UNKNOWN_FIELD", "the index entry carries fields this tool does not check: " + + ", ".join(unknown)) + if not isinstance(eid, str) or not eid or ":" in eid: + raise Rejected("SCHEMA", "id must be a non-empty string without ':'") + if entry.get("replay") != replay_command(eid): + raise Rejected("INDEX_DRIFT", "recomputed fields differ from the index: replay") + shelf = entry.get("shelf") + _schema(isinstance(shelf, dict) and all(isinstance(shelf.get(k), str) for k in + ("repository", "commit", "path", "sha256")), "shelf malformed") + print(f"entry: {eid} ({kind})") + if override is not None: + with open(override, "rb") as f: + raw = f.read() + print(f"shelf: local override {override} (not fetched)") + else: + raw = fetch_shelf(git, shelf) + print(f"shelf: fetched {shelf['repository']}@{shelf['commit']}:{shelf['path']}") + got = sha256(raw) + print(f"digest: sha256={got} expected={shelf['sha256']}") + if got != shelf["sha256"]: + raise Rejected("DIGEST_MISMATCH", f"sha256 {got} != indexed {shelf['sha256']}") + issue = entry.get("issue_or_gate") + computed = evaluate(git, kind, shelf, (entry.get("source") or {}).get("repository"), raw, + issue.get("value") if isinstance(issue, dict) else None) + drift = sorted(k for k in computed if computed[k] != entry.get(k)) + if drift: + raise Rejected("INDEX_DRIFT", "recomputed fields differ from the index: " + ", ".join(drift)) + i = computed["issue_or_gate"] + if i["verified"]: + print(f"issue_or_gate: derived from the {i['basis']}: {i['value']}") + else: + print(f"issue_or_gate: UNVERIFIED (index text; the receipt names no issue or gate): {i['value']}") + if computed.get("signature"): + print(f"signature: {computed['signature']}; key from {computed['trust_anchor']['repository']}" + f"@{computed['trust_anchor']['commit']}:.aien/verify.pub") + head = git.head(shelf["repository"]) + if computed["correction"]: + c = computed["correction"] + print(f"correction: {c['path']} sha256={c['sha256']} supersedes={c['supersedes_historical_status_for_admission']}" + f" claim={c['qualification_claim']}; identical at shelf HEAD {head}") + else: + print(f"correction: none at the shelf commit or at shelf HEAD {head}") + if kind == "omega-qualification-receipt": + s = computed["source"] + print(f"source: {s['repository']}@{s['commit']} resolves={s['commit_resolves']} source_check={s['source_check']}" + " (repository taken from the index: the receipt does not name it)") + eff = computed["effective_verdict"] + print(f"historical: {computed['historical_verdict']}; effective basis: {computed['effective_basis']}") + rc = exit_for(eff) + mark = "" if i["verified"] else " issue_or_gate=UNVERIFIED" + return rc, f"REPLAY {eid}: {eff} rc={rc}{mark}", True + except Rejected as e: + return EXIT["REJECTED"], f"REPLAY {eid}: REJECTED {e} rc={EXIT['REJECTED']}", False + except NotRun as e: + return EXIT["NOT_RUN"], f"REPLAY {eid}: NOT_RUN {e} rc={EXIT['NOT_RUN']}", False + + +def load_index(path): + with open(path, "rb") as f: + idx = parse_json(f.read(), path) + if not isinstance(idx, dict) or idx.get("schema") != INDEX_SCHEMA or not isinstance(idx.get("entries"), list): + raise Rejected("SCHEMA", f"{path} is not an {INDEX_SCHEMA} index") + unknown = sorted(set(idx) - INDEX_FIELDS) + if unknown: + raise Rejected("UNKNOWN_FIELD", f"{path} carries index fields this tool does not know: " + ", ".join(unknown)) + if not isinstance(idx.get("index_version"), int) or not all(isinstance(e, dict) for e in idx["entries"]): + raise Rejected("SCHEMA", f"{path}: index_version must be an integer and every entry an object") + ids = [e.get("id") for e in idx["entries"]] + if len(ids) != len(set(ids)): + raise Rejected("SCHEMA", f"{path} repeats an entry id") + return idx + + +def parse_shelf_arg(s): + try: + repo_commit, path = s.split(":", 1) + repository, commit = repo_commit.split("@", 1) + except ValueError: + raise SystemExit("--shelf must be OWNER/REPO@COMMIT:PATH") + return {"repository": repository, "commit": commit, "path": path} + + +def main(argv=None): + ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + ap.add_argument("--cache", help="git object cache directory (default: a fresh temporary directory)") + ap.add_argument("--remote-base", default="https://github.com/", help="prefix for OWNER/REPO fetch URLs") + sub = ap.add_subparsers(dest="cmd", required=True) + r = sub.add_parser("replay", help="replay indexed entries") + r.add_argument("id", nargs="?") + r.add_argument("--all", action="store_true") + r.add_argument("--index", default=DEFAULT_INDEX) + r.add_argument("--bytes", help="replay these local bytes instead of the fetched shelf file (controls)") + a = sub.add_parser("admit", help="compute a new index entry from pinned commits") + a.add_argument("--kind", required=True, choices=KINDS) + a.add_argument("--shelf", required=True, help="OWNER/REPO@COMMIT:PATH") + a.add_argument("--source-repo", help="implementation repository (omega-qualification-receipt)") + a.add_argument("--id", required=True, help="entry id (no ':' characters)") + a.add_argument("--issue-or-gate", help="issue or gate, only for a receipt that names none (recorded UNVERIFIED)") + args = ap.parse_args(argv) + if args.cmd == "replay" and bool(args.id) == bool(args.all): + ap.error("replay needs exactly one of ID or --all") + if args.cmd == "admit" and args.kind == "omega-qualification-receipt" and not args.source_repo: + ap.error("--source-repo is required for omega-qualification-receipt") + with tempfile.TemporaryDirectory() as tmp: + git = Git(args.cache or tmp, args.remote_base) + if args.cmd == "admit": + shelf = parse_shelf_arg(args.shelf) + try: + raw = fetch_shelf(git, shelf) + computed = evaluate(git, args.kind, shelf, args.source_repo, raw, args.issue_or_gate) + except Rejected as e: + print(f"ADMIT {args.id}: REJECTED {e} rc=3") + return EXIT["REJECTED"] + except NotRun as e: + print(f"ADMIT {args.id}: NOT_RUN {e} rc=2") + return EXIT["NOT_RUN"] + if args.issue_or_gate is not None and computed["issue_or_gate"]["verified"]: + print(f"ADMIT {args.id}: NOT_RUN --issue-or-gate given, but the receipt names its own " + f"({computed['issue_or_gate']['value']}); drop the option rc=2") + return EXIT["NOT_RUN"] + if not args.id or ":" in args.id: + ap.error("--id must be non-empty and contain no ':'") + entry = {"id": args.id, "issue_or_gate": computed["issue_or_gate"], **computed, + "replay": replay_command(args.id)} + print(json.dumps(entry, indent=1, ensure_ascii=False)) + return 0 + try: + idx = load_index(args.index) + except OSError as e: + print(f"REPLAY: NOT_RUN cannot load index: {e} rc=2") + return EXIT["NOT_RUN"] + except Rejected as e: + print(f"REPLAY: REJECTED index {args.index}: {e} rc=3") + return EXIT["REJECTED"] + if args.id: + entry = next((e for e in idx["entries"] if e.get("id") == args.id), None) + if entry is None: + print(f"REPLAY {args.id}: NOT_RUN no such entry in {args.index} rc=2") + return EXIT["NOT_RUN"] + rc, last, _ = replay_entry(git, entry, args.bytes) + print(last) + return rc + worst, bad = 0, 0 + for entry in idx["entries"]: + rc, last, reproduced = replay_entry(git, entry) + print(last) + if not reproduced: + bad += 1 + worst = max(worst, rc) + n = len(idx["entries"]) + print(f"INDEX {os.path.basename(args.index)} v{idx.get('index_version')}: " + f"{n - bad}/{n} entries reproduce as indexed rc={worst}") + return worst + + +if __name__ == "__main__": + sys.exit(main())