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 / core / rsi / om / reuse-eval / ref.om

643 lines · 9823 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note ref.om: the evaluator's own reference of REUSE-1 profile R1 (docs/reuse/REUSE-1.md v1.0,
3note omega-mv d6edaad1, section 1), written from the contract text alone (no candidate code read).
4note Units before it: sha256 (omega-mv main om/sha256/sha256.om, unchanged). Prefix rf / RF.
5note
6note Use: put one request frame (op, p, p payload words) into RFRQ, call rfreq; the response is in
7note RFRS (0 status, 1 q, 2 r0, 3 r1, 4 route 0, rest 0) and rfreq returns the status.
8note Status rules (contract 1.3, 2, integrator clarification K2):
9note p > 7234 or unknown op: 4. p not matching its op: 4. BEGIN: p < 65 or p != 65 + n: 4,
10note n > 4096: 5, invalid PROG: 2, a value outside the domain: 3; a refused BEGIN keeps the
11note previous session. Ops 2..8 without a session: 6. STATS and END: 0, q 0 (END drops the
12note session). SET/INS/DEL/SWAP: 3 when an index is out of range, a value is outside the domain
13note or INS would make n > 4096. BATCH: m outside 1..1024: 3; item op outside 3..6 or a DEL item
14note with b != 0: 3; items judged in order on the state the earlier items leave; all or nothing.
15note PROGRAM: invalid PROG 2 first, then any state value outside the new domain 3.
16note Validity of one change depends only on n and the domain, so BATCH is validated by simulating n
17note over the items and applied only when every item is valid (nothing is written before that).
18note
19note Hashing: rfpdig hashes RFP (512 LE bytes) into RFPD; streams use a context slot 0..7:
20note rfhini slot, rfhabs slot n (RFHB[0..n), n <= 65536), rfhfin slot (-> RFHD). Digest word j =
21note bytes 8j..8j+7 read big endian (contract 1.1).
22
23global RFP ulong 64
24global RFQ ulong 64
25global RFN ulong 1
26global RFX ulong 4096
27global RFS ulong 1
28global RFR ulong 2
29global RFRQ ulong 7240
30global RFRS ulong 8
31global RFPD ulong 4
32global RFHB uchar 65536
33global RFHC uchar 832
34global RFHD ulong 4
35
36note ---- lane map, folds, transitions (contract 1.2) ----
37
38note one lane step: v < 2^wl, c < 2^wl, shifts c < wl
39fn rfop wl ulong op ulong c ulong v ulong to ulong
40m = sub shl ulong 1 wl 1
41if eq op 1
42ret and add v c m
43end
44if eq op 2
45ret and sub v c m
46end
47if eq op 3
48ret and mul v c m
49end
50if eq op 4
51ret and v c
52end
53if eq op 5
54ret or v c
55end
56if eq op 6
57ret xor v c
58end
59if eq op 7
60ret and shl v c m
61end
62ret shr v c
63end
64
65fn rflane x ulong to ulong
66wl = get RFP 2
67k = get RFP 4
68v = x
69for j ulong k
70o = get RFP add 5 mul j 2
71c = get RFP add 6 mul j 2
72v = rfop wl o c v
73end
74ret v
75end
76
77fn rfident f ulong to ulong
78if or eq f 3 eq f 6
79ret 18446744073709551615
80end
81ret 0
82end
83
84fn rffold f ulong a ulong b ulong to ulong
85if eq f 1
86ret add a b
87end
88if eq f 2
89ret xor a b
90end
91if eq f 3
92if lt b a
93ret b
94end
95ret a
96end
97if eq f 4
98if gt b a
99ret b
100end
101ret a
102end
103if eq f 5
104ret or a b
105end
106ret and a b
107end
108
109note delta(s, a): t of the lowest-numbered rule with rule.s = s and lo <= a <= hi, else s
110fn rfdelta s ulong a ulong to ulong
111r = get RFP 5
112for i ulong r
113w = get RFP add 22 i
114if eq and w 255 s
115lo = and shr w 8 255
116hi = and shr w 16 255
117if and le lo a le a hi
118ret shr w 24
119end
120end
121end
122ret s
123end
124
125fn rfagg to void
126n = get RFN 0
127f = get RFP 3
128acc = rfident f
129for i ulong n
130e = rflane get RFX i
131acc = rffold f acc e
132end
133put RFR 0 acc
134put RFR 1 n
135end
136
137fn rffsm to void
138n = get RFN 0
139q = get RFP 4
140sum = ulong 0
141for t ulong n
142q = rfdelta q get RFX t
143sum = add sum get RFP add 6 q
144end
145put RFR 0 q
146put RFR 1 sum
147end
148
149note the result of RFP over (RFN, RFX) into RFR
150fn rffull to void
151if eq get RFP 1 1
152rfagg
153ret
154end
155rffsm
156end
157
158fn rfshape to ulong
159if eq get RFP 1 2
160ret 1
161end
162s = ulong 0
163m = ulong 65536
164k = get RFP 4
165for j ulong k
166s = add s mul m get RFP add 5 mul j 2
167m = mul m 16
168end
169b = add get RFP 2 mul 256 get RFP 3
170ret add add b mul 4096 k s
171end
172
173note ---- program validation (contract 1.1), on the staging buffer RFQ ----
174
175fn rfvagg to int
176wl = get RFQ 2
177if and ne wl 8 ne wl 16
178ret 2
179end
180f = get RFQ 3
181if or lt f 1 gt f 6
182ret 2
183end
184k = get RFQ 4
185if or lt k 1 gt k 6
186ret 2
187end
188lim = shl ulong 1 wl
189for j ulong 6
190o = get RFQ add 5 mul j 2
191c = get RFQ add 6 mul j 2
192if lt j k
193if or lt o 1 gt o 8
194ret 2
195end
196if ge c lim
197ret 2
198end
199if and ge o 7 ge c wl
200ret 2
201end
202else
203if or ne o 0 ne c 0
204ret 2
205end
206end
207end
208for i ulong 47
209if ne get RFQ add i 17 0
210ret 2
211end
212end
213ret 0
214end
215
216note one FSM rule word, r < R: s < S, t < S, lo <= hi < A
217fn rfvrule w ulong s ulong a ulong to bool
218rs = and w 255
219lo = and shr w 8 255
220hi = and shr w 16 255
221t = shr w 24
222if or ge rs s ge t s
223ret false
224end
225if or gt lo hi ge hi a
226ret false
227end
228ret true
229end
230
231fn rfvfsm to int
232s = get RFQ 2
233a = get RFQ 3
234if or lt s 2 gt s 16
235ret 2
236end
237if or lt a 2 gt a 16
238ret 2
239end
240if ge get RFQ 4 s
241ret 2
242end
243r = get RFQ 5
244if or lt r 1 gt r 24
245ret 2
246end
247for i ulong 16
248l = get RFQ add 6 i
249if lt i s
250if gt l 255
251ret 2
252end
253else
254if ne l 0
255ret 2
256end
257end
258end
259for j ulong 24
260w = get RFQ add 22 j
261if lt j r
262if not rfvrule w s a
263ret 2
264end
265else
266if ne w 0
267ret 2
268end
269end
270end
271for k ulong 18
272if ne get RFQ add k 46 0
273ret 2
274end
275end
276ret 0
277end
278
279note 0 valid, 2 invalid (RFQ)
280fn rfvalid to int
281if ne get RFQ 0 3544411312749556050
282ret 2
283end
284fam = get RFQ 1
285if eq fam 1
286ret rfvagg
287end
288if eq fam 2
289ret rfvfsm
290end
291ret 2
292end
293
294note value domain of a valid program: AGG 2^wl, FSM A
295fn rfdomq to ulong
296if eq get RFQ 1 1
297ret shl ulong 1 get RFQ 2
298end
299ret get RFQ 3
300end
301
302fn rfdom to ulong
303if eq get RFP 1 1
304ret shl ulong 1 get RFP 2
305end
306ret get RFP 3
307end
308
309note ---- changes (contract 1.3) ----
310
311note validity of one change on a state of n values with domain d: 0 or 3
312fn rfchk op ulong a ulong b ulong n ulong d ulong to ulong
313if eq op 3
314if or ge a n ge b d
315ret 3
316end
317ret 0
318end
319if eq op 4
320if or gt a n ge b d
321ret 3
322end
323if ge n 4096
324ret 3
325end
326ret 0
327end
328if eq op 5
329if or ge a n ne b 0
330ret 3
331end
332ret 0
333end
334if eq op 6
335if or ge a n ge b n
336ret 3
337end
338ret 0
339end
340ret 3
341end
342
343note apply one already validated change to RFX, RFN
344fn rfdo op ulong a ulong b ulong to void
345n = get RFN 0
346if eq op 3
347put RFX a b
348ret
349end
350if eq op 4
351i = n
352while gt i a bound 4097
353put RFX i get RFX sub i 1
354i = sub i 1
355end
356put RFX a b
357put RFN 0 add n 1
358ret
359end
360if eq op 5
361j = a
362while lt add j 1 n bound 4097
363put RFX j get RFX add j 1
364j = add j 1
365end
366put RFN 0 sub n 1
367ret
368end
369t = get RFX a
370put RFX a get RFX b
371put RFX b t
372end
373
374note BATCH payload at RFRQ[2..]: m, then m triples; p already checked against 1 + 3m
375fn rfbatch to ulong
376m = get RFRQ 2
377if or lt m 1 gt m 1024
378ret 3
379end
380d = rfdom
381n = get RFN 0
382for i ulong m
383o = get RFRQ add 3 mul i 3
384a = get RFRQ add 4 mul i 3
385b = get RFRQ add 5 mul i 3
386if ne rfchk o a b n d 0
387ret 3
388end
389if eq o 4
390n = add n 1
391end
392if eq o 5
393n = sub n 1
394end
395end
396for j ulong m
397o2 = get RFRQ add 3 mul j 3
398a2 = get RFRQ add 4 mul j 3
399b2 = get RFRQ add 5 mul j 3
400rfdo o2 a2 b2
401end
402ret 0
403end
404
405note ---- requests (contract 2) ----
406
407fn rfbegin p ulong to ulong
408if lt p 65
409ret 4
410end
411n = get RFRQ 66
412if ne p add n 65
413ret 4
414end
415if gt n 4096
416ret 5
417end
418for i ulong 64
419put RFQ i get RFRQ add i 2
420end
421if ne rfvalid 0
422ret 2
423end
424d = rfdomq
425for j ulong n
426if ge get RFRQ add j 67 d
427ret 3
428end
429end
430for k ulong 64
431put RFP k get RFQ k
432end
433for t ulong n
434put RFX t get RFRQ add t 67
435end
436put RFN 0 n
437put RFS 0 1
438ret 0
439end
440
441fn rfprog to ulong
442for i ulong 64
443put RFQ i get RFRQ add i 2
444end
445if ne rfvalid 0
446ret 2
447end
448d = rfdomq
449n = get RFN 0
450for j ulong n
451if ge get RFX j d
452ret 3
453end
454end
455for k ulong 64
456put RFP k get RFQ k
457end
458ret 0
459end
460
461fn rfquery to ulong
462rffull
463put RFRS 1 3
464put RFRS 2 get RFR 0
465put RFRS 3 get RFR 1
466ret 0
467end
468
469note the expected payload length of op given the frame, or 7235 when it cannot match
470fn rfplen op ulong p ulong to ulong
471if or eq op 2 or eq op 9 eq op 10
472ret 0
473end
474if or eq op 3 or eq op 4 eq op 6
475ret 2
476end
477if eq op 5
478ret 1
479end
480if eq op 8
481ret 64
482end
483if eq op 7
484if lt p 1
485ret 7235
486end
487m = get RFRQ 2
488if gt m 2411
489ret 7235
490end
491ret add 1 mul 3 m
492end
493ret 7235
494end
495
496fn rfreq2 to ulong
497op = get RFRQ 0
498p = get RFRQ 1
499if gt p 7234
500ret 4
501end
502if or lt op 1 gt op 10
503ret 4
504end
505if eq op 1
506ret rfbegin p
507end
508if ne p rfplen op p
509ret 4
510end
511if eq op 9
512ret 0
513end
514if eq op 10
515put RFS 0 0
516ret 0
517end
518if eq get RFS 0 0
519ret 6
520end
521if eq op 2
522ret rfquery
523end
524if eq op 7
525ret rfbatch
526end
527if eq op 8
528ret rfprog
529end
530b = ulong 0
531if ne op 5
532b = get RFRQ 3
533end
534a = get RFRQ 2
535if ne rfchk op a b get RFN 0 rfdom 0
536ret 3
537end
538rfdo op a b
539ret 0
540end
541
542fn rfreq to int
543for i ulong 8
544put RFRS i 0
545end
546st = rfreq2
547put RFRS 0 st
548ret int st
549end
550
551fn rfreset to void
552put RFS 0 0
553put RFN 0 0
554end
555
556note ---- SHA-256 through omsha (sha256 unit) ----
557
558fn rfbswap x ulong to ulong
559r = ulong 0
560v = x
561for i ulong 8
562r = or shl r 8 and v 255
563v = shr v 8
564end
565ret r
566end
567
568fn rfhini slot ulong to void
569c = new uchar 104 0
570b = new uchar 4096 0
571w = new ulong 64 0
572b8 = new ulong 512 0
573omsha c b 0 0 w b8
574rfhst c slot
575end
576
577note context slot into c and back; RFHB[off..off+k) into b
578fn rfhld c edit uchar 104 slot ulong to void
579o = mul slot 104
580for i ulong 104
581put c i get RFHC add o i
582end
583end
584
585fn rfhst c edit uchar 104 slot ulong to void
586o = mul slot 104
587for i ulong 104
588put RFHC add o i get c i
589end
590end
591
592fn rfhcp b edit uchar 4096 off ulong k ulong to void
593for j ulong k
594put b j get RFHB add off j
595end
596end
597
598fn rfhabs slot ulong n ulong to void
599c = new uchar 104 0
600b = new uchar 4096 0
601w = new ulong 64 0
602b8 = new ulong 512 0
603rfhld c slot
604off = ulong 0
605while lt off n bound 17
606k = sub n off
607if gt k 4096
608k = 4096
609end
610rfhcp b off k
611omsha c b k 1 w b8
612off = add off k
613end
614rfhst c slot
615end
616
617fn rfhfin slot ulong to void
618c = new uchar 104 0
619b = new uchar 4096 0
620w = new ulong 64 0
621b8 = new ulong 512 0
622rfhld c slot
623omsha c b 0 2 w b8
624for j ulong 4
625put RFHD j rfbswap get w j
626end
627end
628
629note program digest of RFP into RFPD (uses slot 7 and RFHB[0..512))
630fn rfpdig to void
631for i ulong 64
632x = get RFP i
633for j ulong 8
634put RFHB add mul i 8 j uchar and shr x mul j 8 255
635end
636end
637rfhini 7
638rfhabs 7 512
639rfhfin 7
640for k ulong 4
641put RFPD k get RFHD k
642end
643end