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 / quantity / README.md

105 lines · 10828 bytes Raw Blame History Rendered
1# SC1-Q checked quantities
2
3Implementation plan: (1) freeze API and fixtures, (2) implement checked operations and independent fixtures, (3) compile pinned seed and execute native tests plus named mutants, (4) record immutable evidence. Scope is only `om/quantity/`.
4
5## Frozen API
6
7`struct bqty val ulong cap ulong end`; `struct qobj ident ulong ver ulong extent ulong end`; `struct qslic ident ulong ver ulong off ulong count ulong end`.
8
9The library struct was first frozen as `struct qty`. Since #909/#914 the seeded compiler has a native `qty` type keyword (spec/quantities-and-modular.md section 6, Phase 1), so `struct qty` is refused with error 16. The struct is renamed `bqty` (bounded quantity) with identical fields and semantics; this is the Phase 2 nominal library type, layered on top of the native Phase 1 `qty`, not a replacement for it. The native `qty` traps on overflow; `bqty` carries a nominal cap and returns status codes. Receipts recorded before the rename used the old name and compiler 734f0a39; the post-rename replay is a separate receipt.
10
11All functions return int: 0 success, 1 invalid operand (`val > cap`), 2 domain mismatch (different caps, negative signed ingress, widening via narrow), 3 overflow/underflow or extent violation, 4 object/version mismatch. Checks precede arithmetic and output stores. Every refusal leaves the complete output unchanged. Output must be a distinct struct from each input (seed alias rule).
12
13- `qword(out edit bqty, raw ulong, cap ulong)` and `qsigned(out edit bqty, raw long, cap ulong)` validate original ingress, then write value/cap.
14- `qadd/qsub/qmul(out edit bqty, a view bqty, b view bqty)`: validate both operands, require equal caps, then checked arithmetic within that cap. Subtraction refuses b>a. Zero multiplication succeeds.
15- `qnarrow(out edit bqty, a view bqty, cap ulong)`: validate a, refuse cap>a.cap as domain mismatch, refuse a.val>cap as overflow; no scalar cast before validation.
16- `qnext(out edit bqty, a view bqty)`: validate a and refuse a.val==a.cap; increment without wrap.
17- `qtyslice(out edit qslic, off view bqty, count view bqty, expect view qobj, current view qobj)`: compare all expected/current identity, version and extent fields, validate operands and require both caps equal current.extent, then check off<=extent and count<=extent-off. Writes binding plus offset/count, never forms an unchecked end address.
18
19Raw words, struct construction, field writes and extraction are trusted boundaries, not sealing or provenance. In particular qword(add raw_a raw_b) cannot detect a prior wrap. Consumers must recompute from validated original operands at the effect boundary. A `ulong` identity is an owner-assigned nonreused object identifier, not an fd; the owner supplies the trusted current version/extent. Reusing both identity and version cannot be detected here. This library has no authentication, storage, parser, address dereference or service integration.
20
21Equal caps are not physical units: two counts from different application domains
22still have type `bqty`. The consumer owns that domain distinction. To revalidate
23a serialized slice, reconstruct distinct checked offset/count values from its
24original fields and the trusted current extent, construct the expected object
25from its recorded identity/version, then call `qtyslice` against the current
26object immediately before the effect. Never treat a raw `qslic` as validated.
27
28## Frozen expectations before implementation
29
30Q1: `(18446744073709551608 + 16) mod 2^64 = 8`; checked add returns3 and leaves sentinel output unchanged. Q2: exhaustive widths1..8, all pairs in0..(2^w-1), compare add/sub/mul with independent exact arithmetic oracle within u64. Q3: u64 zero/max, malformed operands, domain mismatch. Q4: max*2 returns3 before multiplication; zero*max succeeds. Q5: signed -1 returns2 unchanged; signed max succeeds under u64 max. Q6: 256 narrowed to255 returns3 unchanged; 255 narrowed to255 succeeds; widening refuses2. Q7: zero and exact extent slices succeed, extent+1 refuses3. Q8: scalar passed to bqty and bqty passed to scalar are compiler error7; ordinary crypto-style unsigned wrap stays accepted. Q9: epoch max refuses3; stale version and reused identity with changed version refuse4; identity or extent mismatch refuses4. Every runtime refusal checks output preservation.
31
32Mutation controls must compile and reach the named Q1_ADD_GUARD and Q4_MUL_GUARD assertions, with normal exit1. Build failures or signals do not count.
33
34## Qualification boundary
35
36This is a bounded library profile. Independent review is complete (see below). It is not language-wide constructor sealing, formal/native translation proof or a qualified consumer migration. The omnet transport/Revision consumer slice exists only as a proposal in aien-dev/omnet#6, with the remaining sites inventoried, not migrated. Those remain open under #756/#673. Native execution, finite exhaustive arithmetic checks, compiler-refusal fixtures and mutation sensitivity are separate evidence categories. No GPU or timing secrecy claim.
37
38## Native replay
39
40Run from repository root on Linux AArch64. The only production unit is `quantity.om`; `tests.om` is the executable fixture runner, `demo.om` is the demonstration, and `mutate.om` is a test-only exact source transformer. No generated binary is installed or committed.
41
42```sh
43nice -n 19 sh seed/omega-from-seed.sh
44sha256sum seed/out/omc
45# Required compiler hash: 26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991
46# (the replay receipt below used the previous pin 62775d2a...; both emit the same bytes for these programs)
47mkdir -p /tmp/security756-replay
48cat om/quantity/quantity.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/tests
49chmod +x /tmp/security756-replay/tests
50nice -n 19 /tmp/security756-replay/tests
51cat om/quantity/quantity.om om/quantity/demo.om | nice -n 19 seed/out/omc > /tmp/security756-replay/demo
52chmod +x /tmp/security756-replay/demo
53nice -n 19 /tmp/security756-replay/demo
54nice -n 19 seed/out/omc < om/quantity/fixtures/crypto-wrap.om > /tmp/security756-replay/crypto
55chmod +x /tmp/security756-replay/crypto
56nice -n 19 /tmp/security756-replay/crypto
57cat om/quantity/quantity.om om/quantity/fixtures/mixed-scalar.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-scalar
58cat om/quantity/quantity.om om/quantity/fixtures/mixed-quantity.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-quantity
59cat om/quantity/quantity.om om/quantity/fixtures/mixed-object.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-object
60cat om/quantity/quantity.om om/quantity/fixtures/mixed-slice.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-slice
61nice -n 19 seed/out/omc < om/quantity/mutate.om > /tmp/security756-replay/mutate
62chmod +x /tmp/security756-replay/mutate
63nice -n 19 /tmp/security756-replay/mutate a < om/quantity/quantity.om > /tmp/security756-replay/add.om
64nice -n 19 /tmp/security756-replay/mutate m < om/quantity/quantity.om > /tmp/security756-replay/mul.om
65cat /tmp/security756-replay/add.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/mutant-add
66cat /tmp/security756-replay/mul.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/mutant-mul
67chmod +x /tmp/security756-replay/mutant-add /tmp/security756-replay/mutant-mul
68nice -n 19 /tmp/security756-replay/mutant-add
69nice -n 19 /tmp/security756-replay/mutant-mul
70```
71
72Expected exits: successful compiles, tests, demo and crypto control0; each mixed-type compile7; guard transformer0; each mutant compile0 and execution1, printing its named failed assertion. Never execute output from a refused compile. Check each command's exit individually; an arbitrary nonzero is not success.
73
74The independent arithmetic oracle uses signed long operations on inputs0..255, whose exact sums/products fit (at most510/65025); it does not duplicate the library's overflow predicate. The runner exhausts87380 pairs across widths1..8 and262140 binary operations, plus all in-domain raw/signed constructors, next operations, all87380 narrowing pairs, and the zero-capacity unary fixture. This is finite differential checking, not a proof over u64. Extrema and object cases are separately named fixtures. Output sentinels check every tested refusal. The demo's side-effect counter is a local witness only, not a real service-effect test.
75
76Observed evidence is additive under `evidence/`. It retains initial attempts, including the scalar literal syntax diagnostic16 before the fixture was corrected to pass a scalar variable and reach the intended nominal type diagnostic7. The compiled mutation controls both execute to their intended assertion; the transformer also refuses absent/duplicate guards (exit4) and an invalid mode (exit2).
77
78Independent review found no implementation defect and requested additional u64
79multiply fixtures. The runtime suite now refuses `2^32 * 2^32` and
80`(2^32+1)^2`, accepts the exact `(2^32-1)^2 = 18446744065119617025`,
81and exercises `0 * u64_max`. The second refusal defeats a multiply-first guard
82that only compares the wrapped product against its cap and left operand.
83Object-to-quantity and slice-to-quantity fixtures also refuse with compiler7.
84These are boundary checks, not exhaustive u64 proof. The finite signed oracle
85shares the compiler with the library; it is algorithmically independent, not
86an independently compiled translation referee. Original evidence remains immutable;
87review additions and final clean replay have separate receipts. The replay after
88the `qty` -> `bqty` rename on main's compiler 62775d2a is the additive receipt
89`evidence/main-omc-rename-replay.json`: tests, demo and crypto exit0, the four
90mixed fixtures compile7, both mutants exit1 at their named guards, an invalid
91transformer mode exits2, and the exporter stdout equals the retained corpus byte
92for byte. The earlier receipts, recorded with compiler 734f0a39 and the old name,
93are unchanged.
94
95`oracle-export.om` emits actual helper results, with no reference arithmetic in
96the program: width1..8, a0..cap, b0..cap, then add/sub/mul, three little-endian
97u64 words per result `(status,value,cap)`. The external arbitrary-precision oracle
98compares each exact integer result with `[0,cap]`; expected success is
99`(0,result,cap)`, refusal `(3,17,19)`. All262140 records matched independently,
100including every refusal sentinel. `evidence/review-exhaustion.json` binds the
1016291360-byte output and exporter; the raw output is retained compressed beside it.
102Replay by concatenating `quantity.om oracle-export.om` into the pinned compiler,
103executing the resulting binary, and comparing its stdout SHA-256 and bytes to
104the decompressed corpus. This supplements, rather than relabels, the original
105same-compiler signed oracle.