Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/test_omega_genesis_set.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / test_omega_genesis_set.c` 228 lines ยท 11577 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 /* test_omega_genesis_set.c: what a LISTED Genesis Set member does (VC1 stage 6). 18 * 19 * The real VC-GENESIS-1 is empty (src/omega_genesis.h, docs/osc/VC-GENESIS-1.md), so the listed 20 * path cannot run against it. This test is built from copies of omega_vcstore.c and 21 * omega_resolve.c whose single genesis include line is rewritten to 22 * tests/genesis_variant/omega_genesis.h (one member: the id of fixture 0x10). No hook exists in 23 * production source: the variant is a different file chosen by the build, never by a flag. 24 * 25 * It proves, with a member on the list: the store inserts, saves and loads it; omega_resolve_admit_genesis 26 * admits it; the resolver lets it satisfy an import in the build domain (with the mandatory source/IR 27 * recheck); and with the SAME list an id that is not a member is refused at every one of those doors. 28 * Exit 0 only when every check passed. */ 29 #include 30 #include 31 #include 32 #include 33 34 #include "genesis_variant/omega_genesis.h" 35 #include "omega_resolve.h" 36 #include "omega_vcstore.h" 37 #include "omega_vcstore_priv.h" 38 #include "vc_fixture.h" 39 40 static int g_total, g_failed; 41 static void check(const char *name, int ok) { 42 printf("%s %s\n", ok ? "PASS" : "FAIL", name); 43 g_total++; 44 if (!ok) g_failed++; 45 } 46 static void die(const char *what) { fprintf(stderr, "setup failed: %s\n", what); exit(2); } 47 48 typedef struct { uint8_t *p; size_t n, cap; } B; 49 static void bput(B *b, const void *d, size_t k) { 50 if (b->n + k > b->cap) { b->cap = (b->n + k) * 2 + 64; b->p = realloc(b->p, b->cap); if (!b->p) die("oom"); } 51 memcpy(b->p + b->n, d, k); b->n += k; 52 } 53 static void bu32(B *b, uint32_t v) { uint8_t t[4] = { (uint8_t)(v >> 24), (uint8_t)(v >> 16), (uint8_t)(v >> 8), (uint8_t)v }; bput(b, t, 4); } 54 static void bu64(B *b, uint64_t v) { bu32(b, (uint32_t)(v >> 32)); bu32(b, (uint32_t)v); } 55 static void bstr(B *b, const char *s) { size_t n = strlen(s); bu64(b, n); bput(b, s, n); } 56 static void hx(const uint8_t *d, char out[65]) { 57 static const char h[] = "`0123456789abcdef`"; 58 for (int i = 0; i < 32; i++) { out[2 * i] = h[d[i] >> 4]; out[2 * i + 1] = h[d[i] & 15]; } 59 out[64] = 0; 60 } 61 62 /* a record for fixture n: real program, IR digest, audit-style nonzero receipt_id, no dependencies */ 63 static void make_record(uint8_t n, const uint8_t *dep64, uint32_t n_dep, B *o) { 64 const VcFx *f = vcfx(n); 65 uint8_t con[32], rcpt[32], root[32], kind = OMEGA_VC_DIGEST_IR; 66 memcpy(con, f->id, 32); con[0] ^= 0x80; 67 memset(rcpt, 0xA0, 32); rcpt[0] = n; /* for BOOTSTRAP this is the audit record hash */ 68 memset(root, 0x66, 32); 69 o->n = 0; 70 bput(o, "AIEN_VERIFIED_CRUMB_V1", 22); 71 bu32(o, 1); 72 bput(o, f->id, 32); bput(o, con, 32); bput(o, &kind, 1); bput(o, f->digest, 32); 73 bu32(o, 0); 74 bu32(o, n_dep); if (n_dep) bput(o, dep64, 64 * (size_t)n_dep); 75 bput(o, rcpt, 32); bstr(o, "host-v1"); bstr(o, "1.0.0"); bput(o, root, 32); 76 bu32(o, 0); 77 bu32(o, 0); 78 } 79 static int raw_boot(OmegaVcStore *s, uint8_t n) { 80 B b = { 0, 0, 0 }; uint8_t id[32]; 81 make_record(n, NULL, 0, &b); 82 omega_vc_compute_id(b.p, b.n, id); 83 int rc = omega_vcstore_insert_bootstrap(s, b.p, b.n, id); 84 free(b.p); 85 return rc; 86 } 87 static int raw_verified(OmegaVcStore *s, uint8_t n) { 88 B b = { 0, 0, 0 }; uint8_t id[32]; 89 make_record(n, NULL, 0, &b); 90 omega_vc_compute_id(b.p, b.n, id); 91 int rc = omega_vcstore_insert(s, b.p, b.n, id); 92 free(b.p); 93 return rc; 94 } 95 static int admit_genesis(OmegaVcStore *s, uint8_t n, OmegaResolveError *e) { 96 B b = { 0, 0, 0 }; uint8_t id[32]; 97 make_record(n, NULL, 0, &b); 98 omega_vc_compute_id(b.p, b.n, id); 99 int rc = omega_resolve_admit_genesis(s, b.p, b.n, id, NULL, e); 100 free(b.p); 101 return rc; 102 } 103 static void flip(OmegaVcStore *s, uint8_t n, uint8_t kind) { 104 for (size_t i = 0; i < s->count; i++) 105 if (memcmp(s->objs[i].semantic_id, vcfx(n)->id, 32) == 0) { s->objs[i].admission_kind = kind; return; } 106 die("flip: no such object"); 107 } 108 static int kind_of(const OmegaVcStore *s, uint8_t n) { 109 uint8_t k = 0; 110 return omega_vcstore_admission_kind(s, vcfx(n)->id, &k) == 0 ? (int)k : -1; 111 } 112 113 static void t_list(void) { 114 check("variant-list-has-one-member", omega_genesis_count() == 1 && omega_genesis_member(0) != NULL && omega_genesis_member(1) == NULL); 115 check("variant-member-is-the-program-id-of-fixture-0x10", memcmp(omega_genesis_member(0), vcfx(0x10)->id, 32) == 0); 116 check("listed-id-is-contained", omega_genesis_contains(vcfx(0x10)->id) == 1); 117 check("other-real-programs-are-not-contained", omega_genesis_contains(vcfx(0x11)->id) == 0 && omega_genesis_contains(vcfx(0x00)->id) == 0); 118 uint8_t x[32]; int all = 1; 119 for (int i = 0; i < 32; i++) { /* no prefix or partial match: one bit anywhere makes it a non-member */ 120 memcpy(x, vcfx(0x10)->id, 32); x[i] ^= 1; 121 if (omega_genesis_contains(x)) all = 0; 122 } 123 check("one-bit-different-id-is-not-contained-at-any-position", all); 124 uint8_t z[32] = { 0 }; 125 check("zero-id-and-null-are-never-members", omega_genesis_contains(z) == 0 && omega_genesis_contains(NULL) == 0); 126 } 127 128 static void t_store(void) { 129 OmegaVcStore s; if (omega_vcstore_init(&s)) die("init"); 130 check("store-inserts-a-listed-bootstrap-record", raw_boot(&s, 0x10) == 0 && kind_of(&s, 0x10) == (int)OMEGA_VCS_ADMISSION_BOOTSTRAP); 131 check("store-refuses-an-unlisted-bootstrap-record", raw_boot(&s, 0x11) == OMEGA_VCS_GENESIS_NOT_LISTED && omega_vcstore_count(&s) == 1); 132 check("store-still-inserts-an-unlisted-verified-record", raw_verified(&s, 0x11) == 0 && kind_of(&s, 0x11) == (int)OMEGA_VCS_ADMISSION_VERIFIED); 133 check("store-refuses-a-bootstrap-record-over-a-verified-one", raw_boot(&s, 0x11) == OMEGA_VCS_GENESIS_NOT_LISTED); 134 char path[] = "/tmp/omega-gset-XXXXXX"; 135 int fd = mkstemp(path); if (fd < 0) die("mkstemp"); close(fd); 136 OmegaVcStore l; 137 check("store-saves-listed-bootstrap-and-verified-and-loads-them", omega_vcstore_save(&s, path) == 0 && omega_vcstore_init(&l) == 0 && 138 omega_vcstore_load(&l, path) == 0 && omega_vcstore_count(&l) == 2 && kind_of(&l, 0x10) == (int)OMEGA_VCS_ADMISSION_BOOTSTRAP); 139 omega_vcstore_destroy(&l); 140 flip(&s, 0x11, OMEGA_VCS_ADMISSION_BOOTSTRAP); /* an unlisted id marked BOOTSTRAP, written to a file */ 141 int sv = omega_vcstore_save(&s, path); 142 int init = omega_vcstore_init(&l); 143 int ld = omega_vcstore_load(&l, path); 144 check("store-load-refuses-a-file-with-an-unlisted-bootstrap-record", sv == 0 && init == 0 && ld == OMEGA_VCS_GENESIS_NOT_LISTED && omega_vcstore_count(&l) == 0); 145 omega_vcstore_destroy(&l); 146 unlink(path); 147 omega_vcstore_destroy(&s); 148 } 149 150 static void t_admit(void) { 151 OmegaVcStore s; OmegaResolveError e; 152 if (omega_vcstore_init(&s)) die("init"); 153 memset(&e, 0, sizeof e); 154 check("admit-genesis-admits-a-listed-member", admit_genesis(&s, 0x10, &e) == 0 && kind_of(&s, 0x10) == (int)OMEGA_VCS_ADMISSION_BOOTSTRAP); 155 memset(&e, 0, sizeof e); 156 int rc = admit_genesis(&s, 0x11, &e); 157 check("admit-genesis-refuses-a-record-that-is-not-a-member", rc == OMEGA_RES_UNVERIFIED_DEPENDENCY && e.store_code == OMEGA_VCS_GENESIS_NOT_LISTED && strstr(e.message, "pinned genesis set") != NULL && 158 omega_vcstore_count(&s) == 1); 159 omega_vcstore_destroy(&s); 160 } 161 162 static const char *g_lock_name = "gen"; 163 static void lock_for(const OmegaVcStore *s, uint8_t n, char *buf, size_t cap) { 164 uint8_t rid[32]; char a[65], b[65]; 165 if (omega_vcstore_receipt_of(s, vcfx(n)->id, rid) != 0) die("receipt_of"); 166 hx(vcfx(n)->id, a); hx(rid, b); 167 snprintf(buf, cap, "omega.lock v1\n%s = semantic %s receipt %s\n", g_lock_name, a, b); 168 } 169 static int resolve_one(const OmegaVcStore *s, OmegaDomain d, int blobs, char *lock_text, OmegaResolveError *e) { 170 OmegaResolver r; memset(&r, 0, sizeof r); 171 r.store = s; r.domain = d; 172 if (blobs) r.fetch_blob = vcfx_fetch_blob; 173 OmegaLock lock; OmegaResolveError le; 174 if (omega_lock_parse(lock_text, strlen(lock_text), &lock, &le)) die("lock"); 175 const char *names[1] = { g_lock_name }; 176 OmegaClosure c; memset(&c, 0, sizeof c); 177 memset(e, 0, sizeof *e); 178 int rc = omega_resolve_imports(&r, &lock, names, 1, &c, e); 179 int closure_ok = rc == 0 && c.n == 1 && c.entries[0].admission_kind == OMEGA_VCS_ADMISSION_BOOTSTRAP && 180 memcmp(c.entries[0].semantic_id, vcfx(0x10)->id, 32) == 0; 181 omega_closure_free(&c); 182 omega_lock_free(&lock); 183 return rc == 0 ? (closure_ok ? 0 : -1) : rc; 184 } 185 static void t_resolve(void) { 186 OmegaVcStore s; OmegaResolveError e; char lock[400]; 187 if (omega_vcstore_init(&s)) die("init"); 188 if (admit_genesis(&s, 0x10, &e) != 0) die("admit listed"); 189 lock_for(&s, 0x10, lock, sizeof lock); 190 check("resolver-lets-a-listed-bootstrap-record-satisfy-an-import-in-the-build-domain", resolve_one(&s, OMEGA_DOMAIN_BUILD, 1, lock, &e) == 0); 191 check("a-listed-bootstrap-record-still-needs-the-blob-store-in-the-build-domain", resolve_one(&s, OMEGA_DOMAIN_BUILD, 0, lock, &e) == OMEGA_RES_UNVERIFIED_DEPENDENCY); 192 check("resolver-lets-a-listed-bootstrap-record-satisfy-an-import-in-the-dev-domain", resolve_one(&s, OMEGA_DOMAIN_DEV, 0, lock, &e) == 0); 193 omega_vcstore_destroy(&s); 194 195 /* the same list, an id that is not on it, kind BOOTSTRAP made by tampering: refused by the resolver itself */ 196 if (omega_vcstore_init(&s)) die("init"); 197 if (raw_verified(&s, 0x10) != 0) die("insert verified 0x10"); 198 flip(&s, 0x10, OMEGA_VCS_ADMISSION_BOOTSTRAP); /* listed id: fine */ 199 lock_for(&s, 0x10, lock, sizeof lock); 200 check("resolver-accepts-a-listed-id-whatever-route-put-it-in-the-store", resolve_one(&s, OMEGA_DOMAIN_BUILD, 1, lock, &e) == 0); 201 omega_vcstore_destroy(&s); 202 203 if (omega_vcstore_init(&s)) die("init"); 204 if (raw_verified(&s, 0x11) != 0) die("insert verified 0x11"); 205 flip(&s, 0x11, OMEGA_VCS_ADMISSION_BOOTSTRAP); 206 lock_for(&s, 0x11, lock, sizeof lock); 207 OmegaResolver r; memset(&r, 0, sizeof r); r.store = &s; r.domain = OMEGA_DOMAIN_BUILD; r.fetch_blob = vcfx_fetch_blob; 208 OmegaLock lk; OmegaResolveError le; 209 if (omega_lock_parse(lock, strlen(lock), &lk, &le)) die("lock"); 210 const char *names[1] = { g_lock_name }; 211 OmegaClosure c; memset(&c, 0, sizeof c); memset(&e, 0, sizeof e); 212 int rc = omega_resolve_imports(&r, &lk, names, 1, &c, &e); 213 check("resolver-refuses-an-unlisted-bootstrap-record-even-with-the-list-non-empty", 214 rc == OMEGA_RES_UNVERIFIED_DEPENDENCY && e.store_code == OMEGA_VCS_GENESIS_NOT_LISTED && c.n == 0); 215 omega_closure_free(&c); omega_lock_free(&lk); 216 omega_vcstore_destroy(&s); 217 } 218 219 int main(void) { 220 t_list(); 221 t_store(); 222 t_admit(); 223 t_resolve(); 224 printf("%d checks, %d failed\n", g_total, g_failed); 225 if (g_failed) return 1; 226 printf("test-genesis-set: PASS\n"); 227 return 0; 228 }