interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / latent-payload / validator.om

268 lines · 4062 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note LTP0 pure admission-template validator. No main, effects or authority.
3note Compose after om2 debug and before pinned om/tls/sha2.om.
4fn lpbe64 a view uchar * off ulong to ulong
5v = ulong 0
6for i ulong 8
7v = or shl v 8 ulong get a add off i
8end
9ret v
10end
11fn lpbe32 a view uchar * off ulong to ulong
12v = ulong 0
13for i ulong 4
14v = or shl v 8 ulong get a add off i
15end
16ret v
17end
18fn lpeq a view uchar * c view uchar * off ulong n ulong to bool
19for i ulong n
20p = add off i
21if ne get a p get c p
22ret false
23end
24end
25ret true
26end
27fn lpnonzero a view uchar * off ulong n ulong to bool
28v = uchar 0
29for i ulong n
30v = or v get a add off i
31end
32ret ne v 0
33end
34fn lpenums a view uchar * to bool
35if or lt get a 5 1 gt get a 5 2
36ret false
37end
38if or ne get a 6 1 ne get a 7 1
39ret false
40end
41if or ne get a 14 1 ne get a 15 0
42ret false
43end
44if or lt get a 100 1 gt get a 100 3
45ret false
46end
47if gt get a 101 2
48ret false
49end
50if or lt get a 102 2 gt get a 102 3
51ret false
52end
53ret true
54end
55fn lpquant a view uchar * to bool
56scale = lpbe32 a 56
57zero = lpbe32 a 60
58if eq get a 10 1
59if or ne get a 12 1 ne get a 13 0
60ret false
61end
62ret and eq scale 0x3f800000 eq zero 0
63end
64if eq get a 10 2
65if or ne get a 12 5 ne get a 13 1
66ret false
67end
68if or eq scale 0 ge scale 0x7f800000
69ret false
70end
71ret or le zero 127 ge zero 0xffffff80
72end
73ret false
74end
75fn lpshape a view uchar * to bool
76rank = ulong get a 11
77srank = ulong get a 103
78if or lt rank 1 gt rank 4
79ret false
80end
81if or lt srank 1 gt srank 4
82ret false
83end
84for i ulong 4
85sdim = lpbe32 a add 112 mul i 4
86if lt i srank
87if eq sdim 0
88ret false
89end
90else
91if ne sdim 0
92ret false
93end
94end
95end
96width = ulong 1
97if eq get a 10 1
98width = 4
99end
100prod = ulong 1
101stride = width
102for k ulong 4
103i = sub 3 k
104dim = lpbe32 a add 24 mul i 4
105st = lpbe32 a add 40 mul i 4
106if ge i rank
107if or ne dim 0 ne st 0
108ret false
109end
110else
111if or eq dim 0 gt dim 4096
112ret false
113end
114if gt prod div ulong 4096 dim
115ret false
116end
117if ne st stride
118ret false
119end
120prod = mul prod dim
121stride = mul prod width
122end
123end
124ret eq prod lpbe32 a 20
125end
126fn lpsize a view uchar * to bool
127n = lpbe32 a 16
128cap = lpbe32 a 108
129if or eq n 0 gt n 4096
130ret false
131end
132if or eq cap 0 gt cap 4096
133ret false
134end
135if gt n cap
136ret false
137end
138if ne len a add 1024 n
139ret false
140end
141width = ulong 1
142if eq get a 10 1
143width = 4
144end
145ret eq n mul lpbe32 a 20 width
146end
147fn lpids a view uchar * to bool
148if or eq lpbe32 a 88 0 eq lpbe32 a 96 0
149ret false
150end
151if eq lpbe32 a 104 0
152ret false
153end
154for i ulong 2
155if not lpnonzero a add 128 mul i 16 16
156ret false
157end
158end
159for i ulong 18
160if not lpnonzero a add 160 mul i 32 32
161ret false
162end
163end
164for i ulong 2
165if not lpnonzero a add 736 mul i 16 16
166ret false
167end
168end
169for i ulong 3
170if not lpnonzero a add 768 mul i 32 32
171ret false
172end
173end
174ret true
175end
176fn lpfinite a view uchar * to bool
177if eq get a 10 1
178n = lpbe32 a 20
179for i ulong n
180bits = lpbe32 a add 1024 mul i 4
181if eq and bits 0x7f800000 0x7f800000
182ret false
183end
184end
185end
186ret true
187end
188fn lphash a view uchar * to bool
189state = new ulong 40 0
190digest = new uchar 32 0
191sha256_init state
192sha256_update state part a 0 992
193sha256_update state part a 1024 sub len a 1024
194sha256_final state digest
195for i ulong 32
196if ne get digest i get a add 992 i
197ret false
198end
199end
200ret true
201end
202fn lpvalid a view uchar * c view uchar * now ulong lastseq ulong to int
203if or lt len a 1024 gt len a 5120
204ret 10
205end
206if ne len c 1024
207ret 10
208end
209if ne lpbe32 a 0 0x4c545030
210ret 11
211end
212if or ne get a 4 0 ne get a 8 4
213ret 11
214end
215if ne get a 9 0
216ret 11
217end
218if not lpenums a
219ret 12
220end
221if not lpquant a
222ret 13
223end
224if not lpshape a
225ret 14
226end
227if not lpsize a
228ret 15
229end
230for i ulong 128
231if ne get a add 864 i 0
232ret 16
233end
234end
235if not lpids a
236ret 17
237end
238issued = lpbe64 a 64
239expiry = lpbe64 a 72
240if or eq issued 0 gt issued now
241ret 18
242end
243if or le expiry now le expiry issued
244ret 18
245end
246if gt expiry lpbe64 c 72
247ret 18
248end
249if le lpbe64 a 80 lastseq
250ret 19
251end
252if not lpeq a c 0 16
253ret 20
254end
255if not lpeq a c 24 40
256ret 20
257end
258if not lpeq a c 88 776
259ret 20
260end
261if not lpfinite a
262ret 21
263end
264if not lphash a
265ret 22
266end
267ret 0
268end