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
omega-mv / om / receipt / README.md
| 1 | # receipt.om: the EvidenceReceiptV1 reader in seeded Omega |
| 2 | |
| 3 | `receipt.om` ports `src/omega_receipt.c` and `src/omega_receipt.h` to seeded Omega. These files are the |
| 4 | C reader of the aien-proof EvidenceReceiptV1 wire contract (VC1 stage 4). The port does what the C |
| 5 | does: |
| 6 | |
| 7 | - parses the receipt JSON with serde's shape rules (no unknown fields, the same required and |
| 8 | defaulted fields); |
| 9 | - applies every `canonical_bytes` validation in the C order; |
| 10 | - builds the canonical byte encoding; |
| 11 | - computes the id as BLAKE3 over those bytes; |
| 12 | - `verify_bytes` requires the `id` field to equal that BLAKE3 value, in either hex case. |
| 13 | |
| 14 | It also covers `omega_tier_rank` and `omega_tier_satisfies`. Part of #726, |
| 15 | aien-dev/aien-architecture-mv#300 and #316. No C file is changed or removed by this port. |
| 16 | |
| 17 | ## Layout |
| 18 | |
| 19 | The library is everything above the line `note ==== parity harness`. It uses no globals and no |
| 20 | `text`, and every array length is a literal, because function-mode units refuse `const` (error 9). |
| 21 | `parity/unit.py` can cut any entry point into a function-mode unit for the omega-bridge native call |
| 22 | ABI v1: |
| 23 | |
| 24 | | entry | signature (ABI v1) | C counterpart | |
| 25 | |---|---|---| |
| 26 | | `rcparse js n wk` | `js view uchar 4194304`, `wk edit ulong 65536` → long | `omega_receipt_parse` | |
| 27 | | `rccanon js n wk out pos` | `out edit uchar 1049632` → ulong (total length) | `omega_receipt_canonical` + `omega_receipt_compute_id` | |
| 28 | | `rcverify js n wk out` | → long | `omega_receipt_verify_bytes` | |
| 29 | | `rctier s n wk` | → long | `omega_tier_rank` | |
| 30 | | `rcsat need have` | → long | `omega_tier_satisfies` | |
| 31 | |
| 32 | `rcparse` and `rcverify` return 0 or -1, as the C does. A refusal is stored as three numbers: |
| 33 | |
| 34 | - `wk[0]`: a reason code, 1..69, one for each distinct C message; |
| 35 | - `wk[1]`: a field-name index, for messages that name a field; |
| 36 | - `wk[2]`: the byte offset, for JSON syntax messages. |
| 37 | |
| 38 | The program-mode harness renders these numbers as the exact C message text. `rccanon` streams the |
| 39 | canonical bytes: |
| 40 | |
| 41 | - bytes `[pos, pos + 1 MiB)` go to `out[0..]`; |
| 42 | - the 32-byte id goes to `out[1049600..]`; |
| 43 | - the return value is the total length. |
| 44 | |
| 45 | Canonical bytes over 1 MiB need one call per window, and each call re-encodes the whole receipt. |
| 46 | |
| 47 | There is no DOM. Pass 1 checks the JSON syntax with the C reader's exact rules, errors and byte |
| 48 | offsets. It is iterative, because function mode refuses call cycles. Pass 2 reads fields by walking |
| 49 | the validated text, and decodes strings on the fly for comparisons, sorting and output. The whole |
| 50 | `wk` layout is documented at the top of `receipt.om`. |
| 51 | |
| 52 | BLAKE3 is copied from `om/blake3/b3unit.om`, because Omegese has no `import`. The task named |
| 53 | `blake3.om`, but that file uses globals, so it cannot become a function-mode unit; `b3unit.om` is the |
| 54 | array-parameter form from the same merged work. Three locations changed; the compression code is |
| 55 | unchanged: |
| 56 | |
| 57 | - the chaining-value stack lives in `wk` at 512 (depth 952, chunk count 953); |
| 58 | - the chunk is read from `out` at 1048576; |
| 59 | - the root is written to `out` at 1049600. |
| 60 | |
| 61 | ## Build and run |
| 62 | |
| 63 | ``` |
| 64 | OMC=/path/to/seed/out/omc # pinned: sha256 26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991 |
| 65 | $OMC < om/receipt/receipt.om > receipt && chmod +x receipt |
| 66 | python3 om/receipt/parity/corpus.py /tmp/corp && ./receipt < /tmp/corp/rust.bin |
| 67 | ``` |
| 68 | |
| 69 | The harness reads records from stdin and writes one line per record. The record format and the |
| 70 | line format are described in the notes at the end of `receipt.om`. Exit 65 means a short record. |
| 71 | |
| 72 | ## Parity |
| 73 | |
| 74 | `OMEGA_OMC=$OMC [OMEGA_BRIDGE=<omega-bridge checkout>] sh om/receipt/parity/run.sh` |
| 75 | |
| 76 | This command compares the .om output with **recorded** C oracle hashes in `parity/expected.txt`. It |
| 77 | does not build or run any C. It then applies 20 mutants to `receipt.om`. Each mutant must run to exit |
| 78 | 0 and change its stream's sha256. With `OMEGA_BRIDGE` set, it also cuts the five entry points into |
| 79 | units, binds them with the pinned `native.om`, and compiles the generated C. |
| 80 | |
| 81 | **Oracle.** `src/omega_receipt.c` (sha256 `88cfe0c5…1651`) and `omega_receipt.h` (`d8043519…1cbf`) at |
| 82 | omega-mv `acb3f15c`. Built with gcc 13.3.0 and `-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2`, |
| 83 | the Makefile CFLAGS that apply to these files. It is linked with the product BLAKE3 |
| 84 | (`src/omega_blake3.c` + `src/sha256.c`, which is itself the bound `b3unit.om`). A second build with |
| 85 | the pre-port C BLAKE3 (`633a1735:src/omega_blake3.c`, sha256 `c89ef819…0f21`) gave byte-identical |
| 86 | output for every stream. The three receipts written by the Rust implementation verify to their |
| 87 | file-name ids. The driver is kept out of the tree. |
| 88 | |
| 89 | **Corpus.** `parity/corpus.py` is deterministic. It has 9,261 records (45 MB) and is regenerated on |
| 90 | every run. |
| 91 | |
| 92 | | stream | records | content | result | |
| 93 | |---|---|---|---| |
| 94 | | rust | 18 | the 3 Rust receipts, each with an upper-case id, compact, indented, keys reversed, and a `\u` escape | 18/18 lines identical | |
| 95 | | shapes | 96 | every receipt shape of `tests/test_omega_resolve.c` `t_receipts`, plus one receipt that uses every field; each as R (placeholder id), M (id computed, then verified) and M with an upper-case id | 96/96 | |
| 96 | | fields | 1,634 | each top-level key missing or given 17 wrong values; escapes and UTF-8 in every string; version and timestamp edges; commit, tier, result and digest forms; the full declared × observed mutation × tier matrix (648); ledger, lease and assertion shapes; production authority spellings; sorting and dedup with multi-byte and escaped strings; formatting variants | 1,634/1,634 | |
| 97 | | json | 3,412 | 110 handwritten syntax cases (every JSON message), 1,500 grammar-fuzz documents and a one-byte corruption of each, 300 random byte strings, a 3,000-key object and its duplicate-key twin | 3,412/3,412 | |
| 98 | | mutants | 4,062 | mutated serialised receipts: every byte of Rust receipt 1 with bit 0x20 flipped (1,168), every truncation of Rust receipt 2 (1,094), 600 random byte flips of the Rust receipts, and 1,200 flips or truncations of receipts built with computed ids | 4,062/4,062 | |
| 99 | | big | 21 | lists of 4,096 entries and 4,097 entries (each list field), 4,096 and 4,097 assertions, 4.1 MB canonical bytes (5 windows), a 1 MiB authority, 3 MB UTF-8 and 3.6 MB `\u` strings, inputs of exactly 4 MiB and 4 MiB + 1, empty input, a 2,000,000-digit timestamp, a 3 MB array | 21/21 | |
| 100 | | tier | 18 | `omega_tier_rank` for 17 strings and the `omega_tier_satisfies` table over -3, -1, 0..8 | 18/18 | |
| 101 | |
| 102 | Every line holds: |
| 103 | |
| 104 | - the parse return code, and the C error message or the canonical bytes in hex; |
| 105 | - the computed id; |
| 106 | - the verify return code, and the message or the id. |
| 107 | |
| 108 | All 69 C messages are covered except three that are unreachable (see below). The mutants stream |
| 109 | alone has 59 receipts that still verify, 211 that parse but fail the id check, and 3,792 that are |
| 110 | refused. |
| 111 | |
| 112 | **Mutants.** Twenty mutants: five JSON (duplicate key, depth, surrogate UTF-8, pair offset, leading |
| 113 | zero) and eleven receipt rules (deny unknown, schema, env_class, PASS needs an assertion, test-only |
| 114 | authority, canonical sort, id compare, `\f` decoding, set dedup, mutation order, u64 overflow). Four |
| 115 | more cover upper-case hex, the BLAKE3 root flag, the canonical window edge and the test-only tier |
| 116 | rule. Every one is killed. |
| 117 | |
| 118 | **ABI check.** This was run outside the tree, by a /tmp driver linking the generated bindings. It ran |
| 119 | every stream through the five bound units and rendered messages from the reason codes. The output |
| 120 | hashed to `expected.txt`. |
| 121 | |
| 122 | On the Spark (arm64), the whole corpus takes 8.7 s for the .om harness and about 1.5 s for the -O2 |
| 123 | C driver. |
| 124 | |
| 125 | ## Where the C and the task text differ |
| 126 | |
| 127 | - The task asks to port "receipt building, serialisation, parsing and verification". The C has no |
| 128 | JSON writer and no receipt builder. It parses, validates, builds the canonical bytes, hashes and |
| 129 | verifies. The port follows the C. "Building" in the corpus is the test's `rj_make` step (placeholder |
| 130 | id, compute, patch), done by the harness's M records in the same way as the C driver. |
| 131 | - The C reports errors as `-1` plus a text message, with no numeric error codes. Parity therefore |
| 132 | compares the return code and the full message text, including JSON byte offsets. |
| 133 | - Some code cannot run: |
| 134 | - "a read-only run cannot claim that mutation" is unreachable in the C. At tier rank 4, any |
| 135 | observed mutation with index ≥ 4 has severity ≥ 4 and is refused one line earlier. |
| 136 | - The `need >= 4 && have < 4` clause of `omega_tier_satisfies` is implied by the final |
| 137 | `have >= need`, so removing it changes nothing. |
| 138 | - "out of memory" and "cannot compute canonical identity" occur only when the C's malloc fails. |
| 139 | The port has no heap. |
| 140 | |
| 141 | The port keeps all of these as written. |
| 142 | |
| 143 | ## Limits |
| 144 | |
| 145 | - **Struct not exposed.** The parsed `OmegaReceipt` is not returned. Callers get the return code, the |
| 146 | reason, the canonical bytes and the id. `wk` holds offsets into `js`, not decoded strings. |
| 147 | `omega_resolve.c` and `omega_vc_bridge.c` read struct fields: tier_rank, dependencies in input |
| 148 | order, and others. An adapter therefore still needs field accessors before any C can be deleted. |
| 149 | `omega_receipt_free` has no counterpart. |
| 150 | - **Message text.** Function-mode units cannot hold `text`, so units return reason codes. Today the |
| 151 | 69-message table lives only in the harness, and a C adapter would need the same table. |
| 152 | - **Capacities match the C.** Input is limited to 4 MiB (`OMEGA_RECEIPT_MAX_BYTES`), lists and |
| 153 | assertions to 4,096 entries, and nesting to depth 6. Callers provide scratch: `wk` is 512 KiB and |
| 154 | `out` is 1 MiB + 1 KiB. The harness program needs about 5.7 MiB of its 8 MiB stack. |
| 155 | - **Duplicate-key cost.** The duplicate-key check rescans earlier members of the object, which costs |
| 156 | O(keys × object bytes). The C costs O(keys²) strcmp calls. Both are quadratic, and only |
| 157 | pathological objects notice. |
| 158 | - **Tier names.** `rctier` compares all n bytes. The C stops at a NUL, so an adapter passes |
| 159 | `strlen`. |
| 160 | - **Message truncation.** The C truncates messages to `errcap`. The harness and the oracle use 256, |
| 161 | and no message is longer than 160 bytes. |