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

GitHub aien-dev/omega-mv#222 (code only)

closed derived 6c5ef97dafcf3200 #222

Imported from GitHub aien-dev/omega-mv#222 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 9de10dd97a07381da6458b87a2dec7d0fc0f552b · Head 993ece0013a024472ace3440abeebed4904a40aa

Apply it

git checkout -b patch-6c5ef97dafcf3200 9de10dd97a07381da6458b87a2dec7d0fc0f552b
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/6c5ef97dafcf3200.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/omega-mv
222
993ece0013a024472ace3440abeebed4904a40aa
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":222,"url":"https://github.com/aien-dev/omega-mv/pull/222","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:50Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.github/workflows/host-suites-2.yml b/.github/workflows/host-suites-2.yml
index 30957cadd..b9bf58d2f 100644
--- a/.github/workflows/host-suites-2.yml
+++ b/.github/workflows/host-suites-2.yml
@@ -261,7 +261,7 @@ jobs:
         with:
           fetch-depth: 0
       - name: Crumbline learner conformance vectors
-        run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-crumbline test-library
+        run: make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-crumbline test-library test-vcstore
 
   runtime:
     needs: changes
diff --git a/Makefile b/Makefile
index 47c9f9bfa..32365fe7c 100644
--- a/Makefile
+++ b/Makefile
@@ -1708,3 +1708,96 @@ test-library: tests/test_omega_library.c src/omega_library.c src/omega_library.h
 	  build_mutant refuse-valid          capacity             '    if (prog->name[3] == (char)55) return -1;'; \
 	  build_mutant refuse-deps           dep-null             '    if (dep_count > 0) return -1;'
 	@echo "test-library: PASS (all checks, all mutants killed)"
