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

115 lines · 6523 bytes Raw Blame History Rendered
1# blake3.om — BLAKE3 in seeded Omega
2
3`blake3.om` is a program-mode Omega port of `src/omega_blake3.c` (BLAKE3 default mode:
4unkeyed, 32-byte output, no derive-key). It hashes one file, or stdin when no argument is
5given, and prints 64 lowercase hex digits plus a newline — the same contract as
6`tools/zero-legacy/sha256.om` in aien-architecture-mv. Part of #726 and
7aien-dev/aien-architecture-mv#300 (zero-legacy migration).
8
9## Build
10
11```
12OMC=/path/to/seed/out/omc # born by: sh seed/omega-from-seed.sh
13$OMC < om/blake3/blake3.om > blake3 && chmod +x blake3
14./blake3 FILE # or: ./blake3 < FILE
15```
16
17Exit codes: 0 hash written; 65 input cannot be read (missing file, no permission,
18directory, read error); 66 input longer than 16 MiB (16,777,216 bytes is accepted,
1916,777,217 is refused). Messages go to stderr.
20
21Returned stdout write errors or zero-progress writes exit 74. Positive short writes
22resume at the next byte; returned negative results, including interrupted writes,
23fail closed. Signal termination (for example the default SIGPIPE action) is not
24reported as exit 74.
25
26Run the output-contract regression against a freshly compiled binary:
27
28```
29sh om/blake3/test-output.sh ./blake3
30```
31
32The fixture compares the complete empty-input digest, including its newline, and
33checks /dev/full and closed-stdout failures. Positive short writes and EINTR are not
34forced by this fixture. `bash tests/gates/run.sh om-units` compiles `blake3.om` with the
35seed-born omc and runs this fixture, so the om-units CI check covers it.
36
37Native run on the Spark (arm64 host, 2026-10-25), omc 734f0a39…6b61 built by
38`sh seed/omega-from-seed.sh`: this source (sha256 c7c96a26…a150) compiles to an
398,664-byte binary, sha256 f3e343d2…2dbd. `test-output.sh` exits 0 on it and 1 on the
40PR #732 binary (c51199a3…f77b), which exits 0 for /dev/full (ENOSPC) and closed
41stdout (EBADF). A forced positive short write (`ulimit -f 1`, SIGXFSZ ignored, 994-byte
42file opened for append) shows `write(1, …, 65) = 30` then `write(1, …+30, 35) = -1
43EFBIG` and exit 74. The 64-case corpus below, rerun against this binary with a fresh
44-O2 build of `src/omega_blake3.c` as oracle, gives 64/64, and the binary matches
45`tests/resolve/blake3_vectors.txt` 35/35.
46
47## Construction
48
49Same as the C: 1024-byte chunks of 64-byte blocks, CHUNK_START on a chunk's first block,
50CHUNK_END on its last, a binary tree of PARENT nodes merged eagerly with a chaining-value
51stack (64 rows of 8 words; 16 MiB needs at most 14 levels, the 54-deep bound of the
52reference holds trivially), ROOT on the single final compression. 32-bit words live in
53`ulong` cells and are masked with `4294967295` after every add; the 64-bit chunk counter is
54split into words 12 and 13 of the state. The message permutation runs 7 times per
55compression, as in the C.
56
57## Historical oracle and parity (PR #732)
58
59Oracle: `src/omega_blake3.c` compiled with gcc -O2 behind a 12-line C driver (file → hex,
60kept out of the tree). The driver was first checked against the official
61BLAKE3-team/BLAKE3 `test_vectors/test_vectors.json` (fetched 2026-10-24): all 35 cases
62match, and the file is identical to the repo's `tests/resolve/blake3_vectors.txt`.
63Two single-line mutants of the C (the B3M:root and B3M:merge tags) are caught by the
64vector set (35/35 and 16/35 vectors differ), so the corpus discriminates.
65
66The following corpus and hashes belong to the original source at commit
67`c2156c7069df619797a113582fa6ad658c3db999`, before the output-handling fix.
68They are not verification of the revised source or binary.
69
70Corpus run with omc 734f0a39…6b61, `blake3.om` sha256 79857ee8…baa3, output binary
71sha256 c51199a3…f77b (8,660 bytes). Every row compares the .om output byte for byte to
72the oracle (or the exit status where that is the contract).
73
74| Case | Count | Result |
75|---|---|---|
76| Official vectors, input byte i = i mod 251, lengths 0 1 2 3 4 5 6 7 8 63 64 65 127 128 129 1023 1024 1025 2048 2049 3072 3073 4096 4097 5120 5121 6144 6145 7168 7169 8192 8193 16384 31744 102400 | 35 | 35/35 identical |
77| Random files (getrandom), lengths 1048576 747415 857706 158155 834790 310298 179313 1010110 85785 92852 94544 571487 362064 1015847 785532 857018 943647 792807 210568 211540 | 20 | 20/20 identical |
78| stdin path (102400-byte vector, 1 MiB random) | 2 | 2/2 identical |
79| Capacity edge: 16,777,215 and 16,777,216 random bytes | 2 | 2/2 identical |
80| Over capacity: 16,777,217 zero bytes, file and stdin | 2 | exit 66 both |
81| Missing file, mode-000 file, directory | 3 | exit 65 all |
82| **Total** | **64** | **64/64** |
83
84Historical timing of the original PR #732 source on the Spark (arm64): 16 MiB in 0.33 s for the .om versus 0.05 s for the -O2 C.
85
86## Limits
87
88- Input is capped at 16 MiB (one `global uchar 16777216`, the largest array the language
89 allows); the C has no cap. Longer inputs exit 66 instead of hashing.
90- One-shot only: no incremental/streaming API, no keyed or derive-key modes, no extended
91 output — the C exposes none of these either.
92- A read error after some bytes were consumed exits 65 (the C driver has no such path to
93 compare against; the status is a definition, not a parity result).
94
95## In the product: `b3unit.om`
96
97`src/omega_blake3.c` no longer computes BLAKE3. `om/blake3/b3unit.om` is the same tree
98construction as one function-mode unit, entry `omb3`, bound through the omega-bridge native call
99ABI v1 (omega-bridge #8, #12) and generated with the SHA-256 unit into `src/omega_om_units.inc`
100(`om/units.sh`; one file because every binding defines the shared ABI runtime). The C file keeps
101only `omega_blake3_hash`, which cuts the input into 1024-byte chunks (ABI v1 arrays are fixed
102length): state is the caller's 448-word array (54-row chaining-value stack, depth, chunk count).
103Its only caller is `omega_receipt.c` (the aien-proof EvidenceReceiptV1 id).
104
105`om/blake3/parity/run.sh` (with `OMEGA_OMC`, `OMEGA_BRIDGE`): 35/35 official vectors and 1,000
106inputs (boundaries, random to 3 MiB) identical to the replaced C (`src/omega_blake3.c` @ 633a1735);
107the two mutants `make test-resolve` used to apply to the C (B3M:merge, B3M:root) are applied to
108`b3unit.om` and killed (16/35 and 35/35 vectors differ, as for the C). `blake3.om` stays the
109file/stdin program.
110
111## NOT_RUN
112
113- No GPU, no live-server, no `make test` run was needed or performed for this change.
114- The 54-deep parent-stack bound of the reference is not exercised (a 16 MiB cap reaches
115 depth 14); the stack has 64 rows and the loop bound is 64.