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 / apps / interplane-forge / server / state.om

629 lines · 14412 bytes Raw Blame History
1note forged server/state.om: the plain state line of a project (the repo home header and the explore,
2note profile and search rows), read from the Interplane receipts list: content/receipts/ledger.tsv on
3note the default branch (HEAD) of the site's own repository rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV, which
4note is on the allow-list. https://interplane.io/receipts/ publishes that list and its verify.sh walks it.
5note A project is "Checked: ran again on <date>" only when all of these hold:
6note the whole list verifies the way verify.sh checks it: it ends with a line feed, line n has 7 tab
7note fields, field 1 is n, field 6 is 64 lowercase hex (the evidence file name) and field 7 is
8note GENESIS on line 1, else the SHA-256 (lowercase hex) of line n-1 without its line feed;
9note it holds a BUILD record (a rebuild from source) and a SOURCE record with the same time and the
10note same writer (fields 2 and 4), among the neighbouring records with that time, whose text
11note (field 5) names rad:<the project's RID>;
12note that BUILD record's evidence file content/receipts/payload/<field 6>.txt in the same repository
13note hashes to field 6.
14note <date> is the day (field 2) of the newest such BUILD record. Anything else, a list that cannot be
15note read, is cut, or does not verify included, is "Unfinished: not checked yet". The label never
16note says more than the list shows; it is not a verdict on the project.
17note Call fpjload once per request before the rows or the header (it runs git and uses fxo).
18global fpjl uchar 16777216
19global fpjn ulong 1
20note fpjst: 1 the list was read and verifies, anything else: no project is shown as checked
21global fpjst ulong 1
22note per record r (0-based, record r is line r+1): start and end (the line feed) in fpjl, and the
23note evidence check of a BUILD record: 0 not yet, 1 the file hashes to its name, 2 it does not
24global fpjrs ulong 131072
25global fpjre ulong 131072
26global fpjev uchar 131072
27global fpjrn ulong 1
28note fpjfind result: the BUILD record, its commit prefix in its text (start, length; length 0 when the
29note text names none) and whether the project's head starts with that prefix
30global fpjb ulong 1
31global fpjca ulong 1
32global fpjcl ulong 1
33global fpjnew ulong 1
34const FPJNONE ulong 131072
35const FPJMAX ulong 131072
36note FPJLEN: the size of fpjl (the longest list read); FPJXO: the size of fxo (the longest evidence
37note file hashed). Named, not written as numbers, so no loop line here equals one that another
38note slice's mutant test edits by its text (collab/tests/bigstore.sh).
39const FPJLEN ulong 16777216
40const FPJXO ulong 16777216
41text tfpjsite "z399yKvnXcBQNkKoq86iBDgTvQ5QV"
42text tfpjcat "cat-file"
43text tfpjblob "blob"
44text tfpjled "HEAD:content/receipts/ledger.tsv"
45text tfpjpay "HEAD:content/receipts/payload/"
46text tfpjtxt ".txt"
47text tfpjgen "GENESIS"
48text tfpjbld "BUILD"
49text tfpjsrc "SOURCE"
50text tfpjrad "rad:"
51text tfpjfrom "from commit "
52text tfpjrurl "https://interplane.io/receipts/"
53text tfpjpurl "https://interplane.io/receipts/payload/"
54text tfpjok1 "<p class=\"state ok\"><b>Checked:</b> ran again on "
55text tfpjno1 "<p class=\"state no\"><b>Unfinished:</b> not checked yet</p>\n"
56text tfpjpx "</p>\n"
57text tfpjold " (an earlier version)"
58text tfpjnew1 "<p class=\"state-more\">That is the version shown here. <a href=\""
59text tfpjnew0 "<p class=\"state-more\">That was an earlier version: later changes are not checked yet. <a href=\""
60text tfpjm5 ".txt\">Read the receipt</a></p>\n"
61text tfpjn1 "<p class=\"state-more\">There is no published receipt of a rebuild from its source yet. <a href=\""
62text tfpjn2 "\">What a receipt is</a></p>\n"
63text tfpjm1 "Receipt "
64text tfpjm2 " of that list says: &#8220;"
65text tfpjm3 "&#8221; (<a href=\""
66text tfpjm6 ".txt\">its evidence file</a>)."
67text tfpjm7 "This project has no receipt in that list yet."
68note ---- reading and verifying the list
69note fpjsite: the allow-list index of the site repository, or fan when it is not listed
70fn fpjsite to ulong
71for i ulong get fan 0 bound FAMAX
72if eq get fail i len tfpjsite
73m = true
74for k ulong len tfpjsite
75if ne fridbyte i k get tfpjsite k
76m = false
77break
78end
79end
80if m
81ret i
82end
83end
84end
85ret get fan 0
86end
87fn fpjhex c uchar to bool
88if and ge c 48 le c 57
89ret true
90end
91ret and ge c 97 le c 102
92end
93fn fpjhx v ulong to uchar
94if lt v 10
95ret uchar add v 48
96end
97ret uchar add v 87
98end
99note fpjfs: start of field k (0-based) of record r; fpjfe: its end (the tab or the line feed)
100fn fpjfs r ulong k ulong to ulong
101p = get fpjrs r
102e = get fpjre r
103if eq k 0
104ret p
105end
106c = ulong 0
107while lt p e bound FPJLEN
108if eq get fpjl p 9
109c = add c 1
110if eq c k
111ret add p 1
112end
113end
114p = add p 1
115end
116ret e
117end
118fn fpjfe r ulong k ulong to ulong
119p = fpjfs r k
120e = get fpjre r
121while lt p e bound FPJLEN
122if eq get fpjl p 9
123ret p
124end
125p = add p 1
126end
127ret e
128end
129note fpjfeq: field k of record r is the text t
130fn fpjfeq r ulong k ulong t view uchar * to bool
131a = fpjfs r k
132if ne sub fpjfe r k a len t
133ret false
134end
135for i ulong len t bound 64
136if ne get fpjl add a i get t i
137ret false
138end
139end
140ret true
141end
142note fpjsame: field k of records r and q hold the same bytes
143fn fpjsame r ulong q ulong k ulong to bool
144a = fpjfs r k
145n = sub fpjfe r k a
146b = fpjfs q k
147if ne n sub fpjfe q k b
148ret false
149end
150for i ulong n bound FPJLEN
151if ne get fpjl add a i get fpjl add b i
152ret false
153end
154end
155ret true
156end
157note fpjrec: record r (line r+1) is well formed and links to the line before it
158fn fpjrec r ulong to bool
159s = get fpjrs r
160e = get fpjre r
161t = ulong 0
162for i ulong sub e s bound FPJLEN
163if eq get fpjl add s i 9
164t = add t 1
165end
166end
167if ne t 6
168ret false
169end
170note field 1: the decimal record number r+1
171a = fpjfs r 0
172b = fpjfe r 0
173if or eq a b gt sub b a 7
174ret false
175end
176v = ulong 0
177for i ulong sub b a bound 8
178c = get fpjl add a i
179if or lt c 48 gt c 57
180ret false
181end
182note verify.sh compares the number as text: "01" is not record 1
183if and eq i 0 eq c 48
184ret false
185end
186v = add mul v 10 ulong sub c 48
187end
188if ne v add r 1
189ret false
190end
191note field 2: YYYY-MM-DDTHH:MM:SSZ
192a = fpjfs r 1
193if ne sub fpjfe r 1 a 20
194ret false
195end
196for i ulong 20
197c = get fpjl add a i
198if or eq i 4 eq i 7
199if ne c 45
200ret false
201end
202continue
203end
204if eq i 10
205if ne c 84
206ret false
207end
208continue
209end
210if or eq i 13 eq i 16
211if ne c 58
212ret false
213end
214continue
215end
216if eq i 19
217if ne c 90
218ret false
219end
220continue
221end
222if or lt c 48 gt c 57
223ret false
224end
225end
226note field 6: the evidence file name, 64 lowercase hex
227a = fpjfs r 5
228if ne sub fpjfe r 5 a 64
229ret false
230end
231for i ulong 64
232if not fpjhex get fpjl add a i
233ret false
234end
235end
236note field 7: GENESIS first, else the SHA-256 of the line before
237a = fpjfs r 6
238if eq r 0
239ret fpjfeq r 6 tfpjgen
240end
241if ne sub fpjfe r 6 a 64
242ret false
243end
244ps = get fpjrs sub r 1
245fpjshl ps sub get fpjre sub r 1 ps
246ret fpjhexeq a
247end
248note ---- SHA-256 of a part of a global (a global cannot be an argument: omc error 19), copied
249note through a local buffer 64 KiB at a time; the digest goes to fpjh
250global fpjh uchar 32
251fn fpjshl s ulong n ulong to void
252c = new ulong 40 0
253b = new uchar 65536 0
254o = new uchar 32 0
255sha256_init c
256d = ulong 0
257while lt d n bound FPJLEN
258k = hmin sub n d 65536
259for j ulong k bound 65536
260put b j get fpjl add add s d j
261end
262sha256_update c view part b 0 k
263d = add d k
264end
265sha256_final c o
266for j ulong 32
267put fpjh j get o j
268end
269end
270fn fpjshx n ulong to void
271c = new ulong 40 0
272b = new uchar 65536 0
273o = new uchar 32 0
274sha256_init c
275d = ulong 0
276while lt d n bound FPJXO
277k = hmin sub n d 65536
278for j ulong k bound 65536
279put b j get fxo add d j
280end
281sha256_update c view part b 0 k
282d = add d k
283end
284sha256_final c o
285for j ulong 32
286put fpjh j get o j
287end
288end
289note fpjhexeq: fpjl[a, a+64) is fpjh in lowercase hex
290fn fpjhexeq a ulong to bool
291for i ulong 32
292v = ulong get fpjh i
293if ne get fpjl add a mul i 2 fpjhx shr v 4
294ret false
295end
296if ne get fpjl add a add mul i 2 1 fpjhx and v 15
297ret false
298end
299end
300ret true
301end
302note fpjload: read and verify the list. When it cannot (the site repository is not on the allow-list,
303note git fails, the list is longer than fxo, the exec buffer every forged read goes through, or it does
304note not verify), every project shows "Unfinished" and one line goes to the service log, so the cause
305note is seen; server/tests/readmefirst.sh alarms before the real list nears that size.
306text tfpjlg1 "forged: state: the receipts list was not read (site repository not listed, git failed, or the list is 16 MiB or longer); every project shows Unfinished\n"
307text tfpjlg2 "forged: state: the receipts list does not verify (record number, date, fingerprint or chain); every project shows Unfinished\n"
308fn fpjload to void
309put fpjb 0 FPJNONE
310put fpjst 0 0
311put fpjrn 0 0
312put fpjn 0 0
313if fpjread
314if fpjsplit
315put fpjst 0 1
316else
317flog tfpjlg2
318end
319else
320flog tfpjlg1
321end
322end
323fn fpjread to bool
324i = fpjsite
325if ge i get fan 0
326ret false
327end
328fkgiti i
329fka tfpjcat
330fka tfpjblob
331fka tfpjled
332st = fexec 5000000000
333if or ne st 0 ne get fxotr 0 0
334ret false
335end
336n = get fxol 0
337if or eq n 0 gt n len fpjl
338ret false
339end
340for k ulong n bound FPJLEN
341put fpjl k get fxo k
342end
343put fpjn 0 n
344ret true
345end
346note fpjsplit: the records of fpjl, each checked; false at the first that does not verify. FPJMAX
347note holds more records than 16 MiB of them can be (a record is at least 157 bytes), so it is never
348note the limit.
349fn fpjsplit to bool
350n = get fpjn 0
351if ne get fpjl sub n 1 10
352ret false
353end
354s = ulong 0
355r = ulong 0
356p = ulong 0
357while lt p n bound FPJLEN
358if eq get fpjl p 10
359if ge r FPJMAX
360ret false
361end
362put fpjrs r s
363put fpjre r p
364put fpjev r 0
365if not fpjrec r
366ret false
367end
368r = add r 1
369s = add p 1
370end
371p = add p 1
372end
373put fpjrn 0 r
374ret true
375end
376note fpjev1: the evidence file of record r hashes to its name (cached per request in fpjev)
377fn fpjev1 r ulong to bool
378v = get fpjev r
379if ne v 0
380ret eq v 1
381end
382put fpjev r 2
383i = fpjsite
384if ge i get fan 0
385ret false
386end
387a = fpjfs r 5
388fkgiti i
389fka tfpjcat
390fka tfpjblob
391fka tfpjpay
392for k ulong 64
393fkc get fpjl add a k
394end
395fkt tfpjtxt
396st = fexec 5000000000
397if or ne st 0 ne get fxotr 0 0
398ret false
399end
400fpjshx get fxol 0
401if not fpjhexeq a
402ret false
403end
404put fpjev r 1
405ret true
406end
407note ---- one project
408note fpjnames: the text (field 5) of record q names rad:<RID of allow-list repo i>, not as a prefix
409note of a longer RID
410fn fpjnames q ulong i ulong to bool
411a = fpjfs q 4
412e = fpjfe q 4
413m = add len tfpjrad get fail i
414if lt sub e a m
415ret false
416end
417for s ulong add sub sub e a m 1 bound FPJLEN
418if fpjnat add a s e i
419ret true
420end
421end
422ret false
423end
424note fpjnat: fpjl[p, e) starts with "rad:<RID of repo i>" and no RID byte follows it
425fn fpjnat p ulong e ulong i ulong to bool
426for k ulong len tfpjrad
427if ne get fpjl add p k get tfpjrad k
428ret false
429end
430end
431r = add p len tfpjrad
432for k ulong get fail i bound 64
433if ne get fpjl add r k fridbyte i k
434ret false
435end
436end
437x = add r get fail i
438if ge x e
439ret true
440end
441ret not fpjalnum get fpjl x
442end
443fn fpjalnum c uchar to bool
444if and ge c 48 le c 57
445ret true
446end
447if and ge c 65 le c 90
448ret true
449end
450ret and ge c 97 le c 122
451end
452note fpjcommit: the hex run after "from commit " in the text of BUILD record b, into fpjca / fpjcl
453fn fpjcommit b ulong to void
454put fpjcl 0 0
455a = fpjfs b 4
456e = fpjfe b 4
457m = len tfpjfrom
458if lt sub e a m
459ret
460end
461for s ulong add sub sub e a m 1 bound FPJLEN
462if fpjfrat add a s
463fpjhexrun add add a s m e
464ret
465end
466end
467end
468fn fpjfrat p ulong to bool
469for k ulong len tfpjfrom
470if ne get fpjl add p k get tfpjfrom k
471ret false
472end
473end
474ret true
475end
476note fpjhexrun: the run of lowercase hex at fpjl[q, e), kept when it is 7 to 40 bytes long
477fn fpjhexrun q ulong e ulong to void
478n = ulong 0
479while and lt add q n e lt n 41 bound 42
480if not fpjhex get fpjl add q n
481break
482end
483n = add n 1
484end
485if and ge n 7 le n 40
486put fpjca 0 q
487put fpjcl 0 n
488end
489end
490note fpjfind: the newest BUILD record that checks project i (allow-list index) into fpjb; false when
491note there is none. Sets fpjnew: 1 when the project's head (falsh) starts with the commit the BUILD
492note record names, else 0. The SOURCE partner is looked for only in the run of neighbouring records
493note with the BUILD's time (field 2): a release's records are appended together, and this keeps the
494note cost to the list's length per project, not its square.
495fn fpjfind i ulong to bool
496put fpjb 0 FPJNONE
497put fpjnew 0 0
498if ne get fpjst 0 1
499ret false
500end
501n = get fpjrn 0
502for it ulong n bound FPJMAX
503b = sub sub n 1 it
504if fpjfeq b 2 tfpjbld
505if fpjpair b i
506if fpjev1 b
507put fpjb 0 b
508fpjcommit b
509fpjhead i
510ret true
511end
512end
513end
514end
515ret false
516end
517note fpjpair: a SOURCE record by the same writer, in the run of records with the time of BUILD record b,
518note names project i
519fn fpjpair b ulong i ulong to bool
520q = b
521while gt q 0 bound FPJMAX
522if not fpjsame sub q 1 b 1
523break
524end
525q = sub q 1
526end
527n = get fpjrn 0
528while lt q n bound FPJMAX
529if not fpjsame q b 1
530ret false
531end
532if fpjfeq q 2 tfpjsrc
533if fpjsame b q 3
534if fpjnames q i
535ret true
536end
537end
538end
539q = add q 1
540end
541ret false
542end
543fn fpjhead i ulong to void
544n = get fpjcl 0
545if or eq n 0 ne get falsl i 40
546ret
547end
548a = get fpjca 0
549o = mul i 40
550for k ulong n bound 40
551if ne get falsh add o k get fpjl add a k
552ret
553end
554end
555put fpjnew 0 1
556end
557note fpjdate: the day of record b (the first 10 bytes of field 2)
558fn fpjdate b ulong to void
559a = fpjfs b 1
560for k ulong 10
561fputc get fpjl add a k
562end
563end
564note fpjrow: the short state line of an explore, profile or search row (no line feed: a row is one line)
565text tfpjno2 "<p class=\"state no\"><b>Unfinished:</b> not checked yet</p>"
566text tfpjrx "</p>"
567fn fpjrow i ulong to void
568if not fpjfind i
569fput tfpjno2
570ret
571end
572b = get fpjb 0
573fput tfpjok1
574fpjdate b
575if eq get fpjnew 0 0
576fput tfpjold
577end
578fput tfpjrx
579end
580note fpjfull: the state lines of the project page header, with a link to the receipt
581fn fpjfull i ulong to void
582if not fpjfind i
583fput tfpjno1
584fput tfpjn1
585fput tfpjrurl
586fput tfpjn2
587ret
588end
589b = get fpjb 0
590fput tfpjok1
591fpjdate b
592fput tfpjpx
593if eq get fpjnew 0 1
594fput tfpjnew1
595else
596fput tfpjnew0
597end
598fpjpay b
599fput tfpjm5
600end
601fn fpjpay b ulong to void
602fput tfpjpurl
603a = fpjfs b 5
604for k ulong 64
605fputc get fpjl add a k
606end
607end
608note fpjrcpt: for the "For developers" section: the receipt the state comes from, quoted, after
609note fpjfull ran for this project (fpjb)
610fn fpjrcpt to void
611b = get fpjb 0
612if ge b get fpjrn 0
613fput tfpjm7
614ret
615end
616fput tfpjm1
617a = fpjfs b 0
618for k ulong sub fpjfe b 0 a bound 8
619fputc get fpjl add a k
620end
621fput tfpjm2
622a = fpjfs b 4
623for k ulong sub fpjfe b 4 a bound FPJLEN
624fescc get fpjl add a k
625end
626fput tfpjm3
627fpjpay b
628fput tfpjm6
629end