+
+# VC1-STORE (VC1 stage 3): unit test for the Verified Crumb Store (omega_vcstore): golden
+# vectors from aien-protocols (tests/vcstore/golden, PIN names the commit), immutability,
+# dependency closure, insert-order-independent digest, name index, save/load. Plus a mutation
+# proof: each mutant is a copy of src/omega_vcstore.c with one tagged line (VC1S:<tag>) deleted or
+# weakened; the test must exit 1 (KILLED) for every one. A mutant whose sed changed nothing
+# fails the build. Physics-free; CPU only; needs only src/sha256.c.
+.PHONY: test-vcstore
+VCSTEST_FLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -Isrc
+VCSTEST_DIR = $(OUT_DIR)/vcstore-test
+test-vcstore: tests/test_omega_vcstore.c src/omega_vcstore.c src/omega_vcstore.h src/sha256.c
+	@mkdir -p $(VCSTEST_DIR)
+	$(CC) $(VCSTEST_FLAGS) -o $(VCSTEST_DIR)/test_omega_vcstore tests/test_omega_vcstore.c src/omega_vcstore.c src/sha256.c
+	$(VCSTEST_DIR)/test_omega_vcstore
+	@set -eu; build_mutant() { name=$$1; tag=$$2; repl=$$3; \
+	  sed "/VC1S:$$tag/c\\$$repl" src/omega_vcstore.c > $(VCSTEST_DIR)/mut_$$name.c; \
+	  if cmp -s src/omega_vcstore.c $(VCSTEST_DIR)/mut_$$name.c; then echo "mutant $$name: sed changed nothing"; exit 1; fi; \
+	  $(CC) $(VCSTEST_FLAGS) -o $(VCSTEST_DIR)/mut_$$name tests/test_omega_vcstore.c $(VCSTEST_DIR)/mut_$$name.c src/sha256.c; \
+	  rc=0; $(VCSTEST_DIR)/mut_$$name $$name > $(VCSTEST_DIR)/mut_$$name.out 2>&1 || rc=$$?; \
+	  if [ $$rc -ne 1 ] || ! grep -q "^MUTANT $$name KILLED by " $(VCSTEST_DIR)/mut_$$name.out; then \
+	    echo "mutant $$name NOT killed (exit $$rc)"; tail -5 $(VCSTEST_DIR)/mut_$$name.out; exit 1; fi; \
+	  echo "mutant $$name: killed (exit 1)"; }; \
+	  build_mutant refuse-valid             dec-trailing           '    if (!c.err && c.pos == c.n) cfail(&c, OMEGA_VCS_TRAILING_BYTES);'; \
+	  build_mutant refuse-existing-dep      dep-exists             '        if (vcs_find(s, dep, &di)) { rc = OMEGA_VCS_UNVERIFIED_DEPENDENCY; break; } else continue;'; \
+	  build_mutant caps-reversed            dec-caps-order         '        if (!c.err && i > 0 && str_cmp(&v->capabilities[i - 1], &v->capabilities[i]) <= 0) cfail(&c, OMEGA_VCS_NONCANONICAL_SET);'; \
+	  build_mutant kind-source-only         dec-kind               '        if (v->digest_kind != OMEGA_VC_DIGEST_SOURCE) cfail(&c, OMEGA_VCS_BAD_DIGEST_KIND);'; \
+	  build_mutant id-hash                  id-hash                '    sha256_hash(bytes + (len >= 22 ? 22 : 0), len >= 22 ? len - 22 : len, out);'; \
+	  build_mutant dec-dep-dup              dec-dep-dup            '        ;'; \
+	  build_mutant dec-dep-order            dec-dep-order          '        ;'; \
+	  build_mutant dec-receipt              dec-receipt            '    ;'; \
+	  build_mutant dec-dep-self             dec-dep-self           '        ;'; \
+	  build_mutant dec-trailing             dec-trailing           '    ;'; \
+	  build_mutant dec-version              dec-version            '    ;'; \
+	  build_mutant dec-truncated            dec-truncated          '    if (c->n - c->pos < k) return 0;'; \
+	  build_mutant dec-tag                  dec-tag                '    ;'; \
+	  build_mutant dec-exports-order        dec-exports-order      '        ;'; \
+	  build_mutant dec-kind                 dec-kind               '        ;'; \
+	  build_mutant dec-zero-ids             dec-zero-ids           '    ;'; \
+	  build_mutant dec-string-char          dec-string-char        '        (void)ch;'; \
+	  build_mutant dec-count                dec-count              '    ;'; \
+	  build_mutant dec-real-order           dec-real-order         '        (void)prev;'; \
+	  build_mutant dec-caps-order           dec-caps-order         '        ;'; \
+	  build_mutant dec-dep-zero             dec-dep-zero           '        (void)req;'; \
+	  build_mutant dec-evroot               dec-evroot             '    ;'; \
+	  build_mutant dec-string-empty         dec-string-len         '    if (len > OMEGA_VC_MAX_STRING) { cfail(c, OMEGA_VCS_BAD_STRING); return; }'; \
+	  build_mutant dec-string-max           dec-string-len         '    if (len == 0) { cfail(c, OMEGA_VCS_BAD_STRING); return; }'; \
+	  build_mutant claimed-required         claimed-required       '    if (!claimed) { static uint8_t zz[32]; omega_vc_compute_id(canon, len, zz); claimed = zz; }'; \
+	  build_mutant insert-idcheck           insert-idcheck         '    if (0) { free(rec); return OMEGA_VCS_VCSTORE_ID_MISMATCH; }'; \
+	  build_mutant idempotent               idempotent             '        (void)o;'; \
+	  build_mutant idempotent-ignores-kind  idempotent             '        if (o->len == len && memcmp(o->bytes, canon, len) == 0) return OMEGA_VCS_OK;'; \
+	  build_mutant immutable                immutable              '        return OMEGA_VCS_OK;'; \
+	  build_mutant dep-exists               dep-exists             '        if (!vcs_find(s, dep, &di)) continue;'; \
+	  build_mutant dep-contract             dep-contract           '        ;'; \
+	  build_mutant no-cap                   no-cap                 '    if (s->count >= 128) return OMEGA_VCS_VCSTORE_CAPACITY;'; \
+	  build_mutant sorted-insert            sorted-insert          '    size_t at = s->count;'; \
+	  build_mutant kind-bootstrap           kind-bootstrap         '    return vcs_insert(s, canonical, len, claimed_vc_id, OMEGA_VCS_ADMISSION_VERIFIED);'; \
+	  build_mutant get-recompute            get-recompute          '    ;'; \
+	  build_mutant get-key                  get-key                '    ;'; \
+	  build_mutant receipt-of               receipt-of             '    if (rc == OMEGA_VCS_OK) memcpy(out_receipt, rec->vc.evidence_root, 32);'; \
+	  build_mutant walk-order               walk-order             '            const uint8_t *dep = f->deps + 64 * (size_t)(f->n_dep - 1 - f->next++);'; \
+	  build_mutant walk-visited             walk-visited           '            ;'; \
+	  build_mutant walk-capacity            walk-capacity          '    ;'; \
+	  build_mutant walk-dep-exists          walk-dep-exists        '            if (!vcs_find(s, dep, &di)) continue;'; \
+	  build_mutant walk-contract            walk-contract          '            ;'; \
+	  build_mutant walk-cycle               walk-cycle             '            if (state[di] == 1) continue;'; \
+	  build_mutant walk-names               walk-names             '    if (s->n_names) return OMEGA_VCS_UNVERIFIED_DEPENDENCY;'; \
+	  build_mutant digest-magic             digest-magic           '    sha256_update(&ctx, (const uint8_t *)"VCS2", 4);'; \
+	  build_mutant digest-kind              digest-kind            '        uint8_t kind = 0;'; \
+	  build_mutant digest-bytes             digest-bytes           '        sha256_update(&ctx, o->bytes, 0);'; \
+	  build_mutant digest-names             digest-names           '    u64be(&ctx, (uint64_t)s->n_names);'; \
+	  build_mutant namedigest-id            namedigest-id          '        sha256_update(&ctx, nm->id, 0);'; \
+	  build_mutant name-sorted              name-sorted            '    return name_insert_at(s, s->n_names, name, id);'; \
+	  build_mutant name-many                name-many              '    for (size_t k = 0; k < s->n_names; k++) if (memcmp(s->names[k].id, id, 32) == 0) return OMEGA_VCS_VCSTORE_NAME_EXISTS;'; \
+	  build_mutant name-no-silent-rebind    name-no-silent-rebind  '        { memcpy(s->names[np].id, id, 32); return OMEGA_VCS_OK; }'; \
+	  build_mutant rebind-write             rebind-write           '    ;'; \
+	  build_mutant rebind-exists            rebind-exists          '    if (!name_find(s, name, &np)) np = 0;'; \
+	  build_mutant rebind-id-exists         rebind-id-exists       '    (void)vcs_find(s, id, &di);'; \
+	  build_mutant name-id-exists           name-id-exists         '    (void)vcs_find(s, id, &di);'; \
+	  build_mutant name-valid               name-valid             '    ;'; \
+	  build_mutant resolve                  resolve                '    memset(out_id, 0, 32);'; \
+	  build_mutant load-names               load-names             '        ;'; \
+	  build_mutant load-fail                load-fail              '        omega_vcstore_destroy(s);'; \
+	  build_mutant load-magic               load-magic             '    if (!m) return OMEGA_VCS_VCSTORE_MALFORMED;'; \
+	  build_mutant load-digest-obj          load-digest-obj        '    ;'; \
+	  build_mutant load-digest-names        load-digest-names      '    ;'; \
+	  build_mutant load-trailing            load-trailing          '    ;'; \
+	  build_mutant load-kind                load-kind              '        ;'; \
+	  build_mutant load-order               load-order             '        ;'; \
+	  build_mutant load-graph               load-graph             '    (void)vcs_graph_check;'; \
+	  build_mutant load-graph-missing       load-graph             '    (void)vcs_graph_check;'; \
+	  build_mutant load-name-id             load-name-id           '        (void)vcs_find(t, id, &di);'; \
+	  build_mutant save-verify              save-verify            '        int rc = 0;'
+	@echo "test-vcstore: PASS (all checks, all mutants killed)"
diff --git a/src/omega_vcstore.c b/src/omega_vcstore.c
new file mode 100644
index 000000000..2d9538dd0
--- /dev/null
+++ b/src/omega_vcstore.c
@@ -0,0 +1,702 @@
+#include "omega_vcstore.h"
+#include "sha256.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Every refusal guard sits on one line carrying a VC1S:<tag> marker. The mutation test
+ * (Makefile test-vcstore) copies this file, deletes or weakens exactly that line, and
+ * requires tests/test_omega_vcstore.c to fail. A comment-only marker line is a hook where a
+ * mutant injects a forbidden behaviour. Keep one guard per line when editing. */
+
+#define TAG "AIEN_VERIFIED_CRUMB_V1"
+#define TAG_LEN 22
+#define FILE_MAGIC "AIEN_VCSTORE_V1"
+#define FILE_MAGIC_LEN 15
+#define MAX_NAME 128
+
+static const uint8_t ZERO32[32];
+
+const char *omega_vcstore_code_name(int code) {
+    switch (code) {
+    case OMEGA_VCS_OK: return "OK";
+    case OMEGA_VCS_UNVERIFIED_DEPENDENCY: return "UNVERIFIED_DEPENDENCY";
+    case OMEGA_VCS_MISSING_RECEIPT: return "MISSING_RECEIPT";
+    case OMEGA_VCS_RECEIPT_HASH_MISMATCH: return "RECEIPT_HASH_MISMATCH";
+    case OMEGA_VCS_DEPENDENCY_NOT_PINNED: return "DEPENDENCY_NOT_PINNED";
+    case OMEGA_VCS_DEPENDENCY_CYCLE: return "DEPENDENCY_CYCLE";
+    case OMEGA_VCS_STALE_RECEIPT: return "STALE_RECEIPT";
+    case OMEGA_VCS_UNDECLARED_IMPORT: return "UNDECLARED_IMPORT";
+    case OMEGA_VCS_TAINTED_ARTIFACT: return "TAINTED_ARTIFACT";
+    case OMEGA_VCS_UNKNOWN_VERIFIER_PROFILE: return "UNKNOWN_VERIFIER_PROFILE";
+    case OMEGA_VCS_BAD_DOMAIN_TAG: return "BAD_DOMAIN_TAG";
+    case OMEGA_VCS_UNKNOWN_FORMAT_VERSION: return "UNKNOWN_FORMAT_VERSION";
+    case OMEGA_VCS_TRUNCATED: return "TRUNCATED";
+    case OMEGA_VCS_TRAILING_BYTES: return "TRAILING_BYTES";
+    case OMEGA_VCS_DUPLICATE_DEPENDENCY: return "DUPLICATE_DEPENDENCY";
+    case OMEGA_VCS_UNSORTED_DEPENDENCIES: return "UNSORTED_DEPENDENCIES";
+    case OMEGA_VCS_NONCANONICAL_SET: return "NONCANONICAL_SET";
+    case OMEGA_VCS_BAD_STRING: return "BAD_STRING";
+    case OMEGA_VCS_ZERO_ID: return "ZERO_ID";
+    case OMEGA_VCS_TOO_MANY_ENTRIES: return "TOO_MANY_ENTRIES";
+    case OMEGA_VCS_BAD_DIGEST_KIND: return "BAD_DIGEST_KIND";
+    case OMEGA_VCS_VCSTORE_ID_MISMATCH: return "VCSTORE_ID_MISMATCH";
+    case OMEGA_VCS_VCSTORE_IMMUTABLE_CONFLICT: return "VCSTORE_IMMUTABLE_CONFLICT";
+    case OMEGA_VCS_VCSTORE_MALFORMED: return "VCSTORE_MALFORMED";
+    case OMEGA_VCS_VCSTORE_NOT_FOUND: return "VCSTORE_NOT_FOUND";
+    case OMEGA_VCS_VCSTORE_NAME_EXISTS: return "VCSTORE_NAME_EXISTS";
+    case OMEGA_VCS_VCSTORE_CAPACITY: return "VCSTORE_CAPACITY";
+    case OMEGA_VCS_VCSTORE_NOMEM: return "VCSTORE_NOMEM";
+    case OMEGA_VCS_VCSTORE_IO: return "VCSTORE_IO";
+    }
+    return "UNKNOWN_CODE";
+}
+
+/* ---- decoder (SPEC 3; refusal order is field order, the first failure wins) ---- */
+
+typedef struct { const uint8_t *b; size_t n, pos; int err; } cur_t;
+
+static void cfail(cur_t *c, int code) { if (!c->err) c->err = code; }
+
+static int need(cur_t *c, size_t k) {
+    if (c->err) return 0;
+    if (c->n - c->pos < k) { cfail(c, OMEGA_VCS_TRUNCATED); return 0; } /* VC1S:dec-truncated */
+    return 1;
+}
+static uint32_t rd32(cur_t *c) {
+    if (!need(c, 4)) return 0;
+    const uint8_t *p = c->b + c->pos; c->pos += 4;
+    return (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | p[3];
+}
+static uint64_t rd64(cur_t *c) {
+    uint64_t hi = rd32(c), lo = rd32(c);
+    return hi << 32 | lo;
+}
+static const uint8_t *rd_idp(cur_t *c) {
+    if (!need(c, 32)) return ZERO32;
+    const uint8_t *p = c->b + c->pos; c->pos += 32;
+    return p;
+}
+static int is_zero32(const uint8_t *p) {
+    uint8_t acc = 0;
+    for (int i = 0; i < 32; i++) acc |= p[i];
+    return acc == 0;
+}
+static uint32_t rd_count(cur_t *c) {
+    uint32_t n = rd32(c);
+    if (!c->err && n > OMEGA_VC_MAX_ENTRIES) { cfail(c, OMEGA_VCS_TOO_MANY_ENTRIES); return 0; } /* VC1S:dec-count */
+    return n;
+}
+static void rd_str(cur_t *c, OmegaVcStr *out) {
+    uint64_t len = rd64(c);
+    out->p = (const uint8_t *)""; out->len = 0;
+    if (c->err) return;
+    if (len == 0 || len > OMEGA_VC_MAX_STRING) { cfail(c, OMEGA_VCS_BAD_STRING); return; } /* VC1S:dec-string-len */
+    if (!need(c, (size_t)len)) return;
+    for (uint64_t i = 0; i < len; i++) {
+        uint8_t ch = c->b[c->pos + i];
+        if (ch < 0x21 || ch > 0x7e) { cfail(c, OMEGA_VCS_BAD_STRING); return; } /* VC1S:dec-string-char */
+    }
+    out->p = c->b + c->pos; out->len = (size_t)len; c->pos += (size_t)len;
+}
+static int str_cmp(const OmegaVcStr *a, const OmegaVcStr *b) {
+    size_t m = a->len < b->len ? a->len : b->len;
+    int r = memcmp(a->p, b->p, m);
+    if (r) return r;
+    return a->len < b->len ? -1 : a->len > b->len ? 1 : 0;
+}
+
+int omega_vc_decode(const uint8_t *b, size_t n, OmegaVcView *v) {
+    if (!v || (!b && n)) return OMEGA_VCS_VCSTORE_MALFORMED;
+    cur_t c = { b ? b : ZERO32, n, 0, 0 };
+    memset(v, 0, sizeof *v);
+    if (!need(&c, TAG_LEN)) return c.err;
+    if (memcmp(b, TAG, TAG_LEN) != 0) return OMEGA_VCS_BAD_DOMAIN_TAG; /* VC1S:dec-tag */
+    c.pos = TAG_LEN;
+    v->format_version = rd32(&c);
+    if (!c.err && v->format_version != OMEGA_VC_FORMAT_VERSION) cfail(&c, OMEGA_VCS_UNKNOWN_FORMAT_VERSION); /* VC1S:dec-version */
+    v->semantic_id = rd_idp(&c);
+    v->contract_id = rd_idp(&c);
+    if (need(&c, 1)) {
+        v->digest_kind = c.b[c.pos++];
+        if (v->digest_kind != OMEGA_VC_DIGEST_SOURCE && v->digest_kind != OMEGA_VC_DIGEST_IR) cfail(&c, OMEGA_VCS_BAD_DIGEST_KIND); /* VC1S:dec-kind */
+    }
+    v->source_or_ir_digest = rd_idp(&c);
+    if (!c.err && (is_zero32(v->semantic_id) || is_zero32(v->contract_id) || is_zero32(v->source_or_ir_digest))) cfail(&c, OMEGA_VCS_ZERO_ID); /* VC1S:dec-zero-ids */
+    v->n_realizations = rd_count(&c);
+    v->realization_ids = c.b + c.pos;
+    const uint8_t *prev = NULL;
+    for (uint32_t i = 0; i < v->n_realizations && !c.err; i++) {
+        const uint8_t *id = rd_idp(&c);
+        if (!c.err && prev && memcmp(prev, id, 32) >= 0) cfail(&c, OMEGA_VCS_NONCANONICAL_SET); /* VC1S:dec-real-order */
+        prev = id;
+    }
+    v->n_dependencies = rd_count(&c);
+    v->dependencies = c.b + c.pos;
+    prev = NULL;
+    for (uint32_t i = 0; i < v->n_dependencies && !c.err; i++) {
+        const uint8_t *sid = rd_idp(&c);
+        const uint8_t *req = rd_idp(&c);
+        if (c.err) break;
+        if (memcmp(sid, v->semantic_id, 32) == 0) { cfail(&c, OMEGA_VCS_DEPENDENCY_CYCLE); break; } /* VC1S:dec-dep-self */
+        if (is_zero32(sid) || is_zero32(req)) { cfail(&c, OMEGA_VCS_ZERO_ID); break; } /* VC1S:dec-dep-zero */
+        if (prev) {
+            int cmp = memcmp(prev, sid, 32);
+            if (cmp == 0) { cfail(&c, OMEGA_VCS_DUPLICATE_DEPENDENCY); break; } /* VC1S:dec-dep-dup */
+            if (cmp > 0) { cfail(&c, OMEGA_VCS_UNSORTED_DEPENDENCIES); break; } /* VC1S:dec-dep-order */
+        }
+        prev = sid;
+    }
+    v->receipt_id = rd_idp(&c);
+    if (!c.err && is_zero32(v->receipt_id)) cfail(&c, OMEGA_VCS_MISSING_RECEIPT); /* VC1S:dec-receipt */
+    rd_str(&c, &v->verifier_profile);
+    rd_str(&c, &v->verifier_version);
+    v->evidence_root = rd_idp(&c);
+    if (!c.err && is_zero32(v->evidence_root)) cfail(&c, OMEGA_VCS_ZERO_ID); /* VC1S:dec-evroot */
+    v->n_exports = rd_count(&c);
+    for (uint32_t i = 0; i < v->n_exports && !c.err; i++) {
+        rd_str(&c, &v->exports[i]);
+        if (!c.err && i > 0 && str_cmp(&v->exports[i - 1], &v->exports[i]) >= 0) cfail(&c, OMEGA_VCS_NONCANONICAL_SET); /* VC1S:dec-exports-order */
+    }
+    v->n_capabilities = rd_count(&c);
+    for (uint32_t i = 0; i < v->n_capabilities && !c.err; i++) {
+        rd_str(&c, &v->capabilities[i]);
+        if (!c.err && i > 0 && str_cmp(&v->capabilities[i - 1], &v->capabilities[i]) >= 0) cfail(&c, OMEGA_VCS_NONCANONICAL_SET); /* VC1S:dec-caps-order */
+    }
+    if (!c.err && c.pos != c.n) cfail(&c, OMEGA_VCS_TRAILING_BYTES); /* VC1S:dec-trailing */
+    return c.err;
+}
+
+void omega_vc_compute_id(const uint8_t *bytes, size_t len, uint8_t out[OMEGA_VC_ID_BYTES]) {
+    sha256_hash(bytes, len, out); /* VC1S:id-hash */
+}
+
+/* ---- store ---- */
+
+int omega_vcstore_init(OmegaVcStore *s) {
+    if (!s) return OMEGA_VCS_VCSTORE_MALFORMED;
+    memset(s, 0, sizeof *s);
+    return OMEGA_VCS_OK;
+}
+
+void omega_vcstore_destroy(OmegaVcStore *s) {
+    if (!s) return;
+    for (size_t i = 0; i < s->count; i++) free(s->objs[i].bytes);
+    for (size_t i = 0; i < s->n_names; i++) free(s->names[i].name);
+    free(s->objs);
+    free(s->names);
+    memset(s, 0, sizeof *s);
+}
+
+size_t omega_vcstore_count(const OmegaVcStore *s) { return s ? s->count : 0; }
+
+/* lower bound by semantic_id; returns 1 if found at *pos, else 0 with *pos the insert point */
+static int vcs_find(const OmegaVcStore *s, const uint8_t *id, size_t *pos) {
+    size_t lo = 0, hi = s->count;
+    while (lo < hi) {
+        size_t mid = lo + (hi - lo) / 2;
+        int c = memcmp(s->objs[mid].semantic_id, id, 32);
+        if (c == 0) { *pos = mid; return 1; }
+        if (c < 0) lo = mid + 1; else hi = mid;
+    }
+    *pos = lo;
+    return 0;
+}
+
+/* Fetch object idx with every integrity check: the VC id is recomputed from the stored bytes,
+ * the bytes are decoded again, and the decoded semantic_id must be the key. */
+static int vcs_fetch(const OmegaVcStore *s, size_t idx, OmegaVcRecord *out) {
+    const OmegaVcObject *o = &s->objs[idx];
+    uint8_t id[32];
+    omega_vc_compute_id(o->bytes, o->len, id);
+    if (memcmp(id, o->vc_id, 32) != 0) return OMEGA_VCS_VCSTORE_ID_MISMATCH; /* VC1S:get-recompute */
+    int rc = omega_vc_decode(o->bytes, o->len, &out->vc);
+    if (rc) return rc;
+    if (memcmp(out->vc.semantic_id, o->semantic_id, 32) != 0) return OMEGA_VCS_VCSTORE_ID_MISMATCH; /* VC1S:get-key */
+    out->canonical = o->bytes;
+    out->canonical_len = o->len;
+    memcpy(out->vc_id, o->vc_id, 32);
+    out->admission_kind = o->admission_kind;
+    return OMEGA_VCS_OK;
+}
+
+static int vcs_insert(OmegaVcStore *s, const uint8_t *canon, size_t len, const uint8_t *claimed, uint8_t kind) {
+    if (!s || !canon || len == 0) return OMEGA_VCS_VCSTORE_MALFORMED;
+    if (!claimed) return OMEGA_VCS_VCSTORE_MALFORMED; /* VC1S:claimed-required */
+    /* VC1S:no-cap (the store has no fixed capacity: it grows) */
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    if (!rec) return OMEGA_VCS_VCSTORE_NOMEM;
+    int rc = omega_vc_decode(canon, len, &rec->vc);
+    if (rc) { free(rec); return rc; }
+    uint8_t id[32];
+    omega_vc_compute_id(canon, len, id);
+    if (memcmp(id, claimed, 32) != 0) { free(rec); return OMEGA_VCS_VCSTORE_ID_MISMATCH; } /* VC1S:insert-idcheck */
+    size_t pos;
+    if (vcs_find(s, rec->vc.semantic_id, &pos)) {
+        const OmegaVcObject *o = &s->objs[pos];
+        free(rec);
+        if (o->len == len && o->admission_kind == kind && memcmp(o->bytes, canon, len) == 0) return OMEGA_VCS_OK; /* VC1S:idempotent */
+        return OMEGA_VCS_VCSTORE_IMMUTABLE_CONFLICT; /* VC1S:immutable */
+    }
+    /* every dependency must already be stored, under the contract this record requires */
+    OmegaVcRecord *dr = malloc(sizeof *dr);
+    if (!dr) { free(rec); return OMEGA_VCS_VCSTORE_NOMEM; }
+    for (uint32_t i = 0; i < rec->vc.n_dependencies; i++) {
+        const uint8_t *dep = rec->vc.dependencies + 64 * (size_t)i;
+        size_t di;
+        if (!vcs_find(s, dep, &di)) { rc = OMEGA_VCS_UNVERIFIED_DEPENDENCY; break; } /* VC1S:dep-exists */
+        rc = vcs_fetch(s, di, dr);
+        if (rc) break;
+        if (memcmp(dr->vc.contract_id, dep + 32, 32) != 0) { rc = OMEGA_VCS_UNVERIFIED_DEPENDENCY; break; } /* VC1S:dep-contract */
+    }
+    free(dr);
+    if (rc) { free(rec); return rc; }
+    uint8_t sid[32];
+    memcpy(sid, rec->vc.semantic_id, 32);
+    free(rec);
+
+    uint8_t *cp = malloc(len);
+    if (!cp) return OMEGA_VCS_VCSTORE_NOMEM;
+    memcpy(cp, canon, len);
+    if (s->count == s->cap) {
+        size_t nc = s->cap ? s->cap * 2 : 16;
+        if (nc > SIZE_MAX / sizeof *s->objs) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        OmegaVcObject *n = realloc(s->objs, nc * sizeof *s->objs);
+        if (!n) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        s->objs = n; s->cap = nc;
+    }
+    size_t at = pos; /* VC1S:sorted-insert */
+    memmove(&s->objs[at + 1], &s->objs[at], (s->count - at) * sizeof *s->objs);
+    OmegaVcObject *o = &s->objs[at];
+    memcpy(o->semantic_id, sid, 32);
+    memcpy(o->vc_id, id, 32);
+    o->admission_kind = kind;
+    o->bytes = cp;
+    o->len = len;
+    s->count++;
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_insert(OmegaVcStore *s, const uint8_t *canonical, size_t len, const uint8_t claimed_vc_id[32]) {
+    return vcs_insert(s, canonical, len, claimed_vc_id, OMEGA_VCS_ADMISSION_VERIFIED);
+}
+
+int omega_vcstore_insert_bootstrap(OmegaVcStore *s, const uint8_t *canonical, size_t len, const uint8_t claimed_vc_id[32]) {
+    return vcs_insert(s, canonical, len, claimed_vc_id, OMEGA_VCS_ADMISSION_BOOTSTRAP); /* VC1S:kind-bootstrap */
+}
+
+int omega_vcstore_get(const OmegaVcStore *s, const uint8_t semantic_id[32], OmegaVcRecord *out) {
+    if (!s || !semantic_id || !out) return OMEGA_VCS_VCSTORE_MALFORMED;
+    size_t idx;
+    if (!vcs_find(s, semantic_id, &idx)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY;
+    return vcs_fetch(s, idx, out);
+}
+
+int omega_vcstore_receipt_of(const OmegaVcStore *s, const uint8_t semantic_id[32], uint8_t out_receipt[32]) {
+    if (!out_receipt) return OMEGA_VCS_VCSTORE_MALFORMED;
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    if (!rec) return OMEGA_VCS_VCSTORE_NOMEM;
+    int rc = omega_vcstore_get(s, semantic_id, rec);
+    if (rc == OMEGA_VCS_OK) memcpy(out_receipt, rec->vc.receipt_id, 32); /* VC1S:receipt-of */
+    free(rec);
+    return rc;
+}
+
+int omega_vcstore_admission_kind(const OmegaVcStore *s, const uint8_t semantic_id[32], uint8_t *out_kind) {
+    if (!out_kind) return OMEGA_VCS_VCSTORE_MALFORMED;
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    if (!rec) return OMEGA_VCS_VCSTORE_NOMEM;
+    int rc = omega_vcstore_get(s, semantic_id, rec);
+    if (rc == OMEGA_VCS_OK) *out_kind = rec->admission_kind;
+    free(rec);
+    return rc;
+}
+
+/* ---- dependency walk: post-order, shared by closure and the load-time graph check ---- */
+
+typedef struct { size_t idx; uint32_t n_dep, next; const uint8_t *deps; } frame_t;
+
+/* state: 0 unseen, 1 on the current path, 2 done. Visits root and everything it needs that is
+ * still unseen. Emits newly finished ids into out_ids while *emitted < cap, always counts. */
+static int vcs_walk(const OmegaVcStore *s, size_t root, uint8_t *state, frame_t *stack, OmegaVcRecord *rec,
+                    uint8_t *out_ids, size_t cap, size_t *emitted) {
+    /* VC1S:walk-names (no resolution step may read the name index) */
+    if (state[root] == 2) return OMEGA_VCS_OK;
+    int rc = vcs_fetch(s, root, rec);
+    if (rc) return rc;
+    size_t sp = 0;
+    state[root] = 1;
+    stack[sp++] = (frame_t){ root, rec->vc.n_dependencies, 0, rec->vc.dependencies };
+    while (sp) {
+        frame_t *f = &stack[sp - 1];
+        if (f->next < f->n_dep) {
+            const uint8_t *dep = f->deps + 64 * (size_t)f->next++; /* VC1S:walk-order */
+            size_t di;
+            if (!vcs_find(s, dep, &di)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY; /* VC1S:walk-dep-exists */
+            rc = vcs_fetch(s, di, rec);
+            if (rc) return rc;
+            if (memcmp(rec->vc.contract_id, dep + 32, 32) != 0) return OMEGA_VCS_UNVERIFIED_DEPENDENCY; /* VC1S:walk-contract */
+            if (state[di] == 1) return OMEGA_VCS_DEPENDENCY_CYCLE; /* VC1S:walk-cycle */
+            if (state[di] == 2) continue; /* VC1S:walk-visited */
+            state[di] = 1;
+            stack[sp++] = (frame_t){ di, rec->vc.n_dependencies, 0, rec->vc.dependencies };
+        } else {
+            state[f->idx] = 2;
+            if (*emitted < cap) memcpy(out_ids + 32 * *emitted, s->objs[f->idx].semantic_id, 32);
+            (*emitted)++;
+            sp--;
+        }
+    }
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_closure(const OmegaVcStore *s, const uint8_t id[32], uint8_t *out_ids, size_t cap, size_t *out_n) {
+    if (!out_n) return OMEGA_VCS_VCSTORE_MALFORMED;
+    *out_n = 0;
+    if (!s || !id || (cap && !out_ids)) return OMEGA_VCS_VCSTORE_MALFORMED;
+    size_t root;
+    if (!vcs_find(s, id, &root)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY;
+    uint8_t *state = calloc(s->count, 1);
+    frame_t *stack = malloc(s->count * sizeof *stack);
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    int rc;
+    size_t emitted = 0;
+    if (!state || !stack || !rec) { rc = OMEGA_VCS_VCSTORE_NOMEM; goto out; }
+    rc = vcs_walk(s, root, state, stack, rec, out_ids, cap, &emitted);
+    if (rc) goto out;
+    *out_n = emitted;
+    if (emitted > cap) rc = OMEGA_VCS_VCSTORE_CAPACITY; /* VC1S:walk-capacity */
+out:
+    free(state); free(stack); free(rec);
+    return rc;
+}
+
+/* Every dependency present with its contract, no cycle, over the whole store. */
+static int vcs_graph_check(const OmegaVcStore *s) {
+    if (s->count == 0) return OMEGA_VCS_OK;
+    uint8_t *state = calloc(s->count, 1);
+    frame_t *stack = malloc(s->count * sizeof *stack);
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    int rc = OMEGA_VCS_OK;
+    size_t emitted = 0;
+    if (!state || !stack || !rec) rc = OMEGA_VCS_VCSTORE_NOMEM;
+    for (size_t i = 0; !rc && i < s->count; i++) rc = vcs_walk(s, i, state, stack, rec, NULL, 0, &emitted);
+    free(state); free(stack); free(rec);
+    return rc;
+}
+
+/* ---- digests ---- */
+
+static void u32be(sha256_ctx *c, uint32_t v) {
+    uint8_t b[4] = { (uint8_t)(v >> 24), (uint8_t)(v >> 16), (uint8_t)(v >> 8), (uint8_t)v };
+    sha256_update(c, b, 4);
+}
+static void u64be(sha256_ctx *c, uint64_t v) { u32be(c, (uint32_t)(v >> 32)); u32be(c, (uint32_t)v); }
+
+int omega_vcstore_digest(const OmegaVcStore *s, uint8_t out[32]) {
+    if (!s || !out) return OMEGA_VCS_VCSTORE_MALFORMED;
+    sha256_ctx ctx;
+    sha256_init(&ctx);
+    sha256_update(&ctx, (const uint8_t *)"VCS1", 4); /* VC1S:digest-magic */
+    u64be(&ctx, s->count);
+    for (size_t i = 0; i < s->count; i++) {
+        const OmegaVcObject *o = &s->objs[i];
+        sha256_update(&ctx, o->semantic_id, 32);
+        uint8_t kind = o->admission_kind; /* VC1S:digest-kind */
+        sha256_update(&ctx, &kind, 1);
+        u64be(&ctx, o->len);
+        sha256_update(&ctx, o->bytes, o->len); /* VC1S:digest-bytes */
+    }
+    /* VC1S:digest-names (the name index is never part of the object digest) */
+    sha256_final(&ctx, out);
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_name_index_digest(const OmegaVcStore *s, uint8_t out[32]) {
+    if (!s || !out) return OMEGA_VCS_VCSTORE_MALFORMED;
+    sha256_ctx ctx;
+    sha256_init(&ctx);
+    sha256_update(&ctx, (const uint8_t *)"VCN1", 4);
+    u64be(&ctx, s->n_names);
+    for (size_t i = 0; i < s->n_names; i++) {
+        const OmegaVcName *nm = &s->names[i];
+        size_t l = strlen(nm->name);
+        u64be(&ctx, l);
+        sha256_update(&ctx, (const uint8_t *)nm->name, l);
+        sha256_update(&ctx, nm->id, 32); /* VC1S:namedigest-id */
+    }
+    sha256_final(&ctx, out);
+    return OMEGA_VCS_OK;
+}
+
+/* ---- name index ---- */
+
+static int name_valid(const char *name) {
+    size_t n = strlen(name);
+    if (n == 0 || n > MAX_NAME) return 0;
+    for (size_t i = 0; i < n; i++) {
+        char ch = name[i];
+        int alpha = (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '_';
+        int rest = alpha || (ch >= '0' && ch <= '9') || ch == '.' || ch == '-';
+        if (i == 0 ? !alpha : !rest) return 0;
+    }
+    return 1;
+}
+
+static int name_find(const OmegaVcStore *s, const char *name, size_t *pos) {
+    size_t lo = 0, hi = s->n_names;
+    while (lo < hi) {
+        size_t mid = lo + (hi - lo) / 2;
+        int c = strcmp(s->names[mid].name, name);
+        if (c == 0) { *pos = mid; return 1; }
+        if (c < 0) lo = mid + 1; else hi = mid;
+    }
+    *pos = lo;
+    return 0;
+}
+
+static int name_insert_at(OmegaVcStore *s, size_t pos, const char *name, const uint8_t *id) {
+    size_t l = strlen(name);
+    char *cp = malloc(l + 1);
+    if (!cp) return OMEGA_VCS_VCSTORE_NOMEM;
+    memcpy(cp, name, l + 1);
+    if (s->n_names == s->cap_names) {
+        size_t nc = s->cap_names ? s->cap_names * 2 : 8;
+        if (nc > SIZE_MAX / sizeof *s->names) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        OmegaVcName *n = realloc(s->names, nc * sizeof *s->names);
+        if (!n) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        s->names = n; s->cap_names = nc;
+    }
+    memmove(&s->names[pos + 1], &s->names[pos], (s->n_names - pos) * sizeof *s->names);
+    s->names[pos].name = cp;
+    memcpy(s->names[pos].id, id, 32);
+    s->n_names++;
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_name_bind(OmegaVcStore *s, const char *name, const uint8_t id[32]) {
+    if (!s || !name || !id) return OMEGA_VCS_VCSTORE_MALFORMED;
+    if (!name_valid(name)) return OMEGA_VCS_VCSTORE_MALFORMED; /* VC1S:name-valid */
+    size_t di;
+    if (!vcs_find(s, id, &di)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY; /* VC1S:name-id-exists */
+    /* VC1S:name-many (many names may point at one id) */
+    size_t np;
+    if (name_find(s, name, &np)) {
+        if (memcmp(s->names[np].id, id, 32) == 0) return OMEGA_VCS_OK;
+        return OMEGA_VCS_VCSTORE_NAME_EXISTS; /* VC1S:name-no-silent-rebind */
+    }
+    return name_insert_at(s, np, name, id); /* VC1S:name-sorted */
+}
+
+int omega_vcstore_name_rebind(OmegaVcStore *s, const char *name, const uint8_t id[32]) {
+    if (!s || !name || !id) return OMEGA_VCS_VCSTORE_MALFORMED;
+    size_t di, np;
+    if (!vcs_find(s, id, &di)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY; /* VC1S:rebind-id-exists */
+    if (!name_find(s, name, &np)) return OMEGA_VCS_VCSTORE_NOT_FOUND; /* VC1S:rebind-exists */
+    memcpy(s->names[np].id, id, 32); /* VC1S:rebind-write */
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_resolve_name(const OmegaVcStore *s, const char *name, uint8_t out_id[32]) {
+    if (!s || !name || !out_id) return OMEGA_VCS_VCSTORE_MALFORMED;
+    size_t np;
+    if (!name_find(s, name, &np)) return OMEGA_VCS_VCSTORE_NOT_FOUND;
+    memcpy(out_id, s->names[np].id, 32); /* VC1S:resolve */
+    return OMEGA_VCS_OK;
+}
+
+/* ---- persistence ---- */
+
+typedef struct { uint8_t *p; size_t n, cap; int err; } wbuf_t;
+
+static void w_put(wbuf_t *w, const void *d, size_t k) {
+    if (w->err) return;
+    if (w->n + k > w->cap) {
+        size_t nc = (w->n + k) * 2 + 256;
+        uint8_t *np = realloc(w->p, nc);
+        if (!np) { w->err = OMEGA_VCS_VCSTORE_NOMEM; return; }
+        w->p = np; w->cap = nc;
+    }
+    memcpy(w->p + w->n, d, k);
+    w->n += k;
+}
+static void w_u64(wbuf_t *w, uint64_t v) {
+    uint8_t b[8];
+    for (int i = 0; i < 8; i++) b[i] = (uint8_t)(v >> (56 - 8 * i));
+    w_put(w, b, 8);
+}
+
+int omega_vcstore_save(const OmegaVcStore *s, const char *path) {
+    if (!s || !path) return OMEGA_VCS_VCSTORE_MALFORMED;
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    if (!rec) return OMEGA_VCS_VCSTORE_NOMEM;
+    for (size_t i = 0; i < s->count; i++) {
+        int rc = vcs_fetch(s, i, rec); /* VC1S:save-verify */
+        if (rc) { free(rec); return rc; }
+    }
+    free(rec);
+    wbuf_t w = { 0, 0, 0, 0 };
+    w_put(&w, FILE_MAGIC, FILE_MAGIC_LEN);
+    w_u64(&w, s->count);
+    for (size_t i = 0; i < s->count; i++) {
+        w_put(&w, &s->objs[i].admission_kind, 1);
+        w_u64(&w, s->objs[i].len);
+        w_put(&w, s->objs[i].bytes, s->objs[i].len);
+    }
+    w_u64(&w, s->n_names);
+    for (size_t i = 0; i < s->n_names; i++) {
+        size_t l = strlen(s->names[i].name);
+        w_u64(&w, l);
+        w_put(&w, s->names[i].name, l);
+        w_put(&w, s->names[i].id, 32);
+    }
+    uint8_t d1[32], d2[32];
+    omega_vcstore_digest(s, d1);
+    omega_vcstore_name_index_digest(s, d2);
+    w_put(&w, d1, 32);
+    w_put(&w, d2, 32);
+    if (w.err) { free(w.p); return w.err; }
+
+    size_t pl = strlen(path);
+    char *tmp = malloc(pl + 5);
+    if (!tmp) { free(w.p); return OMEGA_VCS_VCSTORE_NOMEM; }
+    memcpy(tmp, path, pl); memcpy(tmp + pl, ".tmp", 5);
+    int rc = OMEGA_VCS_VCSTORE_IO;
+    FILE *f = fopen(tmp, "wb");
+    if (f) {
+        int ok = fwrite(w.p, 1, w.n, f) == w.n && fflush(f) == 0 && fsync(fileno(f)) == 0;
+        ok = (fclose(f) == 0) && ok;
+        if (ok && rename(tmp, path) == 0) rc = OMEGA_VCS_OK;
+        else remove(tmp);
+    }
+    free(tmp); free(w.p);
+    return rc;
+}
+
+typedef struct { const uint8_t *b; size_t n, pos; int bad; } rdr_t;
+
+static const uint8_t *r_take(rdr_t *r, size_t k) {
+    if (r->bad || r->n - r->pos < k) { r->bad = 1; return NULL; }
+    const uint8_t *p = r->b + r->pos; r->pos += k;
+    return p;
+}
+static uint64_t r_u64(rdr_t *r) {
+    const uint8_t *p = r_take(r, 8);
+    if (!p) return 0;
+    uint64_t v = 0;
+    for (int i = 0; i < 8; i++) v = v << 8 | p[i];
+    return v;
+}
+
+/* Append an object that is already known to sort after every stored one. */
+static int vcs_append(OmegaVcStore *s, const OmegaVcRecord *rec, uint8_t kind, const uint8_t id[32]) {
+    uint8_t *cp = malloc(rec->canonical_len);
+    if (!cp) return OMEGA_VCS_VCSTORE_NOMEM;
+    memcpy(cp, rec->canonical, rec->canonical_len);
+    if (s->count == s->cap) {
+        size_t nc = s->cap ? s->cap * 2 : 16;
+        if (nc > SIZE_MAX / sizeof *s->objs) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        OmegaVcObject *n = realloc(s->objs, nc * sizeof *s->objs);
+        if (!n) { free(cp); return OMEGA_VCS_VCSTORE_NOMEM; }
+        s->objs = n; s->cap = nc;
+    }
+    OmegaVcObject *o = &s->objs[s->count++];
+    memcpy(o->semantic_id, rec->vc.semantic_id, 32);
+    memcpy(o->vc_id, id, 32);
+    o->admission_kind = kind;
+    o->bytes = cp;
+    o->len = rec->canonical_len;
+    return OMEGA_VCS_OK;
+}
+
+static int parse_store(OmegaVcStore *t, const uint8_t *b, size_t n) {
+    rdr_t r = { b, n, 0, 0 };
+    const uint8_t *m = r_take(&r, FILE_MAGIC_LEN);
+    if (!m || memcmp(m, FILE_MAGIC, FILE_MAGIC_LEN) != 0) return OMEGA_VCS_VCSTORE_MALFORMED; /* VC1S:load-magic */
+    uint64_t count = r_u64(&r);
+    if (r.bad || count > (n - r.pos) / 9) return OMEGA_VCS_VCSTORE_MALFORMED;
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    if (!rec) return OMEGA_VCS_VCSTORE_NOMEM;
+    int rc = OMEGA_VCS_OK;
+    for (uint64_t i = 0; i < count && !rc; i++) {
+        const uint8_t *kp = r_take(&r, 1);
+        uint64_t len = r_u64(&r);
+        if (r.bad || len > n - r.pos) { rc = OMEGA_VCS_VCSTORE_MALFORMED; break; }
+        uint8_t kind = *kp;
+        if (kind != OMEGA_VCS_ADMISSION_VERIFIED && kind != OMEGA_VCS_ADMISSION_BOOTSTRAP) { rc = OMEGA_VCS_VCSTORE_MALFORMED; break; } /* VC1S:load-kind */
+        const uint8_t *ob = r_take(&r, (size_t)len);
+        rc = omega_vc_decode(ob, (size_t)len, &rec->vc);
+        if (rc) break;
+        if (t->count > 0 && memcmp(t->objs[t->count - 1].semantic_id, rec->vc.semantic_id, 32) >= 0) { rc = OMEGA_VCS_VCSTORE_MALFORMED; break; } /* VC1S:load-order */
+        rec->canonical = ob;
+        rec->canonical_len = (size_t)len;
+        uint8_t id[32];
+        omega_vc_compute_id(ob, (size_t)len, id);
+        rc = vcs_append(t, rec, kind, id);
+    }
+    free(rec);
+    if (rc) return rc;
+    uint64_t nn = r_u64(&r);
+    if (r.bad || nn > (n - r.pos) / 41) return OMEGA_VCS_VCSTORE_MALFORMED;
+    for (uint64_t i = 0; i < nn && !rc; i++) {
+        uint64_t l = r_u64(&r);
+        if (r.bad || l == 0 || l > MAX_NAME) return OMEGA_VCS_VCSTORE_MALFORMED;
+        const uint8_t *nb = r_take(&r, (size_t)l);
+        const uint8_t *id = r_take(&r, 32);
+        if (!nb || !id) return OMEGA_VCS_VCSTORE_MALFORMED;
+        char name[MAX_NAME + 1];
+        memcpy(name, nb, (size_t)l);
+        name[l] = 0;
+        if (strlen(name) != l || !name_valid(name)) return OMEGA_VCS_VCSTORE_MALFORMED;
+        size_t di;
+        if (!vcs_find(t, id, &di)) return OMEGA_VCS_UNVERIFIED_DEPENDENCY; /* VC1S:load-name-id */
+        if (t->n_names > 0 && strcmp(t->names[t->n_names - 1].name, name) >= 0) return OMEGA_VCS_VCSTORE_MALFORMED;
+        rc = name_insert_at(t, t->n_names, name, id); /* VC1S:load-names */
+    }
+    if (rc) return rc;
+    const uint8_t *tr = r_take(&r, 64);
+    if (!tr) return OMEGA_VCS_VCSTORE_MALFORMED;
+    if (r.pos != r.n) return OMEGA_VCS_VCSTORE_MALFORMED; /* VC1S:load-trailing */
+    rc = vcs_graph_check(t); /* VC1S:load-graph */
+    if (rc) return rc;
+    uint8_t d1[32], d2[32];
+    omega_vcstore_digest(t, d1);
+    omega_vcstore_name_index_digest(t, d2);
+    if (memcmp(d1, tr, 32) != 0) return OMEGA_VCS_VCSTORE_ID_MISMATCH; /* VC1S:load-digest-obj */
+    if (memcmp(d2, tr + 32, 32) != 0) return OMEGA_VCS_VCSTORE_ID_MISMATCH; /* VC1S:load-digest-names */
+    return OMEGA_VCS_OK;
+}
+
+int omega_vcstore_load(OmegaVcStore *s, const char *path) {
+    if (!s || !path) return OMEGA_VCS_VCSTORE_MALFORMED;
+    FILE *f = fopen(path, "rb");
+    if (!f) return OMEGA_VCS_VCSTORE_IO;
+    uint8_t *buf = NULL;
+    size_t n = 0, cap = 0;
+    int rc = OMEGA_VCS_OK;
+    for (;;) {
+        if (n == cap) {
+            size_t nc = cap ? cap * 2 : 4096;
+            uint8_t *nb = realloc(buf, nc);
+            if (!nb) { rc = OMEGA_VCS_VCSTORE_NOMEM; break; }
+            buf = nb; cap = nc;
+        }
+        size_t got = fread(buf + n, 1, cap - n, f);
+        n += got;
+        if (got == 0) { if (ferror(f)) rc = OMEGA_VCS_VCSTORE_IO; break; }
+    }
+    fclose(f);
+    if (rc) { free(buf); return rc; }
+    OmegaVcStore t;
+    omega_vcstore_init(&t);
+    rc = parse_store(&t, buf ? buf : ZERO32, n);
+    free(buf);
+    if (rc) {
+        omega_vcstore_destroy(&t); /* VC1S:load-fail */
+        return rc;
+    }
+    omega_vcstore_destroy(s);
+    *s = t;
+    return OMEGA_VCS_OK;
+}
diff --git a/src/omega_vcstore.h b/src/omega_vcstore.h
new file mode 100644
index 000000000..25a4ed33c
--- /dev/null
+++ b/src/omega_vcstore.h
@@ -0,0 +1,220 @@
+#ifndef OMEGA_VCSTORE_H
+#define OMEGA_VCSTORE_H
+
+/* omega_vcstore: the Verified Crumb Store (VC1 stage 3, ADR 0029).
+ *
+ * A content-addressed, immutable store of VerifiedCrumbV1 records (aien-protocols
+ * specs/verified-crumb/SPEC.md), keyed by the 32-byte semantic_id (the Omega program id).
+ * The canonical encoding, the digest_kind byte and the VC id derivation are those of SPEC.md,
+ * byte for byte (VC id = SHA-256 over the canonical bytes, domain tag included).
+ *
+ * WHAT THE STORE DOES
+ *  - insert: decode (format refusals of SPEC 3.6), recompute the VC id and compare it with the
+ *    caller's claimed id, refuse a different record for an existing semantic_id (immutability),
+ *    accept identical bytes as a no-op, and require every dependency to be in the store already
+ *    with a matching contract_id (fail closed, cycles impossible by construction and refused).
+ *  - get / closure: recompute the VC id of the stored bytes on every access and refuse on mismatch.
+ *  - digest: streaming SHA-256 over every object (semantic_id order, admission kind, canonical
+ *    bytes). Independent of insert order. Names are never part of it.
+ *  - save / load: one file, explicit big-endian, digests at the end, load recomputes everything.
+ *
+ * WHAT THE STORE DOES NOT DO
+ *  - It does NOT verify receipts. It holds each record's receipt_id and exposes it through
+ *    omega_vcstore_receipt_of(); checking the receipt (SPEC 5.1) and the verifier profile is the
+ *    evidence verifier's job (VC1 stage 4/5). A record in the store is "well-formed, immutable,
+ *    closed under dependencies", not "proven". The unused ADR 0029 Decision 9 codes below are
+ *    reserved for that verifier and the resolver.
+ *  - It does not read lockfiles and does not decide trust from a name.
+ *
+ * ADMISSION KIND: two insert functions, as in omega_library (#221). VERIFIED is the normal path.
+ * BOOTSTRAP is for the manually audited GENESIS set only (VC1 stage 6). There is no flag,
+ * environment variable or build option that unlocks it or skips any refusal; reviewers must
+ * reject any caller of omega_vcstore_insert_bootstrap that is not the genesis loader. For a
+ * bootstrap record the receipt_id field carries the hash of the audit record. The kind is part
+ * of the state digest.
+ *
+ * NAME INDEX: a separate map name -> semantic_id. Many names may point at one id. A bound name
+ * changes only through the explicit omega_vcstore_name_rebind(). Nothing in get, closure,
+ * insert, receipt_of or the state digest reads it; omega_vcstore_resolve_name() is the only
+ * reader and returns the id and nothing else. It has its own digest. Names are convenience,
+ * digests are authority.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define OMEGA_VC_ID_BYTES 32
+#define OMEGA_VC_FORMAT_VERSION 1u
+#define OMEGA_VC_MAX_ENTRIES 256     /* per list, SPEC 3.3; over the limit is refused, never truncated */
+#define OMEGA_VC_MAX_STRING 256
+#define OMEGA_VC_DIGEST_SOURCE 0x01  /* canonical source */
+#define OMEGA_VC_DIGEST_IR     0x02  /* canonical IR */
+
+#define OMEGA_VCS_ADMISSION_VERIFIED  1u
+#define OMEGA_VCS_ADMISSION_BOOTSTRAP 2u   /* genesis set only */
+
+/* Result codes. 0 is success. Names are what matters (omega_vcstore_code_name). */
+enum {
+    OMEGA_VCS_OK = 0,
+    /* ARCH-0029 Decision 9, in the ADR's order */
+    OMEGA_VCS_UNVERIFIED_DEPENDENCY = 1,   /* absent id, absent dependency, contract mismatch on an edge */
+    OMEGA_VCS_MISSING_RECEIPT,             /* all-zero receipt_id */
+    OMEGA_VCS_RECEIPT_HASH_MISMATCH,       /* reserved: evidence verifier */
+    OMEGA_VCS_DEPENDENCY_NOT_PINNED,       /* reserved: resolver / lockfile */
+    OMEGA_VCS_DEPENDENCY_CYCLE,            /* self dependency, or a cycle in a loaded or tampered graph */
+    OMEGA_VCS_STALE_RECEIPT,               /* reserved: evidence verifier */
+    OMEGA_VCS_UNDECLARED_IMPORT,           /* reserved: compiler */
+    OMEGA_VCS_TAINTED_ARTIFACT,            /* reserved: resolver */
+    OMEGA_VCS_UNKNOWN_VERIFIER_PROFILE,    /* reserved: evidence verifier */
+    /* SPEC 3.6 format refusals (same numbers as vc1-check) */
+    OMEGA_VCS_BAD_DOMAIN_TAG = 20,
+    OMEGA_VCS_UNKNOWN_FORMAT_VERSION,
+    OMEGA_VCS_TRUNCATED,
+    OMEGA_VCS_TRAILING_BYTES,
+    OMEGA_VCS_DUPLICATE_DEPENDENCY,
+    OMEGA_VCS_UNSORTED_DEPENDENCIES,
+    OMEGA_VCS_NONCANONICAL_SET,
+    OMEGA_VCS_BAD_STRING,
+    OMEGA_VCS_ZERO_ID,
+    OMEGA_VCS_TOO_MANY_ENTRIES,
+    OMEGA_VCS_BAD_DIGEST_KIND,
+    /* store-local */
+    OMEGA_VCS_VCSTORE_ID_MISMATCH = 40,    /* recomputed VC id or loaded digest differs */
+    OMEGA_VCS_VCSTORE_IMMUTABLE_CONFLICT,  /* same semantic_id, different bytes or admission kind */
+    OMEGA_VCS_VCSTORE_MALFORMED,           /* bad argument, bad name, bad store file */
+    OMEGA_VCS_VCSTORE_NOT_FOUND,           /* name not bound */
+    OMEGA_VCS_VCSTORE_NAME_EXISTS,         /* name already bound to another id; use name_rebind */
+    OMEGA_VCS_VCSTORE_CAPACITY,            /* closure output array too small (needed count returned) */
+    OMEGA_VCS_VCSTORE_NOMEM,
+    OMEGA_VCS_VCSTORE_IO
+};
+
+const char *omega_vcstore_code_name(int code);
+
+/* ---- decoded view (pointers into the canonical bytes; no copies) ---- */
+typedef struct { const uint8_t *p; size_t len; } OmegaVcStr;
+
+typedef struct {
+    uint32_t format_version;
+    const uint8_t *semantic_id;           /* 32 */
+    const uint8_t *contract_id;           /* 32 */
+    uint8_t digest_kind;
+    const uint8_t *source_or_ir_digest;   /* 32 */
+    uint32_t n_realizations;
+    const uint8_t *realization_ids;       /* n x 32 */
+    uint32_t n_dependencies;
+    const uint8_t *dependencies;          /* n x 64: semantic_id (32) then required_contract (32) */
+    const uint8_t *receipt_id;            /* 32 */
+    OmegaVcStr verifier_profile, verifier_version;
+    const uint8_t *evidence_root;         /* 32 */
+    uint32_t n_exports;
+    OmegaVcStr exports[OMEGA_VC_MAX_ENTRIES];
+    uint32_t n_capabilities;
+    OmegaVcStr capabilities[OMEGA_VC_MAX_ENTRIES];
+} OmegaVcView;
+
+/* Format-only check of canonical bytes (SPEC 3, refusal order SPEC 3.5). Returns 0 or the first
+ * format refusal code. Never sorts: unsorted input is refused. On success fills *view. */
+int omega_vc_decode(const uint8_t *bytes, size_t len, OmegaVcView *view);
+
+/* VC id = SHA-256(canonical bytes), tag included (SPEC 3.4). Does not validate. */
+void omega_vc_compute_id(const uint8_t *bytes, size_t len, uint8_t out[OMEGA_VC_ID_BYTES]);
+
+/* ---- store ----
+ * The fields are public so tests can inspect and corrupt them; production code must treat them
+ * as read-only and use the functions. objs is sorted ascending by semantic_id (memcmp). */
+typedef struct {
+    uint8_t semantic_id[32];
+    uint8_t vc_id[32];
+    uint8_t admission_kind;     /* OMEGA_VCS_ADMISSION_* */
+    uint8_t *bytes;             /* owned canonical bytes, stable until destroy */
+    size_t len;
+} OmegaVcObject;
+
+typedef struct {
+    char *name;                 /* owned, NUL-terminated */
+    uint8_t id[32];
+} OmegaVcName;
+
+typedef struct {
+    OmegaVcObject *objs;
+    size_t count, cap;
+    OmegaVcName *names;         /* sorted ascending by strcmp */
+    size_t n_names, cap_names;
+} OmegaVcStore;
+
+typedef struct {
+    const uint8_t *canonical;   /* points into the store, valid until destroy */
+    size_t canonical_len;
+    uint8_t vc_id[32];
+    uint8_t admission_kind;
+    OmegaVcView vc;
+} OmegaVcRecord;
+
+int  omega_vcstore_init(OmegaVcStore *s);
+void omega_vcstore_destroy(OmegaVcStore *s);
+size_t omega_vcstore_count(const OmegaVcStore *s);
+
+/* Insert a verified Verified Crumb (admission kind VERIFIED). claimed_vc_id is required (NULL is
+ * MALFORMED, never "skip the check"). The store is unchanged on every refusal. Refusals:
+ *  - NULL argument, zero length: VCSTORE_MALFORMED
+ *  - any SPEC 3.6 format refusal (includes MISSING_RECEIPT for a zero receipt_id and
+ *    DEPENDENCY_CYCLE for a self dependency)
+ *  - SHA-256(bytes) != claimed_vc_id: VCSTORE_ID_MISMATCH
+ *  - semantic_id already present with different bytes or another admission kind:
+ *    VCSTORE_IMMUTABLE_CONFLICT (identical bytes and kind: success, no change)
+ *  - a dependency semantic_id not in the store, or whose contract_id differs from the entry's
+ *    required_contract: UNVERIFIED_DEPENDENCY
+ *  - out of memory: VCSTORE_NOMEM
+ * There is no capacity limit: the store grows. */
+int omega_vcstore_insert(OmegaVcStore *s, const uint8_t *canonical, size_t len,
+                         const uint8_t claimed_vc_id[32]);
+
+/* Genesis loading only. Same refusals; admission kind BOOTSTRAP. See the header comment. */
+int omega_vcstore_insert_bootstrap(OmegaVcStore *s, const uint8_t *canonical, size_t len,
+                                   const uint8_t claimed_vc_id[32]);
+
+/* Fetch by semantic_id. Recomputes the VC id of the stored bytes and re-decodes them; any
+ * mismatch is VCSTORE_ID_MISMATCH. Absent: UNVERIFIED_DEPENDENCY. */
+int omega_vcstore_get(const OmegaVcStore *s, const uint8_t semantic_id[32], OmegaVcRecord *out);
+
+/* The receipt_id the record carries. NOT verified here (see header). */
+int omega_vcstore_receipt_of(const OmegaVcStore *s, const uint8_t semantic_id[32], uint8_t out_receipt[32]);
+
+int omega_vcstore_admission_kind(const OmegaVcStore *s, const uint8_t semantic_id[32], uint8_t *out_kind);
+
+/* Transitive dependency closure of id, root included, in deterministic post-order: every
+ * dependency appears before whoever needs it; dependencies are visited in ascending semantic_id
+ * order; each id appears once. out_ids receives n x 32 bytes; *out_n the count. Each record is
+ * fetched with the get checks, each edge's contract is checked. Errors: UNVERIFIED_DEPENDENCY
+ * (absent id/dependency, contract mismatch), VCSTORE_ID_MISMATCH, DEPENDENCY_CYCLE. If cap is
+ * smaller than the closure: VCSTORE_CAPACITY with *out_n = the needed count (cap 0 and
+ * out_ids NULL may be used to ask for the size). On any other error *out_n = 0. Never a
+ * partial success. Does not read the name index. */
+int omega_vcstore_closure(const OmegaVcStore *s, const uint8_t id[32],
+                          uint8_t *out_ids, size_t cap, size_t *out_n);
+
+/* State digest over the objects only (never the names). Streaming; no size limit. */
+int omega_vcstore_digest(const OmegaVcStore *s, uint8_t out[32]);
+
+/* ---- name index ---- names match [A-Za-z_][A-Za-z0-9_.-]{0,127} (the omega.lock grammar) */
+int omega_vcstore_name_bind(OmegaVcStore *s, const char *name, const uint8_t id[32]);
+int omega_vcstore_name_rebind(OmegaVcStore *s, const char *name, const uint8_t id[32]);
+int omega_vcstore_resolve_name(const OmegaVcStore *s, const char *name, uint8_t out_id[32]);
+int omega_vcstore_name_index_digest(const OmegaVcStore *s, uint8_t out[32]);
+
+/* ---- persistence ----
+ * File layout (all integers big-endian, no host structs):
+ *   "AIEN_VCSTORE_V1" (15 bytes)
+ *   u64 object count, then per object: u8 admission_kind, u64 length, canonical bytes
+ *     (objects strictly ascending by semantic_id)
+ *   u64 name count, then per name: u64 length, name bytes, 32-byte id (names strictly ascending)
+ *   32 bytes object state digest, 32 bytes name-index digest
+ *   (end of file: no trailing byte)
+ * load builds a new store, re-decodes and re-hashes every object, re-checks dependencies and
+ * acyclicity, recomputes both digests and refuses on any mismatch. The digests are integrity
+ * checks, not signatures: anyone can recompute them. On failure *s is unchanged; on success its old contents are replaced (s must be initialised). */
+int omega_vcstore_save(const OmegaVcStore *s, const char *path);
+int omega_vcstore_load(OmegaVcStore *s, const char *path);
+
+#endif /* OMEGA_VCSTORE_H */
diff --git a/tests/test_omega_vcstore.c b/tests/test_omega_vcstore.c
new file mode 100644
index 000000000..a0f437dd6
--- /dev/null
+++ b/tests/test_omega_vcstore.c
@@ -0,0 +1,912 @@
+/* test_omega_vcstore.c -- VC1 stage 3: the Verified Crumb Store.
+ *
+ * Usage (run from the repository root; golden vectors are read from tests/vcstore/golden/):
+ *   test_omega_vcstore            run every check; exit 0 only if all pass
+ *   test_omega_vcstore <mutant>   the binary was linked against a deliberately broken copy of
+ *                                 src/omega_vcstore.c (built by `make test-vcstore`); run every
+ *                                 check and require the mapped check to FAIL. Exit 1 = mutant
+ *                                 killed (what the Makefile asserts), 3 = survived, 2 = unknown.
+ *
+ * Nothing here is hardcoded PASS: accepted ids come from golden/expected.txt (computed by
+ * aien-protocols with sha256sum, independent of this code), the state digest and the store file
+ * are re-derived here by a second, independent implementation, and graphs are built with a
+ * test-side encoder that does not share code with the decoder under test.
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "omega_vcstore.h"
+#include "sha256.h"
+
+#define GOLDEN "tests/vcstore/golden"
+
+static const struct { const char *mutant, *check; } MUTANTS[] = {
+    /* decoder */
+    { "refuse-valid",            "accept-v01_minimal" },
+    { "refuse-existing-dep",     "accept-v02_deps" },
+    { "caps-reversed",           "accept-v03_capabilities" },
+    { "kind-source-only",        "accept-v04_ir_kind" },
+    { "id-hash",                 "accept-ids-match-golden" },
+    { "dec-dep-dup",             "refuse-r01_duplicate_dep" },
+    { "dec-dep-order",           "refuse-r02_unsorted_deps" },
+    { "dec-receipt",             "refuse-r03_zero_receipt_id" },
+    { "dec-dep-self",            "refuse-r04_self_dependency" },
+    { "dec-trailing",            "refuse-r05_trailing_byte" },
+    { "dec-version",             "refuse-r06_unknown_version" },
+    { "dec-truncated",           "refuse-r07_truncated" },
+    { "dec-tag",                 "refuse-r08_bad_domain_tag" },
+    { "dec-exports-order",       "refuse-r09_unsorted_exports" },
+    { "dec-kind",                "refuse-r10_bad_digest_kind" },
+    { "dec-zero-ids",            "refuse-r11_zero_id" },
+    { "dec-string-char",         "refuse-r12_bad_string" },
+    { "dec-count",               "refuse-r13_too_many_entries" },
+    { "dec-real-order",          "refuse-unsorted-realizations" },
+    { "dec-caps-order",          "refuse-unsorted-capabilities" },
+    { "dec-dep-zero",            "refuse-zero-dependency-id" },
+    { "dec-evroot",              "refuse-zero-evidence-root" },
+    { "dec-string-empty",        "refuse-bad-string-empty" },
+    { "dec-string-max",          "refuse-bad-string-too-long" },
+    /* insert */
+    { "claimed-required",        "null-claimed-id-refused" },
+    { "insert-idcheck",          "claimed-id-mismatch-refused" },
+    { "idempotent",              "identical-insert-is-noop" },
+    { "idempotent-ignores-kind", "kind-switch-refused" },
+    { "immutable",               "immutable-conflict-refused" },
+    { "dep-exists",              "missing-dep-refused" },
+    { "dep-contract",            "dep-contract-mismatch-refused" },
+    { "no-cap",                  "store-grows-past-old-caps" },
+    { "sorted-insert",           "digest-independent-of-insert-order" },
+    { "kind-bootstrap",          "bootstrap-kind-recorded" },
+    /* get, receipt */
+    { "get-recompute",           "get-detects-corrupt-bytes" },
+    { "get-key",                 "get-detects-key-mismatch" },
+    { "receipt-of",              "receipt-of-returns-receipt-id" },
+    /* closure */
+    { "walk-order",              "closure-order-deterministic" },
+    { "walk-visited",            "closure-visits-each-id-once" },
+    { "walk-capacity",           "closure-capacity-refused" },
+    { "walk-dep-exists",         "closure-missing-dep-refused" },
+    { "walk-contract",           "closure-contract-mismatch-refused" },
+    { "walk-cycle",              "closure-cycle-refused" },
+    { "walk-names",              "names-do-not-affect-resolution" },
+    /* digests */
+    { "digest-magic",            "digest-matches-reference" },
+    { "digest-kind",             "bootstrap-vs-verified-digest-differ" },
+    { "digest-bytes",            "digest-covers-bytes" },
+    { "digest-names",            "name-index-never-changes-object-digest" },
+    { "namedigest-id",           "name-index-digest-covers-id" },
+    { "name-sorted",             "name-index-digest-order-independent" },
+    /* names */
+    { "name-many",               "name-bind-many-to-one" },
+    { "name-no-silent-rebind",   "name-no-silent-rebind" },
+    { "rebind-write",            "name-rebind-explicit" },
+    { "rebind-exists",           "name-rebind-unbound-refused" },
+    { "rebind-id-exists",        "name-rebind-unknown-id-refused" },
+    { "name-id-exists",          "name-bind-unknown-id-refused" },
+    { "name-valid",              "name-invalid-refused" },
+    { "resolve",                 "resolve-name-returns-id" },
+    /* persistence */
+    { "load-names",              "save-load-round-trip" },
+    { "load-fail",               "load-failure-leaves-store-unchanged" },
+    { "load-magic",              "tamper-every-byte-and-prefix-refused" },
+    { "load-digest-obj",         "tamper-object-digest-refused" },
+    { "load-digest-names",       "tamper-name-digest-refused" },
+    { "load-trailing",           "trailing-byte-refused" },
+    { "load-kind",               "load-bad-kind-refused" },
+    { "load-order",              "load-unsorted-objects-refused" },
+    { "load-graph",              "load-cycle-refused" },
+    { "load-graph-missing",      "load-missing-dep-refused" },
+    { "load-name-id",            "load-name-unknown-id-refused" },
+    { "save-verify",             "save-refuses-corrupt-store" },
+};
+#define N_MUT (sizeof MUTANTS / sizeof MUTANTS[0])
+
+static const char *g_mutant, *g_expect_check;
+static int g_failed, g_expect_failed;
+
+static void check(const char *name, int ok) {
+    printf("%s %s\n", ok ? "PASS" : "FAIL", name);
+    if (!ok) {
+        g_failed++;
+        if (g_expect_check && strcmp(name, g_expect_check) == 0) g_expect_failed = 1;
+    }
+}
+/* A setup step that cannot complete is a hard error. Under a mutant it is accepted only if the
+ * mapped check had already failed (the Makefile accepts exactly "KILLED by", exit 1). */
+static void setup_fail(const char *what) {
+    if (g_mutant && g_expect_failed) { printf("MUTANT %s KILLED by %s (a later fixture then failed: %s)\n", g_mutant, g_expect_check, what); exit(1); }
+    if (g_mutant) { printf("MUTANT %s SETUP-BROKEN before check %s ran (%s)\n", g_mutant, g_expect_check, what); exit(4); }
+    fprintf(stderr, "setup failed: %s\n", what);
+    exit(2);
+}
+
+/* ---- byte helpers ---- */
+typedef struct { uint8_t *p; size_t n, cap; } B;
+static void bput(B *b, const void *d, size_t k) {
+    if (b->n + k > b->cap) { b->cap = (b->n + k) * 2 + 64; b->p = realloc(b->p, b->cap); if (!b->p) setup_fail("oom"); }
+    if (k) memcpy(b->p + b->n, d, k);
+    b->n += k;
+}
+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); }
+static void bu64(B *b, uint64_t v) { bu32(b, (uint32_t)(v >> 32)); bu32(b, (uint32_t)v); }
+static void bstr(B *b, const char *s) { size_t n = strlen(s); bu64(b, n); bput(b, s, n); }
+
+static void mkid(uint8_t out[32], uint8_t b0) { memset(out, 0x77, 32); out[0] = b0; }
+static void mkid2(uint8_t out[32], uint8_t b0, uint8_t b1) { memset(out, 0x77, 32); out[0] = b0; out[1] = b1; }
+/* the contract id of a program is its id with the top bit of byte 0 flipped */
+static void con_of(const uint8_t sid[32], uint8_t out[32]) { memcpy(out, sid, 32); out[0] ^= 0x80; }
+
+/* ---- test-side encoder (writes lists exactly as given: no sorting, no validation) ---- */
+typedef struct {
+    uint32_t ver;
+    uint8_t sem[32], con[32], src[32], rcpt[32], root[32];
+    uint8_t kind;
+    uint32_t n_real; const uint8_t (*real)[32];
+    uint32_t n_dep;  const uint8_t (*dep)[64];
+    const char *prof, *pver;
+    uint32_t n_exp; const char *const *exp;
+    uint32_t n_cap; const char *const *cap;
+} Spec;
+
+static void spec_default(Spec *s, const uint8_t sem[32]) {
+    memset(s, 0, sizeof *s);
+    s->ver = 1; s->kind = 1;
+    memcpy(s->sem, sem, 32);
+    con_of(sem, s->con);
+    memset(s->src, 0x33, 32);
+    memset(s->rcpt, 0x55, 32); s->rcpt[0] = sem[0]; s->rcpt[1] = sem[1];
+    memset(s->root, 0x66, 32);
+    s->prof = "test-profile"; s->pver = "1.0.0";
+}
+static void encode(B *o, const Spec *s) {
+    o->n = 0;
+    bput(o, "AIEN_VERIFIED_CRUMB_V1", 22);
+    bu32(o, s->ver);
+    bput(o, s->sem, 32); bput(o, s->con, 32); bput(o, &s->kind, 1); bput(o, s->src, 32);
+    bu32(o, s->n_real); for (uint32_t i = 0; i < s->n_real; i++) bput(o, s->real[i], 32);
+    bu32(o, s->n_dep);  for (uint32_t i = 0; i < s->n_dep; i++) bput(o, s->dep[i], 64);
+    bput(o, s->rcpt, 32); bstr(o, s->prof); bstr(o, s->pver); bput(o, s->root, 32);
+    bu32(o, s->n_exp); for (uint32_t i = 0; i < s->n_exp; i++) bstr(o, s->exp[i]);
+    bu32(o, s->n_cap); for (uint32_t i = 0; i < s->n_cap; i++) bstr(o, s->cap[i]);
+}
+static int ins_kind(OmegaVcStore *st, const Spec *sp, int bootstrap) {
+    B b = { 0, 0, 0 };
+    encode(&b, sp);
+    uint8_t id[32];
+    omega_vc_compute_id(b.p, b.n, id);
+    int rc = bootstrap ? omega_vcstore_insert_bootstrap(st, b.p, b.n, id) : omega_vcstore_insert(st, b.p, b.n, id);
+    free(b.p);
+    return rc;
+}
+static int ins(OmegaVcStore *st, const Spec *sp) { return ins_kind(st, sp, 0); }
+
+/* a node whose dependencies are given by id; each required contract is the dependency's own contract */
+static int node_kind(OmegaVcStore *st, const uint8_t sid[32], const uint8_t (*deps)[32], uint32_t nd, int bootstrap) {
+    Spec sp;
+    spec_default(&sp, sid);
+    uint8_t (*d)[64] = calloc(nd ? nd : 1, 64);
+    if (!d) setup_fail("oom");
+    for (uint32_t i = 0; i < nd; i++) { memcpy(d[i], deps[i], 32); con_of(deps[i], d[i] + 32); }
+    sp.n_dep = nd; sp.dep = (const uint8_t (*)[64])d;
+    int rc = ins_kind(st, &sp, bootstrap);
+    free(d);
+    return rc;
+}
+static int node(OmegaVcStore *st, const uint8_t sid[32], const uint8_t (*deps)[32], uint32_t nd) { return node_kind(st, sid, deps, nd, 0); }
+
+static OmegaVcStore *new_store(void) {
+    OmegaVcStore *s = calloc(1, sizeof *s);
+    if (!s || omega_vcstore_init(s) != 0) setup_fail("store");
+    return s;
+}
+static void free_store(OmegaVcStore *s) { omega_vcstore_destroy(s); free(s); }
+static void dig(const OmegaVcStore *s, uint8_t out[32]) { if (omega_vcstore_digest(s, out) != 0) setup_fail("digest"); }
+static int same_digest(const OmegaVcStore *a, const OmegaVcStore *b) {
+    uint8_t x[32], y[32]; dig(a, x); dig(b, y); return memcmp(x, y, 32) == 0;
+}
+
+/* the diamond: R needs B and C, both need D. Ids ascend with the letters' order below. */
+static uint8_t D[32], Bn[32], C[32], R[32];
+static void diamond_ids(void) { mkid(D, 0x10); mkid(Bn, 0x20); mkid(C, 0x30); mkid(R, 0x40); }
+static int build_diamond(OmegaVcStore *s, int swap_bc) {
+    uint8_t dD[1][32], dR[2][32];
+    memcpy(dD[0], D, 32);
+    memcpy(dR[0], Bn, 32); memcpy(dR[1], C, 32);
+    int rc = node(s, D, NULL, 0);
+    if (swap_bc) { rc |= node(s, C, dD, 1); rc |= node(s, Bn, dD, 1); }
+    else         { rc |= node(s, Bn, dD, 1); rc |= node(s, C, dD, 1); }
+    rc |= node(s, R, dR, 2);
+    return rc;
+}
+
+/* ---- golden corpus ---- */
+static uint8_t *read_hex(const char *path, size_t *n_out) {
+    FILE *f = fopen(path, "rb");
+    if (!f) return NULL;
+    size_t cap = 4096, n = 0; char *t = malloc(cap); int ch;
+    while ((ch = fgetc(f)) != EOF) {
+        if (ch == '\n' || ch == '\r' || ch == ' ') continue;
+        if (n + 1 > cap) { cap *= 2; t = realloc(t, cap); }
+        t[n++] = (char)ch;
+    }
+    fclose(f);
+    uint8_t *b = malloc(n / 2 + 1);
+    for (size_t i = 0; i + 1 < n; i += 2) {
+        int hi = t[i] <= '9' ? t[i] - '0' : t[i] - 'a' + 10, lo = t[i + 1] <= '9' ? t[i + 1] - '0' : t[i + 1] - 'a' + 10;
+        b[i / 2] = (uint8_t)(hi << 4 | lo);
+    }
+    free(t); *n_out = n / 2;
+    return b;
+}
+
+static void golden(void) {
+    char path[512], line[512];
+    snprintf(path, sizeof path, "%s/expected.txt", GOLDEN);
+    FILE *f = fopen(path, "r");
+    if (!f) setup_fail("golden/expected.txt (run from the repository root)");
+    int n_acc = 0, n_ref = 0, ids_ok = 1;
+    while (fgets(line, sizeof line, f)) {
+        char name[256], verb[16], arg[128], cname[300];
+        if (sscanf(line, "%255s %15s %127s", name, verb, arg) != 3) continue;
+        snprintf(path, sizeof path, "%s/%s.hex", GOLDEN, name);
+        size_t n; uint8_t *b = read_hex(path, &n);
+        if (!b) setup_fail("golden vector file");
+        OmegaVcStore *s = new_store();
+        uint8_t claimed[32];
+        omega_vc_compute_id(b, n, claimed);
+        if (strcmp(verb, "ACCEPT") == 0) {
+            n_acc++;
+            /* the expected id is the one aien-protocols computed with sha256sum */
+            for (int i = 0; i < 32; i++) { unsigned v; sscanf(arg + 2 * i, "%2x", &v); claimed[i] = (uint8_t)v; }
+            /* dependencies the vector names must exist first: synthesize them from the vector itself */
+            OmegaVcView *v = malloc(sizeof *v);
+            if (omega_vc_decode(b, n, v) == 0) {
+                for (uint32_t i = 0; i < v->n_dependencies; i++) {
+                    Spec sp;
+                    spec_default(&sp, v->dependencies + 64 * (size_t)i);
+                    memcpy(sp.con, v->dependencies + 64 * (size_t)i + 32, 32);
+                    if (ins(s, &sp) != 0) setup_fail("golden dependency");
+                }
+            }
+            free(v);
+            int rc = omega_vcstore_insert(s, b, n, claimed);
+            snprintf(cname, sizeof cname, "accept-%s", name);
+            check(cname, rc == 0);
+            OmegaVcRecord *rec = malloc(sizeof *rec);
+            uint8_t sid[32];
+            OmegaVcView *v2 = malloc(sizeof *v2);
+            if (omega_vc_decode(b, n, v2) == 0) memcpy(sid, v2->semantic_id, 32); else memset(sid, 0x99, 32);
+            free(v2);
+            if (omega_vcstore_get(s, sid, rec) != 0 || memcmp(rec->vc_id, claimed, 32) != 0) ids_ok = 0;
+            free(rec);
+        } else {
+            n_ref++;
+            int rc = omega_vcstore_insert(s, b, n, claimed);
+            snprintf(cname, sizeof cname, "refuse-%s", name);
+            check(cname, rc != 0 && strcmp(omega_vcstore_code_name(rc), arg) == 0 && omega_vcstore_count(s) == 0);
+        }
+        free(b);
+        free_store(s);
+    }
+    fclose(f);
+    if (n_acc != 4 || n_ref != 13) setup_fail("golden corpus is not 4 accept + 13 refuse vectors");
+    check("accept-ids-match-golden", ids_ok);
+}
+
+/* ---- synthetic refusals ---- */
+static int refuse_code(const Spec *sp) {
+    OmegaVcStore *s = new_store();
+    int rc = ins(s, sp);
+    if (omega_vcstore_count(s) != 0 && rc != 0) rc = -1;   /* a refusal must leave the store empty */
+    free_store(s);
+    return rc;
+}
+
+static void synthetic_refusals(void) {
+    uint8_t sem[32]; mkid(sem, 0x11);
+    Spec sp;
+    uint8_t reals[2][32]; mkid(reals[0], 0x90); mkid(reals[1], 0x80);   /* descending */
+    spec_default(&sp, sem); sp.n_real = 2; sp.real = (const uint8_t (*)[32])reals;
+    check("refuse-unsorted-realizations", refuse_code(&sp) == OMEGA_VCS_NONCANONICAL_SET);
+    const char *caps[2] = { "b-cap", "a-cap" };
+    spec_default(&sp, sem); sp.n_cap = 2; sp.cap = caps;
+    check("refuse-unsorted-capabilities", refuse_code(&sp) == OMEGA_VCS_NONCANONICAL_SET);
+    uint8_t dz[1][64]; mkid(dz[0], 0x22); memset(dz[0] + 32, 0, 32);
+    spec_default(&sp, sem); sp.n_dep = 1; sp.dep = (const uint8_t (*)[64])dz;
+    check("refuse-zero-dependency-id", refuse_code(&sp) == OMEGA_VCS_ZERO_ID);
+    spec_default(&sp, sem); memset(sp.root, 0, 32);
+    check("refuse-zero-evidence-root", refuse_code(&sp) == OMEGA_VCS_ZERO_ID);
+    spec_default(&sp, sem); sp.prof = "";
+    check("refuse-bad-string-empty", refuse_code(&sp) == OMEGA_VCS_BAD_STRING);
+    char longs[258]; memset(longs, 'a', 257); longs[257] = 0;
+    spec_default(&sp, sem); sp.pver = longs;
+    check("refuse-bad-string-too-long", refuse_code(&sp) == OMEGA_VCS_BAD_STRING);
+}
+
+/* ---- store behaviour ---- */
+static const uint8_t ZERO[32];
+
+static void insert_checks(void) {
+    uint8_t sem[32]; mkid(sem, 0x11);
+    Spec sp; spec_default(&sp, sem);
+    B b = { 0, 0, 0 };
+    encode(&b, &sp);
+    uint8_t id[32]; omega_vc_compute_id(b.p, b.n, id);
+
+    OmegaVcStore *s = new_store();
+    check("null-claimed-id-refused",
+          omega_vcstore_insert(s, b.p, b.n, NULL) == OMEGA_VCS_VCSTORE_MALFORMED && omega_vcstore_count(s) == 0);
+    uint8_t wrong[32]; memcpy(wrong, id, 32); wrong[7] ^= 1;
+    check("claimed-id-mismatch-refused",
+          omega_vcstore_insert(s, b.p, b.n, wrong) == OMEGA_VCS_VCSTORE_ID_MISMATCH && omega_vcstore_count(s) == 0);
+
+    /* identical bytes twice: success, one object, same digest */
+    int r1 = omega_vcstore_insert(s, b.p, b.n, id);
+    uint8_t d1[32], d2[32]; dig(s, d1);
+    int r2 = omega_vcstore_insert(s, b.p, b.n, id);
+    dig(s, d2);
+    check("identical-insert-is-noop", r1 == 0 && r2 == 0 && omega_vcstore_count(s) == 1 && memcmp(d1, d2, 32) == 0);
+
+    /* same program id, different record (other receipt and exports): refused, original untouched */
+    Spec sp2; spec_default(&sp2, sem); sp2.rcpt[5] ^= 0xFF;
+    const char *ex[1] = { "other" }; sp2.n_exp = 1; sp2.exp = ex;
+    int rc = ins(s, &sp2);
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    int g = omega_vcstore_get(s, sem, rec);
+    dig(s, d2);
+    check("immutable-conflict-refused",
+          rc == OMEGA_VCS_VCSTORE_IMMUTABLE_CONFLICT && g == 0 && memcmp(rec->vc_id, id, 32) == 0 &&
+          memcmp(d1, d2, 32) == 0 && omega_vcstore_count(s) == 1);
+    free(rec);
+    /* same bytes, other admission kind: also a conflict, never a silent relabel */
+    uint8_t kind = 0;
+    rc = omega_vcstore_insert_bootstrap(s, b.p, b.n, id);
+    int g2 = omega_vcstore_admission_kind(s, sem, &kind);
+    check("kind-switch-refused", rc == OMEGA_VCS_VCSTORE_IMMUTABLE_CONFLICT && g2 == 0 && kind == OMEGA_VCS_ADMISSION_VERIFIED);
+    free_store(s);
+
+    /* receipt_of: the record's receipt_id, nothing else; absent id is refused */
+    s = new_store();
+    if (ins(s, &sp) != 0) setup_fail("receipt_of insert");
+    uint8_t out[32]; memset(out, 0xEE, 32);
+    int ro = omega_vcstore_receipt_of(s, sem, out);
+    uint8_t missing[32]; mkid(missing, 0xF1);
+    uint8_t out2[32]; memset(out2, 0xEE, 32);
+    int ro2 = omega_vcstore_receipt_of(s, missing, out2);
+    check("receipt-of-returns-receipt-id", ro == 0 && memcmp(out, sp.rcpt, 32) == 0 &&
+          ro2 == OMEGA_VCS_UNVERIFIED_DEPENDENCY && out2[0] == 0xEE);
+    free_store(s);
+    free(b.p);
+
+    /* missing dependency: the golden v02 on its own */
+    {
+        char path[512]; size_t n;
+        snprintf(path, sizeof path, "%s/v02_deps.hex", GOLDEN);
+        uint8_t *v2 = read_hex(path, &n);
+        if (!v2) setup_fail("v02");
+        uint8_t cid[32]; omega_vc_compute_id(v2, n, cid);
+        s = new_store();
+        rc = omega_vcstore_insert(s, v2, n, cid);
+        check("missing-dep-refused", rc == OMEGA_VCS_UNVERIFIED_DEPENDENCY && omega_vcstore_count(s) == 0);
+        free_store(s); free(v2);
+    }
+
+    /* dependency present but under another contract */
+    s = new_store();
+    uint8_t dd[32]; mkid(dd, 0x10);
+    if (node(s, dd, NULL, 0) != 0) setup_fail("dep node");
+    Spec sp3; spec_default(&sp3, sem);
+    uint8_t depw[1][64]; memcpy(depw[0], dd, 32); mkid(depw[0] + 32, 0x01);   /* wrong contract */
+    sp3.n_dep = 1; sp3.dep = (const uint8_t (*)[64])depw;
+    check("dep-contract-mismatch-refused", ins(s, &sp3) == OMEGA_VCS_UNVERIFIED_DEPENDENCY && omega_vcstore_count(s) == 1);
+    free_store(s);
+}
+
+static void growth_checks(void) {
+    /* more objects than the old library cap (128) and one record with the maximum 256 dependencies */
+    OmegaVcStore *s = new_store();
+    int ok = 1;
+    for (int i = 999; i >= 0; i--) {
+        uint8_t id[32]; mkid2(id, (uint8_t)(1 + i / 250), (uint8_t)(i % 250 + 1));
+        if (node(s, id, NULL, 0) != 0) { ok = 0; break; }
+    }
+    size_t cnt = omega_vcstore_count(s);
+    int sorted = 1;
+    for (size_t i = 1; i < s->count; i++) if (memcmp(s->objs[i - 1].semantic_id, s->objs[i].semantic_id, 32) >= 0) sorted = 0;
+    check("store-grows-past-old-caps", ok && cnt == 1000 && sorted);
+    free_store(s);
+
+    s = new_store();
+    uint8_t (*deps)[32] = calloc(256, 32);
+    if (!deps) setup_fail("oom");
+    for (int i = 0; i < 256; i++) {
+        mkid2(deps[i], 0x20, (uint8_t)i);
+        if (node(s, deps[i], NULL, 0) != 0) setup_fail("leaf");
+    }
+    uint8_t top[32]; mkid(top, 0x50);
+    int rc = node(s, top, (const uint8_t (*)[32])deps, 256);
+    uint8_t *out = malloc(32 * 300); size_t n = 0;
+    int rc2 = omega_vcstore_closure(s, top, out, 300, &n);
+    check("closure-keeps-all-256-dependencies", rc == 0 && rc2 == 0 && n == 257 && memcmp(out + 32 * 256, top, 32) == 0);
+    free(out); free(deps); free_store(s);
+}
+
+static void closure_checks(void) {
+    diamond_ids();
+    uint8_t want[4][32];
+    memcpy(want[0], D, 32); memcpy(want[1], Bn, 32); memcpy(want[2], C, 32); memcpy(want[3], R, 32);
+
+    OmegaVcStore *a = new_store(), *b = new_store();
+    if (build_diamond(a, 0) != 0 || build_diamond(b, 1) != 0) setup_fail("diamond");
+    uint8_t oa[4 * 32], ob[4 * 32]; size_t na = 99, nb = 99;
+    int ra = omega_vcstore_closure(a, R, oa, 4, &na), rb = omega_vcstore_closure(b, R, ob, 4, &nb);
+    check("closure-order-deterministic",
+          ra == 0 && rb == 0 && na == 4 && nb == 4 && memcmp(oa, want, sizeof want) == 0 && memcmp(ob, want, sizeof want) == 0);
+    check("closure-visits-each-id-once", ra == 0 && na == 4);   /* D appears once although B and C both need it */
+
+    uint8_t two[2 * 32]; size_t n2 = 0;
+    int rcap = omega_vcstore_closure(a, R, two, 2, &n2);
+    size_t n0 = 0;
+    int rcap0 = omega_vcstore_closure(a, R, NULL, 0, &n0);
+    uint8_t exact[4 * 32]; size_t n4 = 0;
+    int rex = omega_vcstore_closure(a, R, exact, 4, &n4);
+    check("closure-capacity-refused",
+          rcap == OMEGA_VCS_VCSTORE_CAPACITY && n2 == 4 && rcap0 == OMEGA_VCS_VCSTORE_CAPACITY && n0 == 4 && rex == 0 && n4 == 4);
+
+    /* the closure of a leaf is itself; an unknown id is refused */
+    uint8_t one[32]; size_t n1 = 0;
+    int rleaf = omega_vcstore_closure(a, D, one, 1, &n1);
+    uint8_t unknown[32]; mkid(unknown, 0xF7); size_t nu = 5;
+    int run = omega_vcstore_closure(a, unknown, one, 1, &nu);
+    check("closure-leaf-and-unknown", rleaf == 0 && n1 == 1 && memcmp(one, D, 32) == 0 && run == OMEGA_VCS_UNVERIFIED_DEPENDENCY && nu == 0);
+
+    /* names never take part in resolution */
+    uint8_t before[4 * 32], after[4 * 32]; size_t nbf = 0, naf = 0;
+    int r0 = omega_vcstore_closure(a, R, before, 4, &nbf);
+    int ok = omega_vcstore_name_bind(a, "alpha", D) == 0 && omega_vcstore_name_bind(a, "beta", R) == 0 &&
+             omega_vcstore_name_rebind(a, "alpha", C) == 0;
+    OmegaVcRecord *g1 = malloc(sizeof *g1), *g2 = malloc(sizeof *g2);
+    int gr1 = omega_vcstore_get(b, R, g1);
+    int r1 = omega_vcstore_closure(a, R, after, 4, &naf);
+    int gr2 = omega_vcstore_get(a, R, g2);
+    check("names-do-not-affect-resolution",
+          ok && r0 == 0 && r1 == 0 && nbf == naf && memcmp(before, after, sizeof before) == 0 &&
+          gr1 == 0 && gr2 == 0 && memcmp(g1->vc_id, g2->vc_id, 32) == 0);
+    free(g1); free(g2);
+
+    /* damage the graph in memory: drop D */
+    {
+        OmegaVcStore *m = new_store();
+        if (build_diamond(m, 0) != 0) setup_fail("diamond");
+        free(m->objs[0].bytes);
+        memmove(&m->objs[0], &m->objs[1], (m->count - 1) * sizeof m->objs[0]);
+        m->count--;
+        uint8_t o[4 * 32]; size_t n = 7;
+        int rc = omega_vcstore_closure(m, R, o, 4, &n);
+        check("closure-missing-dep-refused", rc == OMEGA_VCS_UNVERIFIED_DEPENDENCY && n == 0);
+        free_store(m);
+    }
+    /* damage the graph in memory: B is replaced by a record with another contract id */
+    {
+        OmegaVcStore *m = new_store();
+        if (build_diamond(m, 0) != 0) setup_fail("diamond");
+        Spec sp; spec_default(&sp, Bn);
+        mkid(sp.con, 0x0B);   /* not the contract R requires */
+        uint8_t dd[1][64]; memcpy(dd[0], D, 32); con_of(D, dd[0] + 32);
+        sp.n_dep = 1; sp.dep = (const uint8_t (*)[64])dd;
+        B enc = { 0, 0, 0 }; encode(&enc, &sp);
+        size_t bi = 1;   /* sorted: D, B, C, R */
+        free(m->objs[bi].bytes);
+        m->objs[bi].bytes = enc.p; m->objs[bi].len = enc.n;
+        omega_vc_compute_id(enc.p, enc.n, m->objs[bi].vc_id);
+        uint8_t o[4 * 32]; size_t n = 7;
+        int rc = omega_vcstore_closure(m, R, o, 4, &n);
+        check("closure-contract-mismatch-refused", rc == OMEGA_VCS_UNVERIFIED_DEPENDENCY && n == 0);
+        free_store(m);
+    }
+    /* damage the graph in memory: Y is replaced by a record that needs X, which needs Y */
+    {
+        OmegaVcStore *m = new_store();
+        uint8_t X[32], Y[32], dy[1][32];
+        mkid(X, 0x50); mkid(Y, 0x60); memcpy(dy[0], Y, 32);
+        if (node(m, Y, NULL, 0) != 0 || node(m, X, (const uint8_t (*)[32])dy, 1) != 0) setup_fail("xy");
+        Spec sp; spec_default(&sp, Y);
+        uint8_t dd[1][64]; memcpy(dd[0], X, 32); con_of(X, dd[0] + 32);
+        sp.n_dep = 1; sp.dep = (const uint8_t (*)[64])dd;
+        B enc = { 0, 0, 0 }; encode(&enc, &sp);
+        free(m->objs[1].bytes);                 /* sorted: X, Y */
+        m->objs[1].bytes = enc.p; m->objs[1].len = enc.n;
+        omega_vc_compute_id(enc.p, enc.n, m->objs[1].vc_id);
+        uint8_t o[2 * 32]; size_t n = 7;
+        int rc = omega_vcstore_closure(m, X, o, 2, &n);
+        check("closure-cycle-refused", rc == OMEGA_VCS_DEPENDENCY_CYCLE && n == 0);
+        free_store(m);
+    }
+    free_store(a); free_store(b);
+}
+
+static void integrity_checks(void) {
+    uint8_t sem[32]; mkid(sem, 0x11);
+    Spec sp; spec_default(&sp, sem);
+    OmegaVcStore *s = new_store();
+    if (ins(s, &sp) != 0) setup_fail("insert");
+    /* flip one bit of the source digest: still a well-formed record, but not the bytes that were hashed */
+    s->objs[0].bytes[91] ^= 1;
+    OmegaVcRecord *rec = malloc(sizeof *rec);
+    check("get-detects-corrupt-bytes", omega_vcstore_get(s, sem, rec) == OMEGA_VCS_VCSTORE_ID_MISMATCH);
+    free(rec);
+    free_store(s);
+
+    s = new_store();
+    if (ins(s, &sp) != 0) setup_fail("insert");
+    s->objs[0].semantic_id[0] ^= 1;   /* the key no longer matches the record inside */
+    rec = malloc(sizeof *rec);
+    check("get-detects-key-mismatch", omega_vcstore_get(s, s->objs[0].semantic_id, rec) == OMEGA_VCS_VCSTORE_ID_MISMATCH);
+    free(rec);
+    free_store(s);
+}
+
+/* ---- digest: second implementation ---- */
+static void ref_u64(sha256_ctx *c, uint64_t v) { uint8_t b[8]; for (int i = 0; i < 8; i++) b[i] = (uint8_t)(v >> (56 - 8 * i)); sha256_update(c, b, 8); }
+typedef struct { const uint8_t *bytes; size_t len; uint8_t kind; } FObj;
+typedef struct { const char *name; const uint8_t *id; } FName;
+static int fobj_cmp(const void *x, const void *y) { return memcmp(((const FObj *)x)->bytes + 26, ((const FObj *)y)->bytes + 26, 32); }
+static void ref_digests(const FObj *objs, size_t n, const FName *names, size_t nn, uint8_t d1[32], uint8_t d2[32]) {
+    FObj *sorted = malloc((n ? n : 1) * sizeof *sorted);
+    memcpy(sorted, objs, n * sizeof *sorted);
+    qsort(sorted, n, sizeof *sorted, fobj_cmp);
+    sha256_ctx c; sha256_init(&c);
+    sha256_update(&c, (const uint8_t *)"VCS1", 4); ref_u64(&c, n);
+    for (size_t i = 0; i < n; i++) {
+        sha256_update(&c, sorted[i].bytes + 26, 32);          /* semantic_id sits at offset 22 + 4 */
+        sha256_update(&c, &sorted[i].kind, 1);
+        ref_u64(&c, sorted[i].len);
+        sha256_update(&c, sorted[i].bytes, sorted[i].len);
+    }
+    sha256_final(&c, d1);
+    free(sorted);
+    sha256_init(&c);
+    sha256_update(&c, (const uint8_t *)"VCN1", 4); ref_u64(&c, nn);
+    for (size_t i = 0; i < nn; i++) {
+        size_t l = strlen(names[i].name);
+        ref_u64(&c, l); sha256_update(&c, (const uint8_t *)names[i].name, l); sha256_update(&c, names[i].id, 32);
+    }
+    sha256_final(&c, d2);
+}
+/* write a store file by hand (ascending names expected); trailer digests are the reference ones */
+static void write_file(const char *path, const FObj *objs, size_t n, const FName *names, size_t nn) {
+    B b = { 0, 0, 0 };
+    bput(&b, "AIEN_VCSTORE_V1", 15);
+    bu64(&b, n);
+    for (size_t i = 0; i < n; i++) { bput(&b, &objs[i].kind, 1); bu64(&b, objs[i].len); bput(&b, objs[i].bytes, objs[i].len); }
+    bu64(&b, nn);
+    for (size_t i = 0; i < nn; i++) { bu64(&b, strlen(names[i].name)); bput(&b, names[i].name, strlen(names[i].name)); bput(&b, names[i].id, 32); }
+    uint8_t d1[32], d2[32];
+    ref_digests(objs, n, names, nn, d1, d2);
+    bput(&b, d1, 32); bput(&b, d2, 32);
+    FILE *f = fopen(path, "wb");
+    if (!f || fwrite(b.p, 1, b.n, f) != b.n) setup_fail("write file");
+    fclose(f);
+    free(b.p);
+}
+static uint8_t *slurp(const char *path, size_t *n) {
+    FILE *f = fopen(path, "rb");
+    if (!f) setup_fail("slurp");
+    fseek(f, 0, SEEK_END); long l = ftell(f); fseek(f, 0, SEEK_SET);
+    uint8_t *p = malloc((size_t)l + 1);
+    if (fread(p, 1, (size_t)l, f) != (size_t)l) setup_fail("read");
+    fclose(f); *n = (size_t)l;
+    return p;
+}
+static void spit(const char *path, const uint8_t *p, size_t n) {
+    FILE *f = fopen(path, "wb");
+    if (!f || (n && fwrite(p, 1, n, f) != n)) setup_fail("spit");
+    fclose(f);
+}
+
+static void order_checks(void) {
+    diamond_ids();
+    /* same set, different insert orders: same digest */
+    OmegaVcStore *a = new_store(), *b = new_store(), *c = new_store();
+    uint8_t leaf[6][32];
+    for (int i = 0; i < 6; i++) mkid2(leaf[i], (uint8_t)(0x80 + i * 7), (uint8_t)(i + 1));
+    int ok = build_diamond(a, 0) == 0;
+    for (int i = 0; i < 6; i++) ok &= node(a, leaf[i], NULL, 0) == 0;
+    for (int i = 5; i >= 0; i--) ok &= node(b, leaf[i], NULL, 0) == 0;
+    ok &= build_diamond(b, 1) == 0;
+    ok &= node(c, leaf[3], NULL, 0) == 0;
+    ok &= build_diamond(c, 0) == 0;
+    for (int i = 0; i < 6; i++) if (i != 3) ok &= node(c, leaf[i], NULL, 0) == 0;
+    check("digest-independent-of-insert-order", ok && same_digest(a, b) && same_digest(a, c) && omega_vcstore_count(a) == 10);
+    free_store(a); free_store(b); free_store(c);
+}
+
+static void digest_checks(void) {
+    diamond_ids();
+    /* reference digest equals the library digest (verified and bootstrap mixed) */
+    OmegaVcStore *s = new_store();
+    uint8_t dD[1][32], dR[2][32]; memcpy(dD[0], D, 32); memcpy(dR[0], Bn, 32); memcpy(dR[1], C, 32);
+    int rc = node_kind(s, D, NULL, 0, 1);
+    rc |= node(s, Bn, dD, 1); rc |= node(s, C, dD, 1); rc |= node(s, R, dR, 2);
+    if (rc) setup_fail("digest store");
+    FObj objs[4]; Spec sp; B enc[4] = { {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} };
+    const uint8_t *ids[4] = { D, Bn, C, R };
+    for (int i = 0; i < 4; i++) {
+        spec_default(&sp, ids[i]);
+        uint8_t (*d)[64] = calloc(2, 64);
+        if (i == 1 || i == 2) { memcpy(d[0], D, 32); con_of(D, d[0] + 32); sp.n_dep = 1; }
+        if (i == 3) { memcpy(d[0], Bn, 32); con_of(Bn, d[0] + 32); memcpy(d[1], C, 32); con_of(C, d[1] + 32); sp.n_dep = 2; }
+        sp.dep = (const uint8_t (*)[64])d;
+        encode(&enc[i], &sp);
+        free(d);
+        objs[i].bytes = enc[i].p; objs[i].len = enc[i].n; objs[i].kind = i == 0 ? 2 : 1;
+    }
+    uint8_t r1[32], r2[32], l1[32];
+    ref_digests(objs, 4, NULL, 0, r1, r2);
+    dig(s, l1);
+    check("digest-matches-reference", memcmp(r1, l1, 32) == 0);
+
+    /* the digest covers the bytes of every object */
+    OmegaVcStore *m = new_store();
+    if (build_diamond(m, 0) != 0) setup_fail("diamond");
+    uint8_t x1[32], x2[32];
+    dig(m, x1);
+    m->objs[2].bytes[91] ^= 1;
+    dig(m, x2);
+    check("digest-covers-bytes", memcmp(x1, x2, 32) != 0);
+    free_store(m);
+
+
+    /* the same record admitted as BOOTSTRAP and as VERIFIED never shares a digest */
+    OmegaVcStore *v = new_store(), *bo = new_store();
+    int rv = node_kind(v, D, NULL, 0, 0), rb = node_kind(bo, D, NULL, 0, 1);
+    uint8_t kv = 0, kb = 0;
+    omega_vcstore_admission_kind(v, D, &kv); omega_vcstore_admission_kind(bo, D, &kb);
+    check("bootstrap-kind-recorded", rv == 0 && rb == 0 && kv == OMEGA_VCS_ADMISSION_VERIFIED && kb == OMEGA_VCS_ADMISSION_BOOTSTRAP);
+    check("bootstrap-vs-verified-digest-differ", rv == 0 && rb == 0 && !same_digest(v, bo));
+    free_store(v); free_store(bo);
+
+    for (int i = 0; i < 4; i++) free(enc[i].p);
+    free_store(s);
+}
+
+static void name_checks(void) {
+    diamond_ids();
+    OmegaVcStore *s = new_store();
+    if (build_diamond(s, 0) != 0) setup_fail("diamond");
+    uint8_t od0[32], od1[32], od2[32];
+    dig(s, od0);
+
+    /* many names, one id */
+    int r1 = omega_vcstore_name_bind(s, "first", D), r2 = omega_vcstore_name_bind(s, "second", D), r3 = omega_vcstore_name_bind(s, "third.v-2", D);
+    uint8_t g1[32], g2[32], g3[32];
+    int q1 = omega_vcstore_resolve_name(s, "first", g1), q2 = omega_vcstore_resolve_name(s, "second", g2), q3 = omega_vcstore_resolve_name(s, "third.v-2", g3);
+    check("name-bind-many-to-one", r1 == 0 && r2 == 0 && r3 == 0 && q1 == 0 && q2 == 0 && q3 == 0 &&
+          memcmp(g1, D, 32) == 0 && memcmp(g2, D, 32) == 0 && memcmp(g3, D, 32) == 0 && s->n_names == 3 &&
+          omega_vcstore_name_bind(s, "first", D) == 0);   /* same name, same id: no-op */
+    dig(s, od1);
+    check("name-index-never-changes-object-digest", memcmp(od0, od1, 32) == 0);
+
+    /* a bound name cannot be taken over by a plain bind */
+    int rx = omega_vcstore_name_bind(s, "first", R);
+    uint8_t gx[32];
+    int qx = omega_vcstore_resolve_name(s, "first", gx);
+    check("name-no-silent-rebind", rx == OMEGA_VCS_VCSTORE_NAME_EXISTS && qx == 0 && memcmp(gx, D, 32) == 0);
+
+    /* explicit rebind works, changes the name digest, still not the object digest */
+    uint8_t n1[32], n2[32];
+    omega_vcstore_name_index_digest(s, n1);
+    int rr = omega_vcstore_name_rebind(s, "first", R);
+    int qr = omega_vcstore_resolve_name(s, "first", gx);
+    omega_vcstore_name_index_digest(s, n2);
+    dig(s, od2);
+    check("name-rebind-explicit", rr == 0 && qr == 0 && memcmp(gx, R, 32) == 0);
+    check("name-index-digest-covers-id", memcmp(n1, n2, 32) != 0 && memcmp(od0, od2, 32) == 0);
+
+    uint8_t nobody[32]; mkid(nobody, 0xF3);
+    size_t before = s->n_names;
+    check("name-rebind-unbound-refused", omega_vcstore_name_rebind(s, "never-bound", D) == OMEGA_VCS_VCSTORE_NOT_FOUND && s->n_names == before);
+    check("name-rebind-unknown-id-refused", omega_vcstore_name_rebind(s, "first", nobody) == OMEGA_VCS_UNVERIFIED_DEPENDENCY &&
+          omega_vcstore_resolve_name(s, "first", gx) == 0 && memcmp(gx, R, 32) == 0);
+    check("name-bind-unknown-id-refused", omega_vcstore_name_bind(s, "ghost", nobody) == OMEGA_VCS_UNVERIFIED_DEPENDENCY &&
+          s->n_names == before && omega_vcstore_resolve_name(s, "ghost", gx) == OMEGA_VCS_VCSTORE_NOT_FOUND);
+
+    char long129[130]; memset(long129, 'a', 129); long129[129] = 0;
+    char long128[129]; memset(long128, 'a', 128); long128[128] = 0;
+    int bad = 1;
+    const char *bads[] = { "", "1abc", "a b", "-x", ".x", "a/b", "caf\xc3\xa9", long129 };
+    for (size_t i = 0; i < sizeof bads / sizeof *bads; i++) bad &= omega_vcstore_name_bind(s, bads[i], D) == OMEGA_VCS_VCSTORE_MALFORMED;
+    check("name-invalid-refused", bad && omega_vcstore_name_bind(s, long128, D) == 0 && omega_vcstore_name_bind(s, "_ok.Name-9", D) == 0);
+
+    uint8_t rg[32]; memset(rg, 0xEE, 32);
+    int none = omega_vcstore_resolve_name(s, "does-not-exist", rg);
+    uint8_t rg2[32];
+    int found = omega_vcstore_resolve_name(s, "second", rg2);
+    check("resolve-name-returns-id", none == OMEGA_VCS_VCSTORE_NOT_FOUND && rg[0] == 0xEE && found == 0 && memcmp(rg2, D, 32) == 0);
+    free_store(s);
+
+    /* the name digest does not depend on the order names were bound */
+    OmegaVcStore *a = new_store(), *b = new_store();
+    if (build_diamond(a, 0) != 0 || build_diamond(b, 0) != 0) setup_fail("diamond");
+    omega_vcstore_name_bind(a, "zeta", D); omega_vcstore_name_bind(a, "alpha", R); omega_vcstore_name_bind(a, "mid", C);
+    omega_vcstore_name_bind(b, "mid", C); omega_vcstore_name_bind(b, "alpha", R); omega_vcstore_name_bind(b, "zeta", D);
+    uint8_t da[32], db[32];
+    omega_vcstore_name_index_digest(a, da); omega_vcstore_name_index_digest(b, db);
+    check("name-index-digest-order-independent", memcmp(da, db, 32) == 0);
+    free_store(a); free_store(b);
+}
+
+/* ---- persistence ---- */
+static char g_path[256];
+
+static void persistence_checks(void) {
+    diamond_ids();
+    snprintf(g_path, sizeof g_path, "/tmp/omega_vcstore_test_%d.bin", (int)getpid());
+    char g_path2[300]; snprintf(g_path2, sizeof g_path2, "%s.t", g_path);
+    OmegaVcStore *s = new_store();
+    uint8_t dD[1][32]; memcpy(dD[0], D, 32);
+    uint8_t dR[2][32]; memcpy(dR[0], Bn, 32); memcpy(dR[1], C, 32);
+    int rc = node_kind(s, D, NULL, 0, 1);
+    rc |= node(s, Bn, dD, 1); rc |= node(s, C, dD, 1); rc |= node(s, R, dR, 2);
+    rc |= omega_vcstore_name_bind(s, "root", R); rc |= omega_vcstore_name_bind(s, "leaf", D);
+    if (rc) setup_fail("persist store");
+
+    /* round trip into a store that already holds something else */
+    int sv = omega_vcstore_save(s, g_path);
+    OmegaVcStore *t = new_store();
+    uint8_t other[32]; mkid(other, 0xC4);
+    node(t, other, NULL, 0);
+    int ld = omega_vcstore_load(t, g_path);
+    uint8_t o1[32], o2[32], n1[32], n2[32];
+    dig(s, o1); dig(t, o2); omega_vcstore_name_index_digest(s, n1); omega_vcstore_name_index_digest(t, n2);
+    uint8_t rc1[32], rc2[32], res[32]; uint8_t kind = 0;
+    int a1 = omega_vcstore_receipt_of(s, R, rc1), a2 = omega_vcstore_receipt_of(t, R, rc2);
+    int a3 = omega_vcstore_resolve_name(t, "root", res);
+    int a4 = omega_vcstore_admission_kind(t, D, &kind);
+    uint8_t cl[4 * 32]; size_t ncl = 0;
+    int a5 = omega_vcstore_closure(t, R, cl, 4, &ncl);
+    check("save-load-round-trip", sv == 0 && ld == 0 && omega_vcstore_count(t) == 4 && memcmp(o1, o2, 32) == 0 && memcmp(n1, n2, 32) == 0 &&
+          a1 == 0 && a2 == 0 && memcmp(rc1, rc2, 32) == 0 && a3 == 0 && memcmp(res, R, 32) == 0 &&
+          a4 == 0 && kind == OMEGA_VCS_ADMISSION_BOOTSTRAP && a5 == 0 && ncl == 4 && memcmp(cl, D, 32) == 0);
+    free_store(t);
+
+    size_t fn; uint8_t *file = slurp(g_path, &fn);
+
+    /* a failed load leaves the target as it was */
+    uint8_t bad1[1] = { 0 };
+    spit(g_path2, bad1, 1);
+    t = new_store();
+    node(t, other, NULL, 0);
+    uint8_t t1[32], t2[32]; dig(t, t1);
+    int lf = omega_vcstore_load(t, g_path2);
+    dig(t, t2);
+    check("load-failure-leaves-store-unchanged", lf != 0 && memcmp(t1, t2, 32) == 0 && omega_vcstore_count(t) == 1);
+    free_store(t);
+
+    /* every single-bit change and every proper prefix is refused, and refusal leaves nothing behind */
+    int all = 1;
+    for (size_t i = 0; i < fn && all; i++) {
+        file[i] ^= 1;
+        spit(g_path2, file, fn);
+        file[i] ^= 1;
+        t = new_store();
+        if (omega_vcstore_load(t, g_path2) == 0 || omega_vcstore_count(t) != 0) all = 0;
+        free_store(t);
+    }
+    for (size_t k = 0; k < fn && all; k++) {
+        spit(g_path2, file, k);
+        t = new_store();
+        if (omega_vcstore_load(t, g_path2) == 0 || omega_vcstore_count(t) != 0) all = 0;
+        free_store(t);
+    }
+    check("tamper-every-byte-and-prefix-refused", all);
+
+    /* digest trailers: flip one byte of each; the object trailer also when the record stays well-formed */
+    file[fn - 64] ^= 1; spit(g_path2, file, fn); file[fn - 64] ^= 1;
+    t = new_store();
+    int e1 = omega_vcstore_load(t, g_path2);
+    free_store(t);
+    check("tamper-object-digest-refused", e1 == OMEGA_VCS_VCSTORE_ID_MISMATCH);
+    file[fn - 1] ^= 1; spit(g_path2, file, fn); file[fn - 1] ^= 1;
+    t = new_store();
+    int e2 = omega_vcstore_load(t, g_path2);
+    free_store(t);
+    check("tamper-name-digest-refused", e2 == OMEGA_VCS_VCSTORE_ID_MISMATCH);
+
+    uint8_t *plus = malloc(fn + 1);
+    memcpy(plus, file, fn); plus[fn] = 0;
+    spit(g_path2, plus, fn + 1);
+    t = new_store();
+    int e3 = omega_vcstore_load(t, g_path2);
+    free_store(t);
+    check("trailing-byte-refused", e3 == OMEGA_VCS_VCSTORE_MALFORMED);
+    free(plus);
+    free(file);
+
+    /* a corrupt store is never written out */
+    OmegaVcStore *c = new_store();
+    uint8_t sem[32]; mkid(sem, 0x11);
+    Spec sp; spec_default(&sp, sem);
+    ins(c, &sp);
+    c->objs[0].bytes[91] ^= 1;
+    remove(g_path2);
+    int sc = omega_vcstore_save(c, g_path2);
+    check("save-refuses-corrupt-store", sc == OMEGA_VCS_VCSTORE_ID_MISMATCH && access(g_path2, F_OK) != 0);
+    free_store(c);
+
+    /* hand-built files: each checks one load refusal with correct reference digests */
+    Spec spX, spY, spYc, spA, spB;
+    uint8_t X[32], Y[32]; mkid(X, 0x50); mkid(Y, 0x60);
+    uint8_t dxy[1][64]; memcpy(dxy[0], Y, 32); con_of(Y, dxy[0] + 32);
+    uint8_t dyx[1][64]; memcpy(dyx[0], X, 32); con_of(X, dyx[0] + 32);
+    spec_default(&spX, X); spX.n_dep = 1; spX.dep = (const uint8_t (*)[64])dxy;
+    spec_default(&spYc, Y); spYc.n_dep = 1; spYc.dep = (const uint8_t (*)[64])dyx;
+    spec_default(&spY, Y);
+    spec_default(&spA, other);
+    uint8_t other2[32]; mkid(other2, 0xC9); spec_default(&spB, other2);
+    B bx = { 0, 0, 0 }, by = { 0, 0, 0 }, byc = { 0, 0, 0 }, ba = { 0, 0, 0 }, bb = { 0, 0, 0 };
+    encode(&bx, &spX); encode(&by, &spY); encode(&byc, &spYc); encode(&ba, &spA); encode(&bb, &spB);
+
+    { FObj o[2] = { { bx.p, bx.n, 1 }, { byc.p, byc.n, 1 } };   /* X -> Y -> X */
+      write_file(g_path2, o, 2, NULL, 0);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-cycle-refused", r == OMEGA_VCS_DEPENDENCY_CYCLE && omega_vcstore_count(t) == 0); free_store(t); }
+    { FObj o[1] = { { bx.p, bx.n, 1 } };                        /* X needs Y, Y absent */
+      write_file(g_path2, o, 1, NULL, 0);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-missing-dep-refused", r == OMEGA_VCS_UNVERIFIED_DEPENDENCY && omega_vcstore_count(t) == 0); free_store(t); }
+    { FObj o[2] = { { ba.p, ba.n, 3 }, { bb.p, bb.n, 1 } };     /* admission kind 3 does not exist */
+      write_file(g_path2, o, 2, NULL, 0);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-bad-kind-refused", r == OMEGA_VCS_VCSTORE_MALFORMED); free_store(t); }
+    { FObj o[2] = { { bb.p, bb.n, 1 }, { ba.p, ba.n, 1 } };     /* 0xC9 before 0xC4: not ascending */
+      write_file(g_path2, o, 2, NULL, 0);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-unsorted-objects-refused", r == OMEGA_VCS_VCSTORE_MALFORMED); free_store(t); }
+    { FObj o[1] = { { ba.p, ba.n, 1 } };                        /* name bound to an id that is not stored */
+      uint8_t ghost[32]; mkid(ghost, 0xF9);
+      FName nm[1] = { { "ghost", ghost } };
+      write_file(g_path2, o, 1, nm, 1);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-name-unknown-id-refused", r == OMEGA_VCS_UNVERIFIED_DEPENDENCY); free_store(t); }
+    /* and a valid hand-built file does load (the reference writer and the loader agree) */
+    { FObj o[2] = { { ba.p, ba.n, 1 }, { bb.p, bb.n, 2 } };
+      write_file(g_path2, o, 2, NULL, 0);
+      t = new_store(); int r = omega_vcstore_load(t, g_path2);
+      check("load-reference-written-file", r == 0 && omega_vcstore_count(t) == 2); free_store(t); }
+    free(bx.p); free(by.p); free(byc.p); free(ba.p); free(bb.p);
+
+    remove(g_path); remove(g_path2);
+    free_store(s);
+}
+
+int main(int argc, char **argv) {
+    if (argc > 1) {
+        g_mutant = argv[1];
+        for (size_t i = 0; i < N_MUT; i++)
+            if (strcmp(MUTANTS[i].mutant, g_mutant) == 0) g_expect_check = MUTANTS[i].check;
+        if (!g_expect_check) { fprintf(stderr, "unknown mutant '%s'\n", g_mutant); return 2; }
+    }
+    (void)ZERO;
+    order_checks();
+    golden();
+    synthetic_refusals();
+    insert_checks();
+    growth_checks();
+    closure_checks();
+    integrity_checks();
+    digest_checks();
+    name_checks();
+    persistence_checks();
+
+    if (!g_mutant) {
+        printf("%s: %d check(s) failed\n", g_failed ? "FAIL" : "PASS", g_failed);
+        return g_failed ? 1 : 0;
+    }
+    if (g_expect_failed) { printf("MUTANT %s KILLED by %s\n", g_mutant, g_expect_check); return 1; }
+    printf("MUTANT %s SURVIVED (check %s did not fail)\n", g_mutant, g_expect_check);
+    return 3;
+}
diff --git a/tests/vcstore/golden/PIN b/tests/vcstore/golden/PIN
new file mode 100644
index 000000000..de288c6b9
--- /dev/null
+++ b/tests/vcstore/golden/PIN
@@ -0,0 +1,2 @@
+aien-protocols commit 0e9b9ddc8f19d0e8560153162aa6d9279b0f56c1
+source specs/verified-crumb/golden/ (copied byte for byte: *.hex and expected.txt)
diff --git a/tests/vcstore/golden/expected.txt b/tests/vcstore/golden/expected.txt
new file mode 100644
index 000000000..9b84fda13
--- /dev/null
+++ b/tests/vcstore/golden/expected.txt
@@ -0,0 +1,17 @@
+v01_minimal ACCEPT 27890b090acc8b8e91ecf49bb4249fc99867824d0854f931e5f8fb9ce1497325
+v02_deps ACCEPT fa5a0e8f496b9f8d81b6f942bd56604b5b9a98252999ede6cb62dff6e7374f7f
+v03_capabilities ACCEPT 94b84bf74e22f684d9400b9b31ccfa579f8eec434cb75589231402e2954f3e6d
+r01_duplicate_dep REFUSE DUPLICATE_DEPENDENCY
+r02_unsorted_deps REFUSE UNSORTED_DEPENDENCIES
+r03_zero_receipt_id REFUSE MISSING_RECEIPT
+r04_self_dependency REFUSE DEPENDENCY_CYCLE
+r05_trailing_byte REFUSE TRAILING_BYTES
+r06_unknown_version REFUSE UNKNOWN_FORMAT_VERSION
+r07_truncated REFUSE TRUNCATED
+r08_bad_domain_tag REFUSE BAD_DOMAIN_TAG
+r09_unsorted_exports REFUSE NONCANONICAL_SET
+v04_ir_kind ACCEPT 8d7dd4699e1781b20d4a01421be6779c68da483ff3d9b1899cb1fa0163dfb5c6
+r10_bad_digest_kind REFUSE BAD_DIGEST_KIND
+r11_zero_id REFUSE ZERO_ID
+r12_bad_string REFUSE BAD_STRING
+r13_too_many_entries REFUSE TOO_MANY_ENTRIES
diff --git a/tests/vcstore/golden/r01_duplicate_dep.hex b/tests/vcstore/golden/r01_duplicate_dep.hex
new file mode 100644
index 000000000..df4662b6f
--- /dev/null
+++ b/tests/vcstore/golden/r01_duplicate_dep.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f5631000000011111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222201333333333333333333333333333333333333333333333333333333333333333300000001444444444444444444444444444444444444444444444444444444444444444400000002a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b25555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r02_unsorted_deps.hex b/tests/vcstore/golden/r02_unsorted_deps.hex
new file mode 100644
index 000000000..0f73d7f36
--- /dev/null
+++ b/tests/vcstore/golden/r02_unsorted_deps.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f5631000000011111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222201333333333333333333333333333333333333333333333333333333333333333300000001444444444444444444444444444444444444444444444444444444444444444400000002a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b15555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r03_zero_receipt_id.hex b/tests/vcstore/golden/r03_zero_receipt_id.hex
new file mode 100644
index 000000000..da35a4a50
--- /dev/null
+++ b/tests/vcstore/golden/r03_zero_receipt_id.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r04_self_dependency.hex b/tests/vcstore/golden/r04_self_dependency.hex
new file mode 100644
index 000000000..3478e2853
--- /dev/null
+++ b/tests/vcstore/golden/r04_self_dependency.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000011111111111111111111111111111111111111111111111111111111111111111b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b15555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r05_trailing_byte.hex b/tests/vcstore/golden/r05_trailing_byte.hex
new file mode 100644
index 000000000..e40e3c5ee
--- /dev/null
+++ b/tests/vcstore/golden/r05_trailing_byte.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e306666666666666666666666666666666666666666666666666666666666666666000000000000000000
diff --git a/tests/vcstore/golden/r06_unknown_version.hex b/tests/vcstore/golden/r06_unknown_version.hex
new file mode 100644
index 000000000..ce2a8bc71
--- /dev/null
+++ b/tests/vcstore/golden/r06_unknown_version.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000211111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r07_truncated.hex b/tests/vcstore/golden/r07_truncated.hex
new file mode 100644
index 000000000..214f35f0a
--- /dev/null
+++ b/tests/vcstore/golden/r07_truncated.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e30666666666666666666666666666666666666666666666666666666666666666600000000000000
diff --git a/tests/vcstore/golden/r08_bad_domain_tag.hex b/tests/vcstore/golden/r08_bad_domain_tag.hex
new file mode 100644
index 000000000..bf205550b
--- /dev/null
+++ b/tests/vcstore/golden/r08_bad_domain_tag.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f560a0000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r09_unsorted_exports.hex b/tests/vcstore/golden/r09_unsorted_exports.hex
new file mode 100644
index 000000000..1006c3ac6
--- /dev/null
+++ b/tests/vcstore/golden/r09_unsorted_exports.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e306666666666666666666666666666666666666666666666666666666666666666000000020000000000000003737562000000000000000361646400000000
diff --git a/tests/vcstore/golden/r10_bad_digest_kind.hex b/tests/vcstore/golden/r10_bad_digest_kind.hex
new file mode 100644
index 000000000..beb381fef
--- /dev/null
+++ b/tests/vcstore/golden/r10_bad_digest_kind.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222033333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r11_zero_id.hex b/tests/vcstore/golden/r11_zero_id.hex
new file mode 100644
index 000000000..9cb4b6df2
--- /dev/null
+++ b/tests/vcstore/golden/r11_zero_id.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000100000000000000000000000000000000000000000000000000000000000000002222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r12_bad_string.hex b/tests/vcstore/golden/r12_bad_string.hex
new file mode 100644
index 000000000..79a67bd99
--- /dev/null
+++ b/tests/vcstore/golden/r12_bad_string.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000b6261642070726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/r13_too_many_entries.hex b/tests/vcstore/golden/r13_too_many_entries.hex
new file mode 100644
index 000000000..213cbed48
--- /dev/null
+++ b/tests/vcstore/golden/r13_too_many_entries.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f5631000000011111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222201333333333333333333333333333333333333333333333333333333333333333300000101
diff --git a/tests/vcstore/golden/v01_minimal.hex b/tests/vcstore/golden/v01_minimal.hex
new file mode 100644
index 000000000..aa6213cff
--- /dev/null
+++ b/tests/vcstore/golden/v01_minimal.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000
diff --git a/tests/vcstore/golden/v02_deps.hex b/tests/vcstore/golden/v02_deps.hex
new file mode 100644
index 000000000..37661eeae
--- /dev/null
+++ b/tests/vcstore/golden/v02_deps.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222013333333333333333333333333333333333333333333333333333333333333333000000024444444444444444444444444444444444444444444444444444444444444444454545454545454545454545454545454545454545454545454545454545454500000002a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b25555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000100000000000000046d61696e00000000
diff --git a/tests/vcstore/golden/v03_capabilities.hex b/tests/vcstore/golden/v03_capabilities.hex
new file mode 100644
index 000000000..c8be4f171
--- /dev/null
+++ b/tests/vcstore/golden/v03_capabilities.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f5631000000011212121212121212121212121212121212121212121212121212121212121212222222222222222222222222222222222222222222222222222222222222222201333333333333333333333333333333333333333333333333333333333333333300000001444444444444444444444444444444444444444444444444444444444444444400000001a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b15656565656565656565656565656565656565656565656565656565656565656000000000000000c746573742d70726f66696c650000000000000005312e302e306767676767676767676767676767676767676767676767676767676767676767000000020000000000000003616464000000000000000373756200000002000000000000000e6361702e636c6f636b2e72656164000000000000000b6361702e66732e72656164
diff --git a/tests/vcstore/golden/v04_ir_kind.hex b/tests/vcstore/golden/v04_ir_kind.hex
new file mode 100644
index 000000000..ed89021d5
--- /dev/null
+++ b/tests/vcstore/golden/v04_ir_kind.hex
@@ -0,0 +1 @@
+4149454e5f56455249464945445f4352554d425f56310000000111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222023333333333333333333333333333333333333333333333333333333333333333000000014444444444444444444444444444444444444444444444444444444444444444000000005555555555555555555555555555555555555555555555555555555555555555000000000000000c746573742d70726f66696c650000000000000005312e302e3066666666666666666666666666666666666666666666666666666666666666660000000000000000