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#216 (code only)

closed derived af88005fe2edfa24 #216

Imported from GitHub aien-dev/omega-mv#216 (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 2dc9dd8d964095c4dadeeb806cf6ec69a0061be3 · Head c08ee767329962c44a92563179051c54da2ccbb3

Apply it

git checkout -b patch-af88005fe2edfa24 2dc9dd8d964095c4dadeeb806cf6ec69a0061be3
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/af88005fe2edfa24.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
216
c08ee767329962c44a92563179051c54da2ccbb3
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":216,"url":"https://github.com/aien-dev/omega-mv/pull/216","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:49Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/src/runtime/rx_compose.c b/src/runtime/rx_compose.c
index c201fe39c..532bd2c2a 100644
--- a/src/runtime/rx_compose.c
+++ b/src/runtime/rx_compose.c
@@ -856,7 +856,7 @@ static int open_home(RxCompose *c, const char *dir, const AienMachineId *self, u
     path_in(p, sizeof p, dir, "cortex.cx");
     if (cx_open(&c->cx, p, RX_CORTEX_SUBJECTS, CX_OPEN_SYNC | CX_OPEN_REPAIR_TAIL) != CX_OK)
         return RX_ERR_REPLAY;
-    if (cx_verify_chain(&c->cx) != CX_OK) { cx_close(&c->cx); return RX_ERR_REPLAY; }
+    /* cx_open already verified every record and rebuilt the chain (see rx_cortex.h). */
 
     JsHome home;
     memset(&home, 0, sizeof home);
diff --git a/src/runtime/rx_cortex.c b/src/runtime/rx_cortex.c
index f5728a3b1..322b14131 100644
--- a/src/runtime/rx_cortex.c
+++ b/src/runtime/rx_cortex.c
@@ -290,6 +290,7 @@ static int replay(CxStore *s, const uint8_t *b, size_t len, size_t *good_end) {
     return rc;
 }
 
+/* The single integrity seam: see the guarantee in rx_cortex.h. */
 int cx_open(CxStore *s, const char *path, uint64_t n_subjects, uint32_t flags) {
     if (!s || !path) return CX_ERR_ARG;
     int ro = (flags & CX_OPEN_READONLY) != 0;
diff --git a/src/runtime/rx_cortex.h b/src/runtime/rx_cortex.h
index 689f2156e..4785129e2 100644
--- a/src/runtime/rx_cortex.h
+++ b/src/runtime/rx_cortex.h
@@ -202,7 +202,21 @@ enum {
 /* Open (creating if absent and writable) a journal-backed store. A writable
  * open takes an exclusive lock; a second writable open of the same file,
  * from this or any process, gets CX_ERR_WRITER. n_subjects must match a
- * nonempty journal's. On error the store is left freed. */
+ * nonempty journal's. On error the store is left freed.
+ *
+ * cx_open is the single seam where integrity is established. At open, for
+ * every record: the magic word, the id equal to its position (1, 2, 3, ...),
+ * and the per-record digest recomputed from header plus payload and compared
+ * to the stored one (rx_cortex.c replay). The chain is rebuilt from those
+ * digests, not read from disk. Also checked: the subject count against the
+ * file header, an incomplete trailing record (CX_ERR_TORN, or truncated when
+ * CX_OPEN_REPAIR_TAIL is set), and the writer lock.
+ * After a CX_OK open, callers may assume the objects in memory equal the
+ * journal, and that cx_verify on an object read from this store cannot fail
+ * except through memory corruption or a later in-memory edit.
+ * NOT checked: a journal cut exactly at a record boundary looks like a shorter
+ * valid journal. The file holds no record count or head marker, so such a
+ * truncation is not detectable at open. */
 int  cx_open(CxStore *s, const char *path, uint64_t n_subjects, uint32_t flags);
 void cx_close(CxStore *s);   /* = cx_free */
 
@@ -212,7 +226,10 @@ const uint64_t *cx_payload(const CxStore *s, const CxObject *o);
 /* Recompute an object's digest and compare: CX_OK or CX_ERR_DIGEST. */
 int  cx_verify(const CxStore *s, uint64_t id);
 
-/* Replay the running hash from the objects: CX_OK if it matches `chain`. */
+/* AUDIT entry point, not needed after cx_open (which already verified every
+ * record). Re-hashes every in-memory object, compares each to its stored
+ * digest, replays the running hash and compares it to `chain`: CX_OK if all
+ * match. For audits and tests. */
 int  cx_verify_chain(const CxStore *s);
 
 /* Canonical digest of a header plus payload. */
diff --git a/src/runtime/rx_projection.c b/src/runtime/rx_projection.c
index 127e8fde1..e74c3f06c 100644
--- a/src/runtime/rx_projection.c
+++ b/src/runtime/rx_projection.c
@@ -272,6 +272,9 @@ int pj_feature_compute(CxStore *s, uint64_t subject, uint32_t cls, uint32_t kind
     return PJ_OK;
 }
 
+/* Per-read cx_verify stays here: a store may be memory-only (never through cx_open),
+ * and a projection binds to exact object digests, so a source edited after the build
+ * must be caught (tests/runtime/rx_state_projection.c tamper case, lines 390-408). */
 /* The subject's newest realization whose linked evidence verifies. */
 static const CxObject *verified_anchor(Ctx *c) {
     const CognitiveNeed *n = c->need;
diff --git a/tests/runtime/rx_cortex_canon.c b/tests/runtime/rx_cortex_canon.c
index 462ed5ffa..c6aca8965 100644
--- a/tests/runtime/rx_cortex_canon.c
+++ b/tests/runtime/rx_cortex_canon.c
@@ -177,6 +177,35 @@ static void test_persistence(void) {
     CHECK(cx_open(&t, path, 16, CX_OPEN_REPAIR_TAIL) == CX_ERR_DIGEST, "tampered journal opened");
 }
 
+/* 4b. the chain is derived; opening is the integrity seam --------------------- */
+static void test_chain_derived(void) {
+    g_test = "chain derived at open";
+    printf("[*] %s\n", g_test);
+    char path[512];
+    path_of(path, sizeof path, "derived.cx");
+    CxStore s;
+    CHECK(cx_open(&s, path, 16, 0) == CX_OK, "create journal");
+    for (uint64_t t = 1; t <= 4; t++) {
+        CxHeader h = hdr(CX_CLAIM, CX_K_CLAIM, t % 3, t);
+        uint64_t pay[2] = { t, t + 50 };
+        CHECK(cx_append(&s, &h, pay, 2, NULL) == CX_OK, "append %llu", (unsigned long long)t);
+    }
+    uint8_t chain[32];
+    memcpy(chain, s.chain, 32);
+    CHECK(cx_verify_chain(&s) == CX_OK, "chain verifies before corruption");
+    memset(s.chain, 0xA5, 32);
+    CHECK(cx_verify_chain(&s) == CX_ERR_DIGEST, "corrupt chain not detected");
+    for (uint64_t id = 1; id <= s.n; id++)
+        CHECK(cx_verify(&s, id) == CX_OK, "record %llu digest broke with intact records",
+              (unsigned long long)id);
+    cx_close(&s);
+
+    CHECK(cx_open(&s, path, 16, 0) == CX_OK, "reopen from disk");
+    CHECK(s.n == 4 && memcmp(s.chain, chain, 32) == 0 && cx_verify_chain(&s) == CX_OK,
+          "reopened chain differs from the original");
+    cx_close(&s);
+}
+
 /* 5. execution -> Cortex through the real World ------------------------------ */
 
 enum { SUBJ_WORKER = 1, SUBJ_EXTERNAL = 100, ISSUER = 3, RES_IN = 0x10, RES_OUT = 0x20 };
@@ -353,6 +382,7 @@ int main(void) {
     test_provenance();
     test_recall();
     test_persistence();
+    test_chain_derived();
     test_execution();
     test_single_writer();
     char cmd[300];
diff --git a/tools/c4_requal_mutants.sh b/tools/c4_requal_mutants.sh
index 23cc8ebcd..0f616dc65 100755
--- a/tools/c4_requal_mutants.sh
+++ b/tools/c4_requal_mutants.sh
@@ -15,11 +15,11 @@ phys=${PHYSICS_DIR:-$(cd "$root/../physics" && pwd)}
 work=$(mktemp -d /tmp/c4mut.XXXXXX)
 trap 'rm -rf "$work"' EXIT
 
+# M03 retired: cx_open is the single integrity seam; rx_compose no longer re-walks the chain.
 # id~file~sed expression~what the original check does
 MUTANTS='
 M01~src/runtime/rx_compose.c~s/ || !aien_mid_equal(&stored, self))/ || 0)/~machine identity must match the stored one
 M02~src/runtime/rx_compose.c~s/n_units > 1) return RX_ERR_REPLAY;/n_units > 100000) return RX_ERR_REPLAY;/~refuse durable history when the Cortex journal has no state record
-M03~src/runtime/rx_compose.c~s/if (cx_verify_chain(&c->cx) != CX_OK) { cx_close(&c->cx); return RX_ERR_REPLAY; }/;/~Cortex hash chain verified at open~redundant: at open the chain value is rebuilt from the stored record digests (rx_cortex.c chain_step in append at line 166) and cx_verify_chain re-hashes the in-memory objects that replay already verified per record (M09) and compares them to a chain rebuilt by the same loop, so it can only fail on RAM corruption between replay and verify and alone adds nothing; M13 removes both and is KILLED. Candidate equivalent mutant, UNVERIFIED
 M04~src/runtime/rx_compose.c~s/js_branch_info(&c->js, r, &bi) == JS_OK \&\& !bi.staged/js_branch_info(\&c->js, r, \&bi) == JS_OK/~recovered state branch must be sealed, not staged~redundant: no injection can leave a staged branch in the durable checkpoint (staged branches are never persisted, rx_compose.h recovery note), candidate equivalent mutant, UNVERIFIED
 M05~src/runtime/rx_compose.c~s/if (!o || o->id <= chosen) continue;/continue;/~answer newer, non-durable state records with a rollback admission
 M06~src/runtime/rx_compose.c~s/for (uint32_t i = l->n; i-- > 0;) {/for (uint32_t i = 0; i < l->n; i++) {/~choose the NEWEST durable state record
@@ -29,7 +29,7 @@ M09~src/runtime/rx_cortex.c~s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (
 M10~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint body digest~redundant: header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation
 M11~src/runtime/rx_jspace.c~s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint header digest~redundant: header digest, body digest and the restore-time content check overlap; each alone is covered by the others and by structural validation
 M12~src/runtime/rx_compose.c~s/if (js_space_commit(&c->js) != JS_OK) return RX_ERR_REPLAY;/;/~recovered state is made durable before the World starts
-M13~src/runtime/rx_compose.c,src/runtime/rx_cortex.c~s/if (cx_verify_chain(&c->cx) != CX_OK) { cx_close(&c->cx); return RX_ERR_REPLAY; }/;/@@s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/~Cortex integrity (both the load digest and the chain check removed)
+M13~src/runtime/rx_cortex.c,src/runtime/rx_cortex.c~s/if (memcmp(s->obj\[id - 1\].digest, b + p + 8 \* (CX_R_FIXED + n), 32) != 0) {/if (0) {/@@s/return memcmp(chain, s->chain, 32) == 0 ? CX_OK : CX_ERR_DIGEST;/return CX_OK;/~Cortex integrity (open-time record digest and the audit chain compare both removed)
 M14~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/~J-Space checkpoint integrity (header and body digests both removed)~gap: with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite
 M15~src/runtime/rx_jspace.c,src/runtime/rx_jspace.c,src/runtime/rx_jspace.c~s/if (memcmp(d, f + 64, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(d, f + 96, 32)) return JS_ERR_CORRUPT;/;/@@s/if (memcmp(chk, r->content, 32)) { s->stats.corrupt_restores++; return JS_ERR_CORRUPT; }/;/~J-Space integrity, all three layers (header digest, body digest, restore-time content check) removed~gap: with every J-Space integrity digest removed all 820 single-byte flips of the task checkpoint are still refused structurally or benign, so the digests are not shown to bite
 M16~src/runtime/rx_compose.c~s/if (pp \&\& state_ref_promoted(s, pp\[CX_WREC_FIELD0 + RXC_S_REF\])) return RX_ERR_REPLAY;/(void)pp; (void)state_ref_promoted;/~refuse a J-Space checkpoint that lost a state Cortex already promoted
@@ -58,6 +58,7 @@ echo "$MUTANTS" | while IFS="~" read -r id file expr what redund; do
         log="$work/$id.log"
         if ! (cd "$dir" && nice -n 10 make PHYSICS_DIR="$phys" ${MAKE_ARGS:-} c4-requal-bin >"$log" 2>&1); then
             status=ERROR; note="build failed: $(grep -m1 -E "error:|Error " "$log" | cut -c1-120)"
+            [ -s "$log" ] || note="build failed: empty make log (make killed or never started)"
         else
             (cd "$dir" && ./build/rx_c4_requal "$dir/r.json") >"$log.run" 2>&1
             rc=$?