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 / seed / authority / action-gate.om

400 lines · 6889 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note OM-CONTROL-659 action contract v1. See ../README.md for the trusted-caller boundary.
3note No I/O, authority minting or persistence. Caller serializes and durably commits transitions.
4note Record words 0..7: version,state,attempt,limit,generation,epoch,expiry,reserved.
5note Words 8..31: operation,request,scope,provider,policy,grant identities, four words each.
6note State 1 ready,2 in-flight,3 unknown,4 performed. No timeout implies not performed.
7
8fn actvalid r view ulong 32 to ulong
9if ne get r 0 1
10ret 11
11end
12if or lt get r 1 1 gt get r 1 4
13ret 12
14end
15if or eq get r 3 0 gt get r 3 1024
16ret 12
17end
18if gt get r 2 get r 3
19ret 12
20end
21if and ne get r 1 1 eq get r 2 0
22ret 12
23end
24if or eq get r 4 0 eq get r 5 0
25ret 12
26end
27if or eq get r 6 0 ne get r 7 0
28ret 12
29end
30for g ulong 6
31bits = ulong 0
32for j ulong 4
33bits = or bits get r add 8 add mul g 4 j
34end
35if eq bits 0
36ret 12
37end
38end
39ret 0
40end
41
42fn actbind r view ulong 32 c view ulong 32 to ulong
43for g ulong 6
44diff = ulong 0
45for j ulong 4
46ix = add 8 add mul g 4 j
47diff = or diff xor get r ix get c ix
48end
49if ne diff 0
50ret add 40 g
51end
52end
53ret 0
54end
55
56fn actauth r view ulong 32 c view ulong 32 to ulong
57if ne get c 0 1
58ret 11
59end
60if or ne get c 3 0 or ne get c 6 0 ne get c 7 0
61ret 12
62end
63if ne get c 1 1
64ret 30
65end
66if ne get r 4 get c 4
67ret 31
68end
69if ne get r 5 get c 5
70ret 32
71end
72if ge get c 2 get r 6
73ret 33
74end
75ret actbind r c
76end
77
78fn actstart r edit ulong 32 c view ulong 32 to ulong
79err = actvalid r
80if ne err 0
81ret err
82end
83if eq get r 1 3
84ret 21
85end
86if eq get r 1 4
87ret 22
88end
89if ne get r 1 1
90ret 20
91end
92if ge get r 2 get r 3
93ret 23
94end
95err = actauth r c
96if ne err 0
97ret err
98end
99put r 2 add get r 2 1
100put r 1 2
101ret 0
102end
103
104fn actlost r edit ulong 32 to ulong
105err = actvalid r
106if ne err 0
107ret err
108end
109if eq get r 1 3
110ret 0
111end
112if ne get r 1 2
113ret 20
114end
115put r 1 3
116ret 0
117end
118
119note A trusted receipt maps outcome 0 unknown,1 definitely not performed,2 performed.
120note Not-found or timeout is outcome 0 unless the provider proves absence and quiescence.
121note Receipt words 2/3: exact attempt and verification=1. Words 6/7 must be zero.
122note Recording an observed outcome is permitted after expiry; another attempt is not.
123fn actrecon r edit ulong 32 s view ulong 32 to ulong
124err = actvalid r
125if ne err 0
126ret err
127end
128if not or eq get r 1 2 eq get r 1 3
129ret 20
130end
131if ne get s 0 1
132ret 11
133end
134if or gt get s 1 2 or ne get s 6 0 ne get s 7 0
135ret 12
136end
137if ne get s 3 1
138ret 36
139end
140if ne get s 2 get r 2
141ret 35
142end
143if ne get s 4 get r 4
144ret 31
145end
146if ne get s 5 get r 5
147ret 32
148end
149err = actbind r s
150if ne err 0
151ret err
152end
153if eq get s 1 0
154put r 1 3
155ret 21
156end
157if eq get s 1 1
158put r 1 1
159else
160put r 1 4
161end
162ret 0
163end
164note SPDX-License-Identifier: AGPL-3.0-only
165note Tests call the production transition functions. Provider/store I/O is not simulated as durable.
166global checks ulong 1
167global fails ulong 1
168global report uchar 64
169text title "action checks="
170
171fn check got ulong want ulong to void
172put checks 0 add get checks 0 1
173if ne got want
174put fails 0 add get fails 0 1
175end
176end
177
178fn plan r edit ulong 32 to void
179for i ulong 32
180put r i 0
181end
182put r 0 1
183put r 1 1
184put r 3 3
185put r 4 7
186put r 5 9
187put r 6 100
188for i ulong 24
189put r add i 8 add i 100
190end
191end
192
193fn context c edit ulong 32 to void
194for i ulong 32
195put c i 0
196end
197put c 0 1
198put c 1 1
199put c 2 50
200put c 4 7
201put c 5 9
202for i ulong 24
203put c add i 8 add i 100
204end
205end
206
207fn receipt s edit ulong 32 n ulong outcome ulong to void
208context s
209put s 1 outcome
210put s 2 n
211put s 3 1
212end
213
214fn summary to int
215for i ulong len title
216put report i get title i
217end
218n = get checks 0
219at = len title
220put report at uchar add 48 div n 100
221put report add at 1 uchar add 48 rem div n 10 10
222put report add at 2 uchar add 48 rem n 10
223put report add at 3 32
224put report add at 4 uchar add 48 div get fails 0 100
225put report add at 5 uchar add 48 rem div get fails 0 10 10
226put report add at 6 uchar add 48 rem get fails 0 10
227put report add at 7 10
228w = write 1 report 0 add at 8
229if ne w long add at 8
230ret 2
231end
232if ne get fails 0 0
233ret 1
234end
235ret 0
236end
237
238fn main to int
239r = new ulong 32 0
240c = new ulong 32 0
241s = new ulong 32 0
242plan r
243context c
244check actstart r c 0
245check get r 1 2
246check get r 2 1
247check actstart r c 20
248check get r 2 1
249check actlost r 0
250check get r 1 3
251check actlost r 0
252check actstart r c 21
253receipt s 1 0
254check actrecon r s 21
255check get r 1 3
256check actstart r c 21
257receipt s 1 2
258check actrecon r s 0
259check get r 1 4
260check actstart r c 22
261check actrecon r s 20
262
263note An observed uncertain outcome also moves an in-flight record to unknown.
264plan r
265check actstart r c 0
266receipt s 1 0
267check actrecon r s 21
268check get r 1 3
269check actstart r c 21
270
271note Confirmed not performed enables a new attempt only after a fresh admission check.
272plan r
273check actstart r c 0
274check actlost r 0
275receipt s 1 1
276check actrecon r s 0
277check get r 1 1
278check get r 2 1
279put c 1 0
280check actstart r c 30
281check get r 2 1
282context c
283put c 4 8
284check actstart r c 31
285context c
286put c 5 10
287check actstart r c 32
288context c
289put c 2 100
290check actstart r c 33
291context c
292check actstart r c 0
293check get r 2 2
294receipt s 1 2
295check actrecon r s 35
296check get r 1 2
297receipt s 2 2
298check actrecon r s 0
299check actstart r c 22
300
301note Every word of every identity is checked before mutating the record.
302for i ulong 24
303plan r
304context c
305put c add i 8 add get c add i 8 1
306check actstart r c add 40 div i 4
307check get r 1 1
308check get r 2 0
309end
310note Receipt binding includes all identities and cannot resolve a different attempt.
311for i ulong 24
312plan r
313context c
314check actstart r c 0
315receipt s 1 1
316put s add i 8 add get s add i 8 1
317check actrecon r s add 40 div i 4
318check get r 1 2
319end
320
321plan r
322context c
323put r 2 3
324check actstart r c 23
325put r 2 18446744073709551615
326check actstart r c 12
327check get r 2 18446744073709551615
328plan r
329put r 3 0
330check actstart r c 12
331plan r
332put r 3 1025
333check actstart r c 12
334plan r
335put r 7 1
336check actstart r c 12
337plan r
338put r 0 2
339check actstart r c 11
340plan r
341put r 1 99
342check actstart r c 12
343plan r
344put r 1 2
345check actstart r c 12
346plan r
347context c
348put c 0 2
349check actstart r c 11
350context c
351put c 1 2
352check actstart r c 30
353context c
354put c 3 1
355check actstart r c 12
356context c
357for group ulong 6
358plan r
359for j ulong 4
360put r add 8 add mul group 4 j 0
361end
362check actstart r c 12
363end
364
365plan r
366check actstart r c 0
367receipt s 1 1
368put s 3 0
369check actrecon r s 36
370check get r 1 2
371receipt s 1 1
372put s 4 8
373check actrecon r s 31
374receipt s 1 1
375put s 5 10
376check actrecon r s 32
377receipt s 1 3
378check actrecon r s 12
379receipt s 1 1
380put s 6 1
381check actrecon r s 12
382check actlost r 0
383check actstart r c 21
384receipt s 1 1
385check actrecon r s 0
386check actlost r 20
387check get r 1 1
388
389note Limit is enforced across reconciliation cycles, without rotating operation identity.
390plan r
391for i ulong 3
392check actstart r c 0
393receipt s add i 1 1
394check actrecon r s 0
395end
396check actstart r c 23
397check get r 2 3
398check get r 8 100
399ret summary
400end