interplane.Get Omega
Read in your language

omega-mv

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

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / codec / README.md

245 lines · 14623 bytes Raw Blame History Source

om/codec: the graph codec, canonical form and validator in Omega

codec.om ports src/omega_codec.c, src/omega_canonical.c and src/omega_validate.c (with omega_codec.h, omega_canonical.h, omega_validate.h, omega_types.h) to seeded Omega, for aien-dev/omega-mv#726. It also ports the parts of src/omega_core.c that those files call: the effect payload decode (omega_effect_read) and the four builders that omega_graph_parse_text uses. No C file changes. Nothing is linked into the product yet.

filerole
codec.omthe library (12 exported functions) and, after the note ==== parity harness line, a program-mode harness
parity/corpus.pydeterministic corpus generator (wire graphs, text inputs, hex-id records)
parity/expected.txtsha256 of each output stream as the C oracle wrote it
parity/run.shcompiles codec.om, regenerates the corpus, compares every stream with expected.txt; --mutants adds 21 mutants
parity/unit.pycuts the function-mode unit of one exported function (for omega-bridge ABI v1)

What the C files contain (and where the task text differs)

The task text speaks of "programs/ops/operands" and "decode bytes into a program record". The C has no program or op list. It has an OmegaGraph of up to 256 semantic objects. Each object has a kind, up to 32 attributes (key and value), 64 relations (kind and target id), 32 constraints and a 1024-byte payload. The payload bytes are read through host structs (TypePayload, ValuePayload, OperationPayload, ApplyPayload). The port follows the files:

The task corpus does not exist. The task asked for every .omega/.osc/.bin file under tests/ and examples/ that the C decoder accepts:

The accepted graphs therefore come from two sources:

Design: a graph is a wire image plus an index

The C OmegaGraph is 6,648,836 bytes of fixed records. Omega has no structs that could be passed across the ABI, no heap, and no globals in function mode. So the port never builds the struct. Instead, a graph is two arrays:

Every field of the C object is a function of W and X. Relations are fixed-size records, so one offset locates all of them. cparse uses the C builders' record layout to write the objects it builds into W as an OMGG image. Then it indexes W with the same decoder. A builder object has no attributes, so its canonical encoding is exactly its record, and re-decoding it gives the same object.

sbyte returns any byte of the C struct image of object j, using the aarch64 LP64 layout measured with offsetof:

The C reads past an object's 1024-byte payload in two places, and the port reproduces both:

C behaviours the port keeps:

The cycle walk does not recurse, because function mode forbids call cycles. It keeps an explicit stack of frames (object, phase, step, next j) and visits objects in the C's order. That order includes duplicate objects with equal ids. Cycles are reachable only through the operand read past the payload, when it lands on an id stored in the next object's attribute value. The corpus builds such cycles on purpose.

Oracle

Parity (pinned omc 26540e6d…8991)

codec.om sha256 is c8e93310…a2e8. It compiles to a 95,048-byte program, the same bytes as under the previous pins 3ad9f10f…3194, b4f45121…9b55, be8c5130…448a, 24caacf4…abb7, 90c8884c…3983, 469532a5…79bc and 62775d2a…712b. The corpus is generated on every run:

streamwhat it recordslinesresult
decoderc, count, has_id and id of every object4,564 (2,908 decoded)equal to C
validaterc and message (23 distinct message forms seen, including 8 cycles)2,908equal
serializerc, length, bytes, sha256 at max_len 1,049,606; rc and length at 8,1922,908equal
formatrc and text at cap 4,096 and at cap 2002,908equal
parseparse_text rc, ids, then the validate, serialize and format lines of the graph it built6,448equal
hexidparse_hex rc and output bytes, hex of an id, compare of two ids and of an id with itself6,000equal
headerobject_version and check_header for all 65,536 (version, kind) pairs65,536equal

The decode inputs are:

The text inputs cover:

Mutants. run.sh --mutants makes 21 single edits. Each one must change the stream it names, and it must run to completion: a trap does not count as killed. All 21 are killed:

Reproduce from a fresh clone; the default omc is the checkout's seed/out/omc, which is the pinned one:

sh om/codec/parity/run.sh --mutants

ABI note (bindable functions)

The pinned omc refuses const in function mode (error 9), so array lengths are written as numbers. parity/unit.py cuts each exported function with its helpers. Every one of the 12 units compiles in function mode. The pinned native.om (omega-bridge 012860db, sha256 2c2c53f6…3940) accepts them all, and its generated C compiles with -Wall -Wextra -Werror. Signatures:

There is also a check run outside the tree. A /tmp driver (abi.c sha256 e2f31ab1…6a6f) ran all 7 streams through the generated bindings, and the output was byte-identical to the C oracle's.

Limits

  1. WCAP. cdecode returns -2 instead of continuing when it would read a wire byte at or past 2,097,152. The C has no such limit. run.sh shows a 2,097,174-byte graph that the C decodes (rc 0) and the port refuses (rc -2). Every graph that serialize can write is at most 1,049,606 bytes, and the product's callers use 4,096 to 8,192-byte buffers.
  2. SCAP. cparse returns -2 when the input is longer than 262,144 bytes. The C has no limit. The string ends at its first NUL or at n.
  3. TCAP. cformat returns -1 for cap > 65,536, which the C would format. The product's caller uses 4,096.
  4. The error buffer is 256 bytes, and there is no length parameter. The C callers pass 256 (omega_verify.c, omegatool.c, visor_verify.c) or 160 (visor_effect_request.c). The longest message is 99 bytes (a dangling-relation message with its 64 hex digits), so the C's snprintf never truncates for these callers. A caller that passes fewer than 100 bytes would see truncation in the C and not here. An adapter for a 160-byte caller copies the message out.
  5. Reads past the object. Inside the graph, the port reproduces the C struct image exactly. Past the end of OmegaGraph, the C reads memory it does not own (undefined behaviour), and the port returns zero there. That matches the oracle only because the oracle's graph sits in zeroed slack. Another caller's memory past the graph could differ.
  6. omega_validate_object. The C also takes an object that is not in the graph. cvobject validates X's object j.
  7. Arguments. j must be below 256 (ccanon, cvobject), or the call traps 3. W and X must come from cdecode or cparse: an arbitrary index can trap (out of range).
  8. ccanon on failure. When the encoding exceeds 4,096 bytes, ccanon writes nothing. The C writes a prefix before it fails. No caller reads the buffer after a failure. cserial writes the same prefix as the C.
  9. Unreachable C paths are not ported:
    • NULL-argument checks and their messages (Null graph pointer, Null object pointer);
    • Graph object count %u exceeds maximum (X never holds more than 256);
    • the C's omega_graph_find_object* and the other builders in omega_core.c, which are out of scope.

    The effect-refusal message in validate is ported but not covered: a decoded graph's effects have already passed the same check, and parse_text builds no effects.

  10. Platform. Parity holds for the product's platform: aarch64 LP64 struct offsets, glibc 2.39 strtoul/strtol/memcmp, and the C locale. It is not claimed for another libc or ABI.

NOT_RUN