interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / visor / visor_evidence.h

111 lines · 5803 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* Omega Visor V1 - lane 4: evidence (receipt) inspection.
18 *
19 * Reads receipt files under an evidence root directly (never includes
20 * omega_evidence.h, which pulls in physics). The on-disk tree holds JSON
21 * receipts in two shapes, both supported by one strict fixed-buffer JSON scanner:
22 * - milestone receipts (evidence/omega_*_receipt.json): git_commit, host{os,arch},
23 * status, qualification_gates{total,passed,gates{}}, nested semantic_id/realization_id
24 * - run receipts, content-addressed (evidence/<LANE>/<sha256>.json): schema, run_id,
25 * candidate_commit/run_commit, tree_dirty, host{sysname,release,machine} or
26 * machine_identity{node,...}, hardware_scope|scope, gates{}|gate{}, silicon_observed,
27 * physics_commit|physics_forge_commit, selected_realization_identity
28 * Everything else (txt/log/bin/omg/SHA256SUMS, malformed or oversize JSON) is
29 * counted UNPARSED with its path.
30 *
31 * Scope law: qualification scope is NEVER upgraded. It is inferred only from
32 * explicit receipt fields, and when several signals exist the LOWEST wins:
33 * silicon_observed:true, gpu_uuid, compute_class -> SILICON
34 * silicon_observed:false -> HOST (cap)
35 * a "qemu_target" key (any depth), or hardware_scope/scope naming qemu -> QEMU
36 * (gate names like *_QEMU_VIRT_PASS or modeled QEMU machine profiles do not count)
37 * hardware_scope/scope starting "host" / "no silicon claim" -> HOST
38 * hardware_scope/scope containing "simulat" -> SIMULATED
39 * none of the above (a bare host{} build-machine block included) -> UNKNOWN
40 *
41 * Fixed storage, not reentrant (one static read buffer + token pool). */
42#ifndef VISOR_EVIDENCE_H
43#define VISOR_EVIDENCE_H
44
45#include <stdbool.h>
46#include <stddef.h>
47#include <stdint.h>
48
49#include "omega_types.h"
50
51#define VISOR_EVIDENCE_MAX_ITEMS 16
52#define VISOR_EVIDENCE_MAX_UNPARSED_PATHS 8
53#define VISOR_EVIDENCE_MAX_FILE_BYTES (256u * 1024u)
54/* Walk cap: regular files kept per scan. Past it the scan keeps the lexicographically
55 * smallest paths (never the first ones readdir returned) and sets truncated. */
56#define VISOR_EVIDENCE_MAX_FILES ((size_t)131072)
57
58typedef enum {
59 VISOR_QUAL_UNKNOWN, VISOR_QUAL_SIMULATED, VISOR_QUAL_HOST, VISOR_QUAL_QEMU, VISOR_QUAL_SILICON
60} VisorQualScope;
61
62typedef struct {
63 char path[256];
64 char receipt_id[72]; /* "sha256:<hex>" of the exact file bytes */
65 char commit[41]; /* candidate_commit | run_commit | git_commit | candidate_git_commit | qualified_implementation_commit */
66 char physics_commit[41]; /* physics_commit | physics_forge_commit */
67 char run_id[64];
68 char machine[96]; /* from machine_identity{} or host{}; "" if absent */
69 char realization_id[72]; /* "sha256:<hex>" from realization_id | selected_/promoted_realization_identity | compiler_realization_id */
70 VisorQualScope scope;
71 const char *scope_name; /* "UNKNOWN" / "SIMULATED" / "HOST" / "QEMU" / "SILICON" */
72 bool tree_dirty;
73 uint32_t gates_run, gates_passed;
74 char claim[128];
75 /* extensions (lane 4) */
76 char scope_basis[96]; /* which explicit field(s) set the scope, "" when UNKNOWN */
77 bool tree_state_known; /* false: receipt says nothing about tree cleanliness */
78 int name_hash_match; /* 1: <sha256>.json name == content hash, 0: mismatch, -1: not hash-named */
79} VisorEvidenceRecord;
80
81typedef struct {
82 VisorEvidenceRecord items[VISOR_EVIDENCE_MAX_ITEMS];
83 size_t count; /* items filled (<= 16, sorted by path) */
84 size_t scanned; /* files visited */
85 size_t unparsed; /* non-JSON, malformed or oversize files */
86 /* extensions (lane 4) */
87 size_t matched; /* records that qualified (may exceed count: truncated) */
88 bool truncated;
89 char unparsed_paths[VISOR_EVIDENCE_MAX_UNPARSED_PATHS][256];
90 size_t unparsed_listed;
91} VisorEvidenceView;
92
93const char *visor_qual_scope_name(VisorQualScope s);
94
95/* All receipts under root, depth-first, sorted by path. -1 if root unreadable or the
96 * path list cannot be allocated. */
97int visor_evidence_scan(const char *evidence_root, VisorEvidenceView *out);
98/* Sets the walk cap (0 restores VISOR_EVIDENCE_MAX_FILES); returns the previous cap.
99 * Tests lower it to prove the cap keeps the same files for any readdir order. */
100size_t visor_evidence_set_max_files(size_t cap);
101/* Receipts whose bytes mention the id's 64-hex form (semantic, realization or
102 * machine id, any nesting). count==0 means "no evidence" and returns 0. */
103int visor_evidence_for_id(const char *evidence_root, const SemanticId *id, VisorEvidenceView *out);
104/* One receipt. -1 (fail closed) if unreadable, oversize, not strict JSON, or not an object. */
105int visor_evidence_load(const char *path, VisorEvidenceRecord *out);
106
107/* Deterministic renderings. Return bytes written (excl. NUL) or -1 if truncated/invalid. */
108int visor_evidence_format_text(const VisorEvidenceView *v, char *out, size_t n);
109int visor_evidence_format_json(const VisorEvidenceView *v, char *out, size_t n);
110
111#endif /* VISOR_EVIDENCE_H */