From 8938011a20dae6c138a69a3ee62de993427c9f62 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 25 Oct 2026 17:10:06 -0500 Subject: [PATCH 1/5] fix(store): charge record framing with checked quantities stwrite accepted a length, a running byte total and a running record count through three hand-written comparisons, and stnext re-derived the same three checks while reading. Both sites are now a single checked charge built on the SC1-Q quantity subgraph: stbound admits a length inside the fixed 65536 frame buffer, stcharge accumulates the total up to 33554432 and stcount steps the count up to 65536. Refusal codes are unchanged (1 with the poisoned flag on write, -1 while reading), so every caller keeps its contract. A running charge below zero is now a declared refusal instead of a checked conversion trap; it is not a reachable store state, but the store must answer rather than trap mid-write. No vulnerability is claimed or retracted. The producers that feed these lengths were traced and left alone because they are already bounded: state.om dssave lengths are bounded at this single effect boundary, socket.om takes ds_ctl 3 from a 0/1 header byte and ds_ctl 4 from one byte, and the disablement secret is refused above 1024 bytes at both ingresses before it reaches the 2048-byte ds_sup/ds_dis arrays. The store suite compiles om/quantity alongside the store units and adds two controls: a negative running byte charge and a negative running record count must be declared refusals, not traps. Reachable caps stay pinned by the existing U/Q/C modes, each asserting a byte-identical committed snapshot. Mutants are not claimed for the charge helpers: the states that separate the checked form from a modular sum are unreachable from the public API, and the difference there is a trap, which the mutant rule does not count as detection. (cherry picked from commit 604ee274a3d12883aa4d70855e5f16b8fda8e792) --- om/store/storepool.om | 81 ++++++++++++++++++---- om/store/test/driver.om | 19 +++++ om/store/test/run.py | 6 +- qualification/security3-store/README.md | 92 +++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 qualification/security3-store/README.md diff --git a/om/store/storepool.om b/om/store/storepool.om index 6798eba..f34bdfd 100644 --- a/om/store/storepool.om +++ b/om/store/storepool.om @@ -34,6 +34,59 @@ end ret 0 end +note Store capacity is charged as checked quantities. A record length is admitted +note only if it fits the fixed 65536 frame buffer, and the running byte total and +note record count are accumulated with checked addition up to their declared caps. +note A refused charge returns its cap plus one, which no caller can accept. +fn stbound n ulong to ulong +q = new qty ulong 0 ulong 0 +if ne qword q n ulong 65536 int 0 +ret 65537 +end +ret get q val +end +fn stcharge cur long n ulong to ulong +note A charge below zero is not a reachable store state; refuse it rather than +note trap on the unsigned conversion below. +if lt cur long 0 +ret 33554433 +end +if gt stbound n 65536 +ret 33554433 +end +a = new qty ulong 0 ulong 0 +b = new qty ulong 0 ulong 0 +o = new qty ulong 0 ulong 0 +if ne qword a ulong cur ulong 33554432 int 0 +ret 33554433 +end +if ne qword b n ulong 33554432 int 0 +ret 33554433 +end +note SC1_CHARGE mutation bypasses this checked addition with a modular sum. +if ne qadd o a b int 0 +ret 33554433 +end +ret get o val +end +fn stcount cur long to ulong +note A count below zero is not a reachable store state; refuse it rather than +note trap on the unsigned conversion below. +if lt cur long 0 +ret 65537 +end +c = new qty ulong 0 ulong 0 +o = new qty ulong 0 ulong 0 +if ne qword c ulong cur ulong 65536 int 0 +ret 65537 +end +note SC1_COUNT mutation bypasses this checked step with a modular sum. +if ne qnext o c int 0 +ret 65537 +end +ret get o val +end + note Reader rejects all damage including trailing data and missing terminator. fn stnext fd int out edit uchar 65536 to long if ne get stctx 11 long 0 @@ -70,10 +123,12 @@ end if gt n 65536 ret -1 end -if gt add ulong get stctx 8 n 33554432 +nb = stcharge get stctx 8 n +if gt nb 33554432 ret -1 end -if ge get stctx 9 long 65536 +nc = stcount get stctx 9 +if gt nc 65536 ret -1 end if ne streadall fd out n 0 @@ -83,10 +138,10 @@ sthashdata out n d if ne steqhash h 8 d 0 ret -1 end -put stctx 8 add get stctx 8 long n -put stctx 9 add get stctx 9 long 1 +put stctx 8 long nb +put stctx 9 long nc stgethash 1 p -stchain p d n ulong get stctx 8 ulong get stctx 9 q +stchain p d n nb nc q stsethash 1 q ret long n end @@ -340,15 +395,13 @@ end if eq n 0 ret 0 end -if gt n 65536 -put stctx 10 1 -ret 1 -end -if gt add ulong get stctx 6 n 33554432 +nb = stcharge get stctx 6 n +if gt nb 33554432 put stctx 10 1 ret 1 end -if ge get stctx 7 long 65536 +nc = stcount get stctx 7 +if gt nc 65536 put stctx 10 1 ret 1 end @@ -370,10 +423,10 @@ if ne stwriteall f b n 0 put stctx 10 1 ret 1 end -put stctx 6 add get stctx 6 long n -put stctx 7 add get stctx 7 long 1 +put stctx 6 long nb +put stctx 7 long nc stgethash 0 p -stchain p d n ulong get stctx 6 ulong get stctx 7 q +stchain p d n nb nc q stsethash 0 q ret 0 end diff --git a/om/store/test/driver.om b/om/store/test/driver.om index d599dde..6adeb4c 100644 --- a/om/store/test/driver.om +++ b/om/store/test/driver.om @@ -10,6 +10,22 @@ r = stclose ret testresult code end fn testcapacity b edit uchar 65536 mode uchar to int +note Capacity is charged as checked quantities. These two modes pin the guard +note against a wrapped running charge; the states they set are test-image only. +if eq mode uchar 89 +put stctx 6 long -8 +if ne stwrite b 16 1 +ret testfinish 4 +end +ret testfinish 0 +end +if eq mode uchar 66 +put stctx 7 long -1 +if ne stwrite b 1 1 +ret testfinish 4 +end +ret testfinish 0 +end if eq mode uchar 85 if ne stwrite b 65537 1 ret testfinish 4 @@ -134,6 +150,9 @@ end if or eq mode uchar 81 eq mode uchar 85 ret testcapacity b mode end +if or eq mode uchar 89 eq mode uchar 66 +ret testcapacity b mode +end if ne mode uchar 69 for i ulong 65536 put b i uchar and add ulong seed i 255 diff --git a/om/store/test/run.py b/om/store/test/run.py index d3b96ef..cae7feb 100755 --- a/om/store/test/run.py +++ b/om/store/test/run.py @@ -13,6 +13,7 @@ ROOT = Path(__file__).resolve().parents[3] UNIT = ROOT / "om/store" COMPILER = subprocess.check_output([str(ROOT / "tools/omc.sh")], text=True).strip() BASE = (ROOT / "om/blake2s/blake2s.om").read_text() +QUANT = (ROOT / "om/quantity/quantity.om").read_text() HELP = (UNIT / "store.om").read_text() POOL = (UNIT / "storepool.om").read_text() DRIVER = (UNIT / "test/driver.om").read_text() @@ -21,7 +22,7 @@ COUNT = 0 def compile_binary(folder, name, helpers=HELP, pool=POOL, driver=DRIVER, prefix=""): - source = BASE + "\n" + prefix + "\n" + helpers + "\n" + pool + "\n" + driver + source = QUANT + "\n" + BASE + "\n" + prefix + "\n" + helpers + "\n" + pool + "\n" + driver result = subprocess.run([COMPILER], input=source.encode(), capture_output=True) if result.returncode: (folder / (name + ".om")).write_text(source) @@ -270,6 +271,8 @@ ret renames p ulong 0 ulong 26 int 0""") call(binary, p, "U") # too-large chunk is a declared error, not an array trap call(binary, p, "Q") # exactly 65536 frames, then refuse one more call(binary, p, "C") # exactly 32 MiB payload, then refuse one more byte + call(binary, p, "Y") # a negative running byte charge is a declared refusal, not a trap + call(binary, p, "B") # a negative running frame count is a declared refusal, not a trap assert (p / "snapshot").read_bytes() == original capacity = directory(root, "capacity") call(binary, capacity, "E") @@ -367,6 +370,7 @@ ret renames p ulong 0 ulong 26 int 0""") save(p / "snapshot", forged) call(binary, p, "L", 1) call(mutant, p, "L", 3) + save(p / "snapshot", original) print(f"PASS store: {COUNT} completed native cases; independent BLAKE2s framing; checksum mutant detected") if os.geteuid() != 0: print("SKIP store foreign-UID chown fixtures: runner is non-root") diff --git a/qualification/security3-store/README.md b/qualification/security3-store/README.md new file mode 100644 index 0000000..baf585a --- /dev/null +++ b/qualification/security3-store/README.md @@ -0,0 +1,92 @@ +# SC1-Q durable framing charges + +Base: `security/3-consumer-enforcement` at `b571465`, which supplies `om/quantity`. +This slice is the WORM-owned durable-state side of the SC1-Q row and touches no +transport, revision or comparison function owned elsewhere. + +## What changed + +`om/store/storepool.om` now charges a record against the store limits with the checked +quantity operations instead of loose integer comparisons: + +| Function | Admitted effect | +|---|---| +| `stbound` | a record length is admitted only inside the fixed 65536 frame buffer | +| `stcharge` | running byte total accumulated with `qadd` up to the 33554432 cap | +| `stcount` | running record count accumulated with `qnext` up to the 65536 cap | +| `stwrite` | one charge of length, total and count before any header, payload or footer write | +| `stnext` | the same three charges before a record is accepted while reading | + +The refusal codes are unchanged (`stwrite` 1 with the poisoned flag, `stnext` -1), so every +existing caller and test keeps its contract. Two differences are deliberate: + +- A charge of `n = 65537` and a total over cap now refuse through the same path instead of + two hand-written comparisons, so a future caller cannot re-derive one and forget the other. +- A running charge below zero is a declared refusal. The previous form cast the counter to + `ulong` directly, which is a checked conversion in Omega and traps; it is not a reachable + store state, but a trap in the middle of a write is a worse answer than a refusal. + +## Audit of the neighbouring producers, no source change + +Record lengths and counts that reach `stwrite` were traced to their producers before deciding +not to change them: + +- `cmd/tkad/state.om` `dssave` passes `dsget 3`, `dsget 4`, `dssig` and `tkaget` lengths. All of + them are now bounded at the single effect boundary, so a bounded length in `dssave` is + admitted or refused by the same charge and cannot be forgotten there. +- `cmd/tkad/socket.om` takes `ds_ctl 3` from header byte 5 (`gt get h 5 1` refuses anything but + 0/1) and `ds_ctl 4` from header byte 4, a single byte, so the `dsget 3`/`dsget 4` loops in + `dssave` cannot exceed 1 or 255 against a 65536 buffer. +- The disablement secret reaches `dssecretput` only through `dsvalidsecretat` (`gt n 1024` + refuses) and `dsdisable` (`gt n 1024` refuses), matching `om/argon2` `a2tka`, and + `ds_sup`/`ds_dis` are 2048 bytes with a 1024 stride. The two copy sites are bounded at both + ingresses. + +No vulnerability is claimed or retracted by this audit: the values were already bounded, and +the inventory note "absence of migration is not evidence of a bug" still applies to every +module this slice did not touch. + +## Controls + +`om/store/test/run.py` already pins the reachable caps: `U` (one 65537 chunk refused), `Q` +(exactly 65536 frames, then refuse one more) and `C` (exactly 32 MiB, then refuse one more +byte), each asserting the committed snapshot is byte-identical afterwards. This slice adds the +two charge refusals that are not reachable from the public API: + +- `Y` sets a negative running byte charge in the test image and requires a declared refusal. +- `B` sets a negative running record count and requires a declared refusal. + +Both run on the same image that serves the rest of the suite, and both restore-verify the +committed snapshot. + +Mutants are deliberately not claimed for these two controls. A mutant that drops the checked +step differs from the original only in a state the public API cannot reach, and the difference +it produces there is a trap, which the mutant rule in issue #3 says is not detection. The +reachable-cap controls `U`/`Q`/`C` remain the behavioural pins for the caps themselves. + +## Reproduction + +```sh +sh om/store/test/run.sh +sh cmd/tkad/test/run.sh +sh tools/test.sh +``` + +Verdict at this head: `PASS store` (118 native cases), `PASS tkad` (224 assertions plus the +disk-full, restart, self-exec and corruption arms), `PASS quantity`, `PASS tkasig`, and the +crypto unit suites, from `sh tools/test.sh` (`127` PASS lines, exit 1). The two `FAIL` lines are +`json` and `tka`, and both stop on `go: not found` while building a Go oracle or running the +Go TKA oracle on this host, which has no Go toolchain. This slice touches neither unit, so +those two rows are environmental here and carry no verdict on this change. + +The store suite compiles `om/quantity`, `om/blake2s`, `om/store` and the store pool together, +then runs the driver natively; the daemon suite exercises the same store through the real +socket protocol, including disk-full, restart and corruption cases. + +## Not claimed + +- `cmd/tkad/state.om`, `cmd/tkad/rpc.om`, `cmd/tkad/helpers.om` and `cmd/tkad/main.om` remain + outside the admitted quantity subgraph. +- No constant-time, secrecy, power-loss or whole-path claim is made here. +- The standing per-slot and temporary-reserve charges for the R5 durable resource frame are not + implemented by this slice; these helpers are the accounting primitives that work starts from. From 812b57b406d935a651d719b8659c944617f6d529 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 26 Oct 2026 00:02:25 -0500 Subject: [PATCH 2/5] feat(quantity): carry the checked-quantity unit onto main The store charge change in the next commit calls qword, qadd and qnext. This is the om/quantity unit exactly as written on security/3-store-quantity (f2d702f), carried over unchanged so the store change lands with its helpers and its own test suite. Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Drake Stapleton --- om/quantity/README.md | 55 ++++ om/quantity/demo.om | 94 +++++++ om/quantity/fixtures/crypto-wrap.om | 12 + om/quantity/fixtures/mixed-object.om | 7 + om/quantity/fixtures/mixed-quantity.om | 8 + om/quantity/fixtures/mixed-scalar.om | 7 + om/quantity/fixtures/mixed-slice.om | 7 + om/quantity/mutate.om | 95 +++++++ om/quantity/oracle-export.om | 55 ++++ om/quantity/quantity.om | 142 ++++++++++ om/quantity/test/run.sh | 10 + om/quantity/tests.om | 358 +++++++++++++++++++++++++ 12 files changed, 850 insertions(+) create mode 100644 om/quantity/README.md create mode 100644 om/quantity/demo.om create mode 100644 om/quantity/fixtures/crypto-wrap.om create mode 100644 om/quantity/fixtures/mixed-object.om create mode 100644 om/quantity/fixtures/mixed-quantity.om create mode 100644 om/quantity/fixtures/mixed-scalar.om create mode 100644 om/quantity/fixtures/mixed-slice.om create mode 100644 om/quantity/mutate.om create mode 100644 om/quantity/oracle-export.om create mode 100644 om/quantity/quantity.om create mode 100755 om/quantity/test/run.sh create mode 100644 om/quantity/tests.om diff --git a/om/quantity/README.md b/om/quantity/README.md new file mode 100644 index 0000000..aec3404 --- /dev/null +++ b/om/quantity/README.md @@ -0,0 +1,55 @@ +# Checked quantities (SC1-Q) + +Apache-2.0 source imported byte-for-byte from Omega's `om/quantity/` proposal +[#771](https://github.com/aien-dev/omega-mv/pull/771), not a second implementation. +The `q` function prefix names this unit. Compiler pin is unchanged. + +`qty {val,cap}` distinguishes bounded quantities from modular scalar words; +`qobj {ident,ver,extent}` and `qslic {ident,ver,off,count}` bind a view to an +owner-assigned nonreused object/version, not an fd number. Raw fields remain +trusted construction boundaries, not sealed capabilities or physical units. + +All calls return int:0 success,1 malformed input,2 domain mismatch/negative signed +ingress/widening through narrow,3 overflow/underflow,4 object mismatch. Refusal +leaves output unchanged. Output/input structs must be distinct (seed alias rule). + +- `qword`, `qsigned`: validate original ingress before conversion/effects. +- `qadd`, `qsub`, `qmul`: validate both inputs/equal caps before guarded arithmetic. +- `qnarrow`: target cap cannot exceed source cap; value must fit. +- `qnext`: refuse cap exhaustion; no wrapping policy epoch. +- `qtyslice`: validate expected/current identity, version, extent, then offset and + count by subtraction before address formation. + +A constructor applied after a wrapped sum cannot recover the original operands. +Revalidate serialized slices from original offset/count against the trusted current +object immediately before effects. Same caps do not distinguish application units. + +Actual consumer: `dsframe` and `dsio` validate decoded lengths and cursor arithmetic +before socket effects; `dsgrow` checks positive signed syscall results before +conversion and checked addition. `dsbound` rechecks final response length, but it +cannot prove that all upstream response-writer arithmetic was checked. The remaining +producer/effect inventory is in `qualification/security3-consumer/quantities.json`. + +## Qualification + +The imported runtime fixtures cover widths1..8, u64 wrapping products, negative +input, narrowing, object/version mismatches, unchanged refusal outputs and epoch +exhaustion. Four mixed nominal fixtures must compile-refuse7; crypto wrapping +must execute0. The exact-source add/mul guard mutants must compile and normally +fail their named assertions. `oracle-export.om` emits262140 actual records for +external exact-arithmetic comparison; raw corpus evidence lives in Omega #771. +These are finite/native tests, not a language-wide or translation theorem. + +`sh om/quantity/test/run.sh` is registered by the existing `tools/test.sh` glob. +It only bootstraps the pinned compiler and executes the existing security3 `.om` +coordinator. All selection, source composition, mutation, exit/output checks and +verdicts are in `qualification/security3/run.om --consumer-units`, not shell. +That mode also exercises actual transport/no-op and secret-comparison fixtures; +see `qualification/security3/README.md` for exact commands and retained results. + +## Third-party material and notices + +No third-party algorithm or vector text is copied into this unit. Omega source is +Apache-2.0, the same license as omnet. Imported deterministic fixtures are synthetic. +The independent arbitrary-precision arithmetic oracle is a development tool, not +shipped production/test-runner logic. diff --git a/om/quantity/demo.om b/om/quantity/demo.om new file mode 100644 index 0000000..8780e3d --- /dev/null +++ b/om/quantity/demo.om @@ -0,0 +1,94 @@ +note Concatenate quantity.om then demo.om. No parser or service is simulated. +text db "PASS modular baseline8 checked add status3 unchanged output effects0\n" +text dm "PASS multiply status3 narrow status3 negative status2 unchanged output\n" +text da "PASS reused object identity changed version status4 unchanged slice\n" + +fn demoadd to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 18446744073709551608 ulong 18446744073709551615 +b = new qty ulong 16 ulong 18446744073709551615 +effects = int 0 +rc = qadd out a b +if eq rc int 0 +effects = add effects int 1 +end +if ne effects int 0 +ret bool 0 +end +if ne add get a val get b val ulong 8 +ret bool 0 +end +if ne rc int 3 +ret bool 0 +end +ret and eq get out val ulong 17 eq get out cap ulong 19 +end + +fn demomul to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 18446744073709551615 ulong 18446744073709551615 +b = new qty ulong 2 ulong 18446744073709551615 +rc = qmul out a b +if ne rc int 3 +ret bool 0 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret bool 0 +end +rc = qnarrow out a ulong 255 +if ne rc int 3 +ret bool 0 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret bool 0 +end +rc = qsigned out long -1 ulong 18446744073709551615 +if ne rc int 2 +ret bool 0 +end +ret and eq get out val ulong 17 eq get out cap ulong 19 +end + +fn demoaba to bool +out = new qslic ulong 91 ulong 92 ulong 93 ulong 94 +off = new qty ulong 0 ulong 8 +count = new qty ulong 1 ulong 8 +expect = new qobj ulong 5 ulong 7 ulong 8 +current = new qobj ulong 5 ulong 8 ulong 8 +rc = qtyslice out off count expect current +if ne rc int 4 +ret bool 0 +end +if ne get out ident ulong 91 +ret bool 0 +end +if ne get out ver ulong 92 +ret bool 0 +end +ret and eq get out off ulong 93 eq get out count ulong 94 +end + +fn main to int +if not demoadd +ret int 1 +end +n = write int 1 db ulong 0 len db +if ne n long len db +ret int 2 +end +if not demomul +ret int 3 +end +n = write int 1 dm ulong 0 len dm +if ne n long len dm +ret int 4 +end +if not demoaba +ret int 5 +end +n = write int 1 da ulong 0 len da +if ne n long len da +ret int 6 +end +ret int 0 +end diff --git a/om/quantity/fixtures/crypto-wrap.om b/om/quantity/fixtures/crypto-wrap.om new file mode 100644 index 0000000..5b8c7d3 --- /dev/null +++ b/om/quantity/fixtures/crypto-wrap.om @@ -0,0 +1,12 @@ +note Ordinary modular crypto words remain legal. This is arithmetic compatibility not crypto qualification. +fn main to int +word = add ulong 18446744073709551615 ulong 1 +if ne word ulong 0 +ret int 1 +end +word = mul ulong 18446744073709551615 ulong 2 +if ne word ulong 18446744073709551614 +ret int 2 +end +ret int 0 +end diff --git a/om/quantity/fixtures/mixed-object.om b/om/quantity/fixtures/mixed-object.om new file mode 100644 index 0000000..17b489e --- /dev/null +++ b/om/quantity/fixtures/mixed-object.om @@ -0,0 +1,7 @@ +note Nominal qobj is not a bounded qty even when its words fit. +fn main to int +out = new qty ulong 0 ulong 8 +a = new qobj ulong 1 ulong 0 ulong 8 +b = new qty ulong 1 ulong 8 +ret qadd out a b +end diff --git a/om/quantity/fixtures/mixed-quantity.om b/om/quantity/fixtures/mixed-quantity.om new file mode 100644 index 0000000..f7dfe8c --- /dev/null +++ b/om/quantity/fixtures/mixed-quantity.om @@ -0,0 +1,8 @@ +note Compile after quantity.om; expected compiler error7 at scalar argument. +fn scalar raw ulong to ulong +ret raw +end +fn main to int +a = new qty ulong 1 ulong 9 +ret int scalar a +end diff --git a/om/quantity/fixtures/mixed-scalar.om b/om/quantity/fixtures/mixed-scalar.om new file mode 100644 index 0000000..ee99cff --- /dev/null +++ b/om/quantity/fixtures/mixed-scalar.om @@ -0,0 +1,7 @@ +note Compile after quantity.om; expected compiler error7 at qadd scalar argument. +fn main to int +out = new qty ulong 0 ulong 9 +a = new qty ulong 1 ulong 9 +raw = ulong 1 +ret qadd out a raw +end diff --git a/om/quantity/fixtures/mixed-slice.om b/om/quantity/fixtures/mixed-slice.om new file mode 100644 index 0000000..670728e --- /dev/null +++ b/om/quantity/fixtures/mixed-slice.om @@ -0,0 +1,7 @@ +note A previously formed slice is not a quantity operand. +fn main to int +out = new qty ulong 0 ulong 8 +a = new qslic ulong 1 ulong 0 ulong 0 ulong 1 +b = new qty ulong 1 ulong 8 +ret qadd out a b +end diff --git a/om/quantity/mutate.om b/om/quantity/mutate.om new file mode 100644 index 0000000..b2aaf33 --- /dev/null +++ b/om/quantity/mutate.om @@ -0,0 +1,95 @@ +note Test-only source transformer. stdin quantity.om, argument a or m; stdout one guard removed. +note Requires exactly one exact guard occurrence, bounded input, complete writes. Never production code. +global src uchar 16384 +text aguard "if gt get b val sub get a cap get a val\nret int 3\nend\n" +text mguard "if ne get a val ulong 0\nif gt get b val div get a cap get a val\nret int 3\nend\nend\n" + +fn match at ulong kind uchar to bool +if eq kind uchar 97 +for i ulong len aguard +if ne get src add at i get aguard i +ret bool 0 +end +end +else +for i ulong len mguard +if ne get src add at i get mguard i +ret bool 0 +end +end +end +ret bool 1 +end + +fn emit at ulong size ulong to bool +pos = ulong 0 +while lt pos size bound 16384 +n = write int 1 src add at pos sub size pos +if le n long 0 +ret bool 0 +end +pos = add pos ulong n +end +ret bool 1 +end + +fn load to long +size = ulong 0 +while lt size len src bound 16384 +n = read int 0 src size sub len src size +if lt n long 0 +ret long -1 +end +if eq n long 0 +ret long size +end +size = add size ulong n +end +ret long -1 +end + +fn main to int +arg = new uchar 1 uchar 0 +if ne argcnt long 2 +ret int 2 +end +n = argread ulong 1 arg ulong 0 ulong 1 +if ne n long 1 +ret int 2 +end +kind = get arg 0 +if and ne kind uchar 97 ne kind uchar 109 +ret int 2 +end +n = load +if lt n long 0 +ret int 3 +end +size = ulong n +width = len aguard +if eq kind uchar 109 +width = len mguard +end +if lt size width +ret int 4 +end +hits = ulong 0 +found = ulong 0 +for i ulong add sub size width ulong 1 +if match i kind +hits = add hits ulong 1 +found = i +end +end +if ne hits ulong 1 +ret int 4 +end +if not emit ulong 0 found +ret int 5 +end +found = add found width +if not emit found sub size found +ret int 5 +end +ret int 0 +end diff --git a/om/quantity/oracle-export.om b/om/quantity/oracle-export.om new file mode 100644 index 0000000..0f0d254 --- /dev/null +++ b/om/quantity/oracle-export.om @@ -0,0 +1,55 @@ +note Emit actual quantity outcomes for an independently implemented external oracle. +note Order width1..8, a0..cap, b0..cap, add/sub/mul. Record three LEu64: status,val,cap. +note Refusals retain sentinel17/19. No oracle arithmetic is used in this program. +global qxbuf uchar 24 +fn qxemit rc int out view qty to int +for k ulong 8 +put qxbuf k uchar and shr ulong rc mul k 8 255 +put qxbuf add k 8 uchar and shr get out val mul k 8 255 +put qxbuf add k 16 uchar and shr get out cap mul k 8 255 +end +p = ulong 0 +while lt p 24 +n = write 1 qxbuf p sub 24 p +if le n 0 +ret 2 +end +p = add p ulong n +end +ret 0 +end +fn main to int +out = new qty ulong 17 ulong 19 +a = new qty ulong 0 ulong 0 +b = new qty ulong 0 ulong 0 +for w ulong 8 +cap = sub shl ulong 1 add w 1 1 +for av ulong add cap 1 +for bv ulong add cap 1 +put a val av +put a cap cap +put b val bv +put b cap cap +put out val 17 +put out cap 19 +rc = qadd out a b +if ne qxemit rc out 0 +ret 2 +end +put out val 17 +put out cap 19 +rc = qsub out a b +if ne qxemit rc out 0 +ret 2 +end +put out val 17 +put out cap 19 +rc = qmul out a b +if ne qxemit rc out 0 +ret 2 +end +end +end +end +ret 0 +end diff --git a/om/quantity/quantity.om b/om/quantity/quantity.om new file mode 100644 index 0000000..4ba9453 --- /dev/null +++ b/om/quantity/quantity.om @@ -0,0 +1,142 @@ +note SC1-Q API and status contract frozen in README.md. Raw structs are trusted not sealed. +struct qty 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 + +fn qword out edit qty raw ulong cap ulong to int +if gt raw cap +ret int 3 +end +put out val raw +put out cap cap +ret int 0 +end + +fn qsigned out edit qty raw long cap ulong to int +if lt raw long 0 +ret int 2 +end +ret qword out ulong raw cap +end + +fn qvalid a view qty to int +if gt get a val get a cap +ret int 1 +end +ret int 0 +end + +fn qpair a view qty b view qty to int +if ne qvalid a int 0 +ret int 1 +end +if ne qvalid b int 0 +ret int 1 +end +if ne get a cap get b cap +ret int 2 +end +ret int 0 +end + +fn qadd out edit qty a view qty b view qty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +note Q1_ADD_GUARD mutation removes this check only. +if gt get b val sub get a cap get a val +ret int 3 +end +put out val add get a val get b val +put out cap get a cap +ret int 0 +end + +fn qsub out edit qty a view qty b view qty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +if gt get b val get a val +ret int 3 +end +put out val sub get a val get b val +put out cap get a cap +ret int 0 +end + +fn qmul out edit qty a view qty b view qty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +note Q4_MUL_GUARD mutation removes this check only. +if ne get a val ulong 0 +if gt get b val div get a cap get a val +ret int 3 +end +end +put out val mul get a val get b val +put out cap get a cap +ret int 0 +end + +fn qnarrow out edit qty a view qty cap ulong to int +rc = qvalid a +if ne rc int 0 +ret rc +end +if gt cap get a cap +ret int 2 +end +if gt get a val cap +ret int 3 +end +put out val get a val +put out cap cap +ret int 0 +end + +fn qnext out edit qty a view qty to int +rc = qvalid a +if ne rc int 0 +ret rc +end +if eq get a val get a cap +ret int 3 +end +put out val add get a val ulong 1 +put out cap get a cap +ret int 0 +end + +fn qtyslice out edit qslic off view qty count view qty expect view qobj current view qobj to int +if ne get expect ident get current ident +ret int 4 +end +if ne get expect ver get current ver +ret int 4 +end +if ne get expect extent get current extent +ret int 4 +end +rc = qpair off count +if ne rc int 0 +ret rc +end +if ne get off cap get current extent +ret int 2 +end +if gt get off val get current extent +ret int 3 +end +if gt get count val sub get current extent get off val +ret int 3 +end +put out ident get current ident +put out ver get current ver +put out off get off val +put out count get count val +ret int 0 +end diff --git a/om/quantity/test/run.sh b/om/quantity/test/run.sh new file mode 100755 index 0000000..d441da6 --- /dev/null +++ b/om/quantity/test/run.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# Bootstrap glue only; all test selection, controls and verdicts are Omega. +set -eu +root=$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd) +cd "$root" +omc=$(sh tools/omc.sh) +mkdir -p build/security3 +"$omc" < qualification/security3/run.om > build/security3/consumer-units +chmod +x build/security3/consumer-units +exec build/security3/consumer-units "$omc" --consumer-units diff --git a/om/quantity/tests.om b/om/quantity/tests.om new file mode 100644 index 0000000..2269bb2 --- /dev/null +++ b/om/quantity/tests.om @@ -0,0 +1,358 @@ +note Concatenate quantity.om then tests.om. Wider signed oracle has no quantity guard. +text tadd "FAIL Q1_ADD_GUARD\n" +text tmul "FAIL Q4_MUL_GUARD\n" +text tedge "FAIL Q3_Q5_Q6_Q9_EDGES\n" +text tslc "FAIL Q7_Q9_SLICE\n" +text texh "FAIL Q2_EXACT_ORACLE\n" +text tpass "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n" + +fn qsent out edit qty to void +put out val ulong 17 +put out cap ulong 19 +end + +fn qcheck out view qty rc int want int value ulong cap ulong to bool +if ne rc want +ret bool 0 +end +if ne get out val value +ret bool 0 +end +ret eq get out cap cap +end + +fn testadd to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 18446744073709551608 ulong 18446744073709551615 +b = new qty ulong 16 ulong 18446744073709551615 +if ne add get a val get b val ulong 8 +ret bool 0 +end +rc = qadd out a b +ret qcheck out rc int 3 ulong 17 ulong 19 +end + +fn testmul to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 18446744073709551615 ulong 18446744073709551615 +b = new qty ulong 2 ulong 18446744073709551615 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967296 +put b val ulong 4294967296 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967297 +put b val ulong 4294967297 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967295 +put b val ulong 4294967295 +rc = qmul out a b +if not qcheck out rc int 0 ulong 18446744065119617025 ulong 18446744073709551615 +ret bool 0 +end +qsent out +put a val ulong 0 +put b val ulong 18446744073709551615 +rc = qmul out a b +ret qcheck out rc int 0 ulong 0 ulong 18446744073709551615 +end + +fn edges to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 18446744073709551615 ulong 18446744073709551615 +b = new qty ulong 0 ulong 18446744073709551615 +rc = qnext out a +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qsigned out long -1 ulong 18446744073709551615 +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qword out ulong 1 ulong 0 +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 0 ulong 0 ulong 18446744073709551615 +ret bool 0 +end +qsent out +rc = qadd out a b +if not qcheck out rc int 0 ulong 18446744073709551615 ulong 18446744073709551615 +ret bool 0 +end +qsent out +rc = qsub out b a +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qsigned out long 9223372036854775807 ulong 18446744073709551615 +if not qcheck out rc int 0 ulong 9223372036854775807 ulong 18446744073709551615 +ret bool 0 +end +qsent out +put a val ulong 256 +rc = qnarrow out a ulong 255 +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 255 +rc = qnarrow out a ulong 255 +if not qcheck out rc int 0 ulong 255 ulong 255 +ret bool 0 +end +qsent out +put a cap ulong 255 +rc = qnarrow out a ulong 256 +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qadd out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qsub out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 256 +rc = qadd out a b +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qsub out b a +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qnarrow out a ulong 0 +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qnext out a +ret qcheck out rc int 1 ulong 17 ulong 19 +end + +fn sexpect out view qslic rc int want int to bool +if ne rc want +ret bool 0 +end +if ne get out ident ulong 91 +ret bool 0 +end +if ne get out ver ulong 92 +ret bool 0 +end +if ne get out off ulong 93 +ret bool 0 +end +ret eq get out count ulong 94 +end + +fn slices to bool +out = new qslic ulong 91 ulong 92 ulong 93 ulong 94 +off = new qty ulong 6 ulong 8 +count = new qty ulong 3 ulong 8 +expect = new qobj ulong 5 ulong 7 ulong 8 +current = new qobj ulong 5 ulong 7 ulong 8 +rc = qtyslice out off count expect current +if not sexpect out rc int 3 +ret bool 0 +end +put expect ver ulong 6 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect ver ulong 7 +put expect ident ulong 4 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect ident ulong 5 +put expect extent ulong 7 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect extent ulong 8 +put off cap ulong 9 +rc = qtyslice out off count expect current +if not sexpect out rc int 2 +ret bool 0 +end +put count cap ulong 9 +rc = qtyslice out off count expect current +if not sexpect out rc int 2 +ret bool 0 +end +put off val ulong 10 +rc = qtyslice out off count expect current +if not sexpect out rc int 1 +ret bool 0 +end +put off val ulong 6 +put off cap ulong 8 +put count cap ulong 8 +put count val ulong 2 +rc = qtyslice out off count expect current +if ne rc int 0 +ret bool 0 +end +if ne get out ident ulong 5 +ret bool 0 +end +if ne get out ver ulong 7 +ret bool 0 +end +if ne get out off ulong 6 +ret bool 0 +end +if ne get out count ulong 2 +ret bool 0 +end +put off val ulong 8 +put count val ulong 0 +rc = qtyslice out off count expect current +if ne rc int 0 +ret bool 0 +end +if ne get out off ulong 8 +ret bool 0 +end +if ne get out count ulong 0 +ret bool 0 +end +put off val ulong 0 +put off cap ulong 0 +put count cap ulong 0 +put current extent ulong 0 +put expect extent ulong 0 +rc = qtyslice out off count expect current +ret eq rc int 0 +end + +note Oracle uses signed 64-bit exact arithmetic only on operands0..255. +note Its results are at most65025; it neither uses nor repeats the guarded algorithms. +fn oracle out view qty rc int exact long cap ulong to bool +if or lt exact long 0 gt exact long cap +ret qcheck out rc int 3 ulong 17 ulong 19 +end +ret qcheck out rc int 0 ulong exact cap +end + +fn pairs cap ulong to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 0 cap +b = new qty ulong 0 cap +rc = int 0 +for x ulong add cap ulong 1 +put a val x +for y ulong add cap ulong 1 +put b val y +qsent out +rc = qadd out a b +if not oracle out rc add long x long y cap +ret bool 0 +end +qsent out +rc = qsub out a b +if not oracle out rc sub long x long y cap +ret bool 0 +end +qsent out +rc = qmul out a b +if not oracle out rc mul long x long y cap +ret bool 0 +end +end +end +ret bool 1 +end + +fn unary cap ulong to bool +out = new qty ulong 17 ulong 19 +a = new qty ulong 0 cap +rc = int 0 +for x ulong add cap ulong 1 +qsent out +rc = qword out x cap +if not qcheck out rc int 0 x cap +ret bool 0 +end +qsent out +rc = qsigned out long x cap +if not qcheck out rc int 0 x cap +ret bool 0 +end +qsent out +put a val x +rc = qnext out a +if not oracle out rc add long x long 1 cap +ret bool 0 +end +for y ulong add cap ulong 1 +qsent out +rc = qnarrow out a y +if not oracle out rc long x y +ret bool 0 +end +end +end +qsent out +rc = qword out add cap ulong 1 cap +ret qcheck out rc int 3 ulong 17 ulong 19 +end + +fn main to int +n = long 0 +if not testadd +n = write int 1 tadd ulong 0 len tadd +ret int sub n sub n long 1 +end +if not testmul +n = write int 1 tmul ulong 0 len tmul +ret int sub n sub n long 1 +end +if not edges +n = write int 1 tedge ulong 0 len tedge +ret int sub n sub n long 1 +end +if not slices +n = write int 1 tslc ulong 0 len tslc +ret int sub n sub n long 1 +end +if not unary ulong 0 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +for w ulong 8 +if not unary sub shl ulong 1 add w ulong 1 ulong 1 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +if not pairs sub shl ulong 1 add w ulong 1 ulong 1 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +end +n = write int 1 tpass ulong 0 len tpass +ret int sub n n +end From ee9f0bb31f5a9fc1117178fc6d223ca1fe3b79c4 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 26 Oct 2026 00:05:06 -0500 Subject: [PATCH 3/5] test(quantity): native contract test for the checked-quantity unit The unit arrived on security/3-store-quantity with a harness that compiled qualification/security3/run.om, a runner main does not have, so carrying the unit alone left om/quantity/test/run.sh unable to run. Replace that glue with a native driver: 21 contract cases in Omega, one result byte, 0 means every case passed. They pin what the store charge path relies on: qword cap admission and refusal with the output left unchanged, qsigned negative ingress, qadd fit/overflow/cap mismatch, qsub underflow and difference, qmul wrapping and zero operand, qnarrow widen/fit/value-too-big, qnext increment and exhaustion, qvalid and qpair, and the two store caps (65536 frame, 33554432 bytes). The full differential corpus for this unit stays where it was produced, Omega #771; this test guards the local contract, not that corpus. Evidence: sh om/quantity/test/run.sh -> PASS quantity, 21 contract cases. Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Drake Stapleton --- om/quantity/test/driver.om | 214 +++++++++++++++++++++++++++++++++++++ om/quantity/test/run.py | 27 +++++ om/quantity/test/run.sh | 9 +- 3 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 om/quantity/test/driver.om create mode 100755 om/quantity/test/run.py diff --git a/om/quantity/test/driver.om b/om/quantity/test/driver.om new file mode 100644 index 0000000..91d7bfe --- /dev/null +++ b/om/quantity/test/driver.om @@ -0,0 +1,214 @@ +note SPDX-License-Identifier: Apache-2.0 +note Native contract test for om/quantity: one result byte, 0 means every case passed, +note otherwise the number of the first case that failed. Refusals must leave the +note output struct unchanged, which is what the store's charging path relies on. +fn testresult code int to int +b = new uchar 65536 0 +put b 0 uchar code +r = write int 1 b ulong 0 ulong 1 +ret 0 +end +fn setq o edit qty v ulong c ulong to int +put o val v +put o cap c +ret 0 +end +fn main to int +out = new qty ulong 17 ulong 19 +a = new qty ulong 0 ulong 0 +b = new qty ulong 0 ulong 0 + +note 1: qword accepts an in-cap value and records value and cap. +r0 = setq out ulong 17 ulong 19 +rc = qword out ulong 5 ulong 7 +if ne rc int 0 +ret testresult 1 +end +if not and eq get out val ulong 5 eq get out cap ulong 7 +ret testresult 1 +end + +note 2: qword refuses above the cap with 3 and leaves the output unchanged. +r0 = setq out ulong 17 ulong 19 +rc = qword out ulong 8 ulong 7 +if ne rc int 3 +ret testresult 2 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret testresult 2 +end + +note 3: qword accepts the boundary value equal to the cap. +rc = qword out ulong 7 ulong 7 +if ne rc int 0 +ret testresult 3 +end + +note 4: qsigned refuses negative ingress with 2 and leaves the output unchanged. +r0 = setq out ulong 17 ulong 19 +rc = qsigned out long -1 ulong 7 +if ne rc int 2 +ret testresult 4 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret testresult 4 +end + +note 5: qsigned accepts a non-negative value. +rc = qsigned out long 5 ulong 7 +if ne rc int 0 +ret testresult 5 +end +if not and eq get out val ulong 5 eq get out cap ulong 7 +ret testresult 5 +end + +note 6: qadd sums equal-cap operands that fit. +r0 = setq a ulong 3 ulong 7 +r0 = setq b ulong 4 ulong 7 +r0 = setq out ulong 17 ulong 19 +rc = qadd out a b +if ne rc int 0 +ret testresult 6 +end +if not and eq get out val ulong 7 eq get out cap ulong 7 +ret testresult 6 +end + +note 7: qadd refuses overflow with 3 and leaves the output unchanged. +r0 = setq a ulong 7 ulong 7 +r0 = setq b ulong 1 ulong 7 +r0 = setq out ulong 17 ulong 19 +rc = qadd out a b +if ne rc int 3 +ret testresult 7 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret testresult 7 +end + +note 8: qadd refuses unequal caps with 2. +r0 = setq a ulong 3 ulong 7 +r0 = setq b ulong 1 ulong 8 +rc = qadd out a b +if ne rc int 2 +ret testresult 8 +end + +note 9: qsub refuses underflow with 3 and leaves the output unchanged. +r0 = setq a ulong 1 ulong 7 +r0 = setq b ulong 2 ulong 7 +r0 = setq out ulong 17 ulong 19 +rc = qsub out a b +if ne rc int 3 +ret testresult 9 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret testresult 9 +end + +note 10: qsub difference fits. +r0 = setq a ulong 5 ulong 7 +r0 = setq b ulong 2 ulong 7 +rc = qsub out a b +if ne rc int 0 +ret testresult 10 +end +if not and eq get out val ulong 3 eq get out cap ulong 7 +ret testresult 10 +end + +note 11: qmul refuses a wrapping product with 3. +r0 = setq a ulong 18446744073709551615 ulong 18446744073709551615 +r0 = setq b ulong 2 ulong 18446744073709551615 +rc = qmul out a b +if ne rc int 3 +ret testresult 11 +end + +note 12: qmul accepts a zero operand without dividing by zero. +r0 = setq a ulong 0 ulong 18446744073709551615 +r0 = setq b ulong 18446744073709551615 ulong 18446744073709551615 +rc = qmul out a b +if ne rc int 0 +ret testresult 12 +end +if ne get out val ulong 0 +ret testresult 12 +end + +note 13: qnarrow refuses a target cap above the source cap with 2. +r0 = setq a ulong 5 ulong 10 +r0 = setq out ulong 17 ulong 19 +rc = qnarrow out a ulong 20 +if ne rc int 2 +ret testresult 13 +end + +note 14: qnarrow refuses a value that does not fit the target cap with 3. +r0 = setq a ulong 9 ulong 10 +rc = qnarrow out a ulong 8 +if ne rc int 3 +ret testresult 14 +end + +note 15: qnarrow accepts a fitting value and records the narrower cap. +r0 = setq a ulong 5 ulong 10 +rc = qnarrow out a ulong 7 +if ne rc int 0 +ret testresult 15 +end +if not and eq get out val ulong 5 eq get out cap ulong 7 +ret testresult 15 +end + +note 16: qnext increments up to the cap. +r0 = setq a ulong 6 ulong 7 +rc = qnext out a +if ne rc int 0 +ret testresult 16 +end +if not and eq get out val ulong 7 eq get out cap ulong 7 +ret testresult 16 +end + +note 17: qnext refuses at exhaustion with 3 and leaves the output unchanged. +r0 = setq out ulong 17 ulong 19 +r0 = setq a ulong 7 ulong 7 +rc = qnext out a +if ne rc int 3 +ret testresult 17 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret testresult 17 +end + +note 18: qvalid refuses a value above its cap with 1. +r0 = setq a ulong 8 ulong 7 +rc = qvalid a +if ne rc int 1 +ret testresult 18 +end + +note 19: qpair refuses unequal caps with 2. +r0 = setq a ulong 1 ulong 7 +r0 = setq b ulong 1 ulong 8 +rc = qpair a b +if ne rc int 2 +ret testresult 19 +end + +note 20: the store's frame cap refuses one byte more than the 65536 buffer. +rc = qword out ulong 65537 ulong 65536 +if ne rc int 3 +ret testresult 20 +end + +note 21: the store's byte cap admits exactly 33554432. +rc = qword out ulong 33554432 ulong 33554432 +if ne rc int 0 +ret testresult 21 +end + +ret testresult 0 +end diff --git a/om/quantity/test/run.py b/om/quantity/test/run.py new file mode 100755 index 0000000..5967299 --- /dev/null +++ b/om/quantity/test/run.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +"""Native contract test for om/quantity. Python compiles and compares; the checks are Omega.""" +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[3] +UNIT = ROOT / "om/quantity" +OUT = ROOT / "build/quantity" +COMPILER = subprocess.check_output([str(ROOT / "tools/omc.sh")], text=True).strip() + +source = (UNIT / "quantity.om").read_text() + "\n" + (UNIT / "test/driver.om").read_text() +result = subprocess.run([COMPILER], input=source.encode(), capture_output=True) +if result.returncode: + OUT.mkdir(parents=True, exist_ok=True) + (OUT / "driver.om").write_text(source) + sys.exit(f"quantity: compile failed: {result.stderr.decode()}") +OUT.mkdir(parents=True, exist_ok=True) +binary = OUT / "driver" +binary.write_bytes(result.stdout) +binary.chmod(0o700) +run = subprocess.run([str(binary)], capture_output=True, timeout=120) +if run.returncode != 0: + sys.exit(f"quantity: driver exit {run.returncode}: {run.stderr.decode()}") +if run.stdout != bytes([0]): + sys.exit(f"quantity: contract case {run.stdout[0]} failed (0 means every case passed)") +print("PASS quantity: checked-quantity contract cases, refusal leaves output unchanged") diff --git a/om/quantity/test/run.sh b/om/quantity/test/run.sh index d441da6..71490ad 100755 --- a/om/quantity/test/run.sh +++ b/om/quantity/test/run.sh @@ -1,10 +1,5 @@ #!/bin/sh -# Bootstrap glue only; all test selection, controls and verdicts are Omega. +# Bootstrap glue only; every check and verdict is Omega. set -eu root=$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd) -cd "$root" -omc=$(sh tools/omc.sh) -mkdir -p build/security3 -"$omc" < qualification/security3/run.om > build/security3/consumer-units -chmod +x build/security3/consumer-units -exec build/security3/consumer-units "$omc" --consumer-units +exec python3 "$root/om/quantity/test/run.py" From 405b57454e58083a105346e1cc869673995f0a49 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 26 Oct 2026 00:07:53 -0500 Subject: [PATCH 4/5] fix(build): assemble the quantity unit before any unit that defines functions The store charge change calls qword, qadd and qnext, so tkad's source needs the quantity unit. Adding it after json did not compile: a struct declaration that follows a function definition is error 9, and the failure lands on the struct line, not on the call site. Smallest repro, compiler 734f0a39: quantity.om + main -> rc 0 blake2s.om + quantity.om -> line 203: error 9 (struct qty line) json.om + quantity.om -> line 802: error 9 (struct qty line) quantity.om + blake2s.om -> rc 0 The store unit's own test already compiles the quantity unit first (om/store/test/run.py builds QUANT + BASE + ... + pool + driver), which is the same ordering. Put the unit at the front of the tkad assembly. Evidence: sh tools/build-tkad.sh -> build/tkad (was line 5941 error 16 with the unit missing entirely, then line 5684 error 9 with it placed after json). Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Drake Stapleton --- tools/build-tkad.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build-tkad.sh b/tools/build-tkad.sh index e2d7a83..6819f07 100755 --- a/tools/build-tkad.sh +++ b/tools/build-tkad.sh @@ -7,7 +7,7 @@ omc=$(sh "$root/tools/omc.sh") out=${1:-"$root/build/tkad"} mkdir -p "$(dirname -- "$out")" src="$out.om" -cat "$root/om/blake2s/blake2s.om" "$root/om/sha512/sha512.om" \ +cat "$root/om/quantity/quantity.om" "$root/om/blake2s/blake2s.om" "$root/om/sha512/sha512.om" \ "$root/om/ed25519/ed25519.om" "$root/om/blake2b/blake2b.om" \ "$root/om/argon2/argon2.om" "$root/om/argon2/argon2pool.om" \ "$root/om/codec/codec.om" "$root/om/cbor/cbor.om" \ From c4dd257c3067c7a2b8748d4e39cde40aee09d3dc Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Mon, 26 Oct 2026 00:09:39 -0500 Subject: [PATCH 5/5] docs(store): state the base this slice actually lands on The note was written on security/3-store-quantity, whose base was security/3-consumer-enforcement at b571465 supplying om/quantity. The rebuild on main carries om/quantity itself (imported from Omega #771) and depends on nothing from that stack, so the note now says so. The neighbouring audit still matches main: cmd/tkad/socket.om bounds ds_ctl 3 at header byte 5 (`gt get h 5 1`) and takes ds_ctl 4 from header byte 4, which is the claim the note makes. No test reads this file. Co-Authored-By: Claude Fable 5.1 Co-Authored-By: Drake Stapleton --- qualification/security3-store/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qualification/security3-store/README.md b/qualification/security3-store/README.md index baf585a..abcd417 100644 --- a/qualification/security3-store/README.md +++ b/qualification/security3-store/README.md @@ -1,6 +1,7 @@ # SC1-Q durable framing charges -Base: `security/3-consumer-enforcement` at `b571465`, which supplies `om/quantity`. +Base: current `main`. This rebuild carries `om/quantity` itself (imported from Omega #771), +so nothing here depends on the old `security/3-consumer-enforcement` stack. This slice is the WORM-owned durable-state side of the SC1-Q row and touches no transport, revision or comparison function owned elsewhere.