interplane.Get Omega
Read in your language

spark-rsi-mv

Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger

Brought by drakestapleton

branch main Branches Tags History

spark-rsi-mv / om / governance / v2_main.om

428 lines · 8033 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/rsi/om/governance/v2_main.om
3note Standalone pure-Omega CLI for spark-rsi-mv Version 2 ECDSA P-256 promotion gate.
4note Compose with:
5note core/rsi/om/p256/sha256.om core/rsi/om/p256/p256.om
6note core/rsi/om/governance/receipt_v2.om core/rsi/om/governance/v2_main.om
7note Subcommands (argv[1]):
8note version print engine version and V2 domain tag
9note selfcheck run built-in P-256 V2 receipt sign/verify + fail-closed promotion check
10note verify read key=value V2 promotion bundle from stdin, output PROMOTE or REFUSE code=N
11
12text vm_ver "spark-rsi-gate-om 2.0 (domain=spark-rsi.evaluation-receipt.v2, p256=fips186-4)\n"
13text vm_usage "usage: rsi-v2-gate version|selfcheck|verify\n"
14text vm_prom "PROMOTE digest="
15text vm_ref "REFUSE code="
16text vm_nl "\n"
17text vm_cmd_ver "version"
18text vm_cmd_sc "selfcheck"
19text vm_cmd_vrf "verify"
20text vm_k_ver "format_version="
21text vm_k_htot "holdouts_total="
22text vm_k_hpas "holdouts_passed="
23text vm_k_adm "admitted="
24text vm_k_hard "hard_inv="
25text vm_k_stat "stat_gates="
26text vm_k_mbps "min_ratio_bps="
27text vm_k_cyc "cycle_id="
28text vm_k_cnd "candidate_id="
29text vm_k_par "parent_id="
30text vm_k_eat "evaluated_at="
31text vm_k_evv "evaluator_version="
32text vm_k_ebh "evaluator_binary_sha256="
33text vm_k_sp "subject_path="
34text vm_k_sh "subject_sha256="
35text vm_k_dh "disk_sha256="
36text vm_k_hh "holdout_set_sha256="
37text vm_k_ph "policy_sha256="
38text vm_k_jp "judge_pub_hex="
39text vm_k_op "own_pub_hex="
40text vm_k_sg "signature_hex="
41text vm_k_dg "receipt_digest="
42text vm_k_al "allowed_target="
43text vm_k_pr "protected_path="
44text vm_sc_cyc "selfcheck-cycle"
45text vm_sc_cnd "selfcheck-cand"
46text vm_sc_par "selfcheck-parent"
47text vm_sc_at "2026-11-21T00:00:00Z"
48text vm_sc_ev "2.0.0"
49text vm_sc_sp "README.md"
50
51global vm_arg uchar 64
52global vm_in uchar 16384
53
54fn vm_write_u64 v ulong to void
55buf = new uchar 24 0
56if eq v 0
57put buf 0 uchar 48
58r = write 1 buf 0 1
59ret
60end
61tmp = new uchar 24 0
62cnt = ulong 0
63x = v
64while gt x 0 bound 24
65put tmp cnt uchar add 48 rem x 10
66cnt = add cnt 1
67x = div x 10
68end
69for i ulong cnt bound 24
70put buf i get tmp sub sub cnt 1 i
71end
72r = write 1 buf 0 cnt
73end
74
75fn vm_hex_nib c uchar to ulong
76if and ge c uchar 48 le c uchar 57
77ret ulong sub c uchar 48
78end
79if and ge c uchar 97 le c uchar 102
80ret add 10 ulong sub c uchar 97
81end
82if and ge c uchar 65 le c uchar 70
83ret add 10 ulong sub c uchar 65
84end
85ret 255
86end
87
88fn vm_arg_eq n ulong which ulong to bool
89if eq which 0
90if ne n len vm_cmd_ver
91ret false
92end
93for i ulong n bound 64
94if ne get vm_arg i get vm_cmd_ver i
95ret false
96end
97end
98ret true
99end
100if eq which 1
101if ne n len vm_cmd_sc
102ret false
103end
104for i ulong n bound 64
105if ne get vm_arg i get vm_cmd_sc i
106ret false
107end
108end
109ret true
110end
111if ne n len vm_cmd_vrf
112ret false
113end
114for i ulong n bound 64
115if ne get vm_arg i get vm_cmd_vrf i
116ret false
117end
118end
119ret true
120end
121
122fn vm_selfcheck to int
123rv2_reset
124jpriv = new uchar 32 3
125opriv = new uchar 32 4
126jpub = new uchar 65 0
127opub = new uchar 65 0
128if ne rv2_p256_pubkey jpriv jpub 0
129ret 1
130end
131if ne rv2_p256_pubkey opriv opub 0
132ret 1
133end
134for i ulong 65
135put rv2_judge_pub i get jpub i
136put rv2_own_pub i get opub i
137end
138for i ulong 64
139put rv2_eval_bin_hex i uchar 97
140put rv2_subj_hex i uchar 98
141put rv2_sub_content_hex i uchar 98
142put rv2_sub_disk_hex i uchar 98
143put rv2_holdout_hex i uchar 99
144put rv2_pol_holdout_hex i uchar 99
145put rv2_policy_hex i uchar 100
146put rv2_pol_sha_hex i uchar 100
147end
148put rv2_meta 0 2
149put rv2_meta 1 1
150put rv2_meta 2 1
151put rv2_meta 3 1
152put rv2_meta 4 1
153put rv2_meta 5 1
154put rv2_meta 6 0
155put rv2_meta 7 0
156put rv2_meta 9 len vm_sc_cyc
157for i ulong len vm_sc_cyc bound 64
158put rv2_cycle i get vm_sc_cyc i
159end
160put rv2_meta 10 len vm_sc_cnd
161for i ulong len vm_sc_cnd bound 64
162put rv2_cand i get vm_sc_cnd i
163end
164put rv2_meta 11 len vm_sc_par
165put rv2_pol_meta 4 len vm_sc_par
166for i ulong len vm_sc_par bound 64
167put rv2_parent i get vm_sc_par i
168put rv2_sub_parent i get vm_sc_par i
169end
170put rv2_meta 12 len vm_sc_at
171for i ulong len vm_sc_at bound 64
172put rv2_eval_at i get vm_sc_at i
173end
174put rv2_meta 13 len vm_sc_ev
175for i ulong len vm_sc_ev bound 64
176put rv2_eval_ver i get vm_sc_ev i
177end
178put rv2_meta 14 len vm_sc_sp
179put rv2_pol_meta 5 len vm_sc_sp
180put rv2_pol_alen 0 len vm_sc_sp
181for i ulong len vm_sc_sp bound 64
182put rv2_subj_path i get vm_sc_sp i
183put rv2_sub_path i get vm_sc_sp i
184put rv2_pol_allowed i get vm_sc_sp i
185end
186put rv2_pol_meta 0 1
187put rv2_pol_meta 1 10000
188put rv2_pol_meta 2 1
189put rv2_pol_meta 3 0
190rv2_compute_digest
191dig = new uchar 32 0
192sig = new uchar 64 0
193for i ulong 32
194put rv2_claimed_dig i get rv2_comp_dig i
195put dig i get rv2_comp_dig i
196end
197if ne rv2_p256_sign jpriv dig sig 0
198ret 1
199end
200for i ulong 64
201put rv2_sig i get sig i
202end
203rc = rv2_check_promotion
204if ne rc RV2_OK
205r = write 1 vm_ref 0 len vm_ref
206vm_write_u64 rc
207r = write 1 vm_nl 0 len vm_nl
208ret 1
209end
210r = write 1 vm_prom 0 len vm_prom
211r = write 1 rv2_comp_hex 0 64
212r = write 1 vm_nl 0 len vm_nl
213ret 0
214end
215
216fn vm_parse_u64 s ulong e ulong to ulong
217if ge s e
218ret 0
219end
220acc = ulong 0
221i = s
222while lt i e bound 24
223c = get vm_in i
224if or lt c uchar 48 gt c uchar 57
225ret 0
226end
227acc = add mul acc 10 ulong sub c uchar 48
228i = add i 1
229end
230ret acc
231end
232
233fn vm_line_has s ulong e ulong kind ulong to ulong
234n = sub e s
235if eq kind 0
236kl = len vm_k_ver
237if lt n kl
238ret 0
239end
240for i ulong kl bound 32
241if ne get vm_in add s i get vm_k_ver i
242ret 0
243end
244end
245ret kl
246end
247if eq kind 1
248kl = len vm_k_htot
249if lt n kl
250ret 0
251end
252for i ulong kl bound 32
253if ne get vm_in add s i get vm_k_htot i
254ret 0
255end
256end
257ret kl
258end
259if eq kind 2
260kl = len vm_k_hpas
261if lt n kl
262ret 0
263end
264for i ulong kl bound 32
265if ne get vm_in add s i get vm_k_hpas i
266ret 0
267end
268end
269ret kl
270end
271if eq kind 3
272kl = len vm_k_adm
273if lt n kl
274ret 0
275end
276for i ulong kl bound 32
277if ne get vm_in add s i get vm_k_adm i
278ret 0
279end
280end
281ret kl
282end
283if eq kind 4
284kl = len vm_k_hard
285if lt n kl
286ret 0
287end
288for i ulong kl bound 32
289if ne get vm_in add s i get vm_k_hard i
290ret 0
291end
292end
293ret kl
294end
295if eq kind 5
296kl = len vm_k_stat
297if lt n kl
298ret 0
299end
300for i ulong kl bound 32
301if ne get vm_in add s i get vm_k_stat i
302ret 0
303end
304end
305ret kl
306end
307if eq kind 6
308kl = len vm_k_mbps
309if lt n kl
310ret 0
311end
312for i ulong kl bound 32
313if ne get vm_in add s i get vm_k_mbps i
314ret 0
315end
316end
317ret kl
318end
319ret 0
320end
321
322fn vm_verify_stdin to int
323rv2_reset
324put rv2_pol_meta 0 1
325put rv2_pol_meta 1 10000
326tot = ulong 0
327while lt tot 16384 bound 16384
328k = read 0 vm_in tot sub 16384 tot
329if le k 0
330break
331end
332tot = add tot ulong k
333end
334pos = ulong 0
335while lt pos tot bound 256
336ls = pos
337while lt pos tot bound 16384
338if eq get vm_in pos uchar 10
339break
340end
341pos = add pos 1
342end
343le_p = pos
344if lt pos tot
345pos = add pos 1
346end
347if gt le_p ls
348if eq get vm_in sub le_p 1 uchar 13
349le_p = sub le_p 1
350end
351end
352if eq le_p ls
353continue
354end
355kl = vm_line_has ls le_p 0
356if gt kl 0
357put rv2_meta 0 vm_parse_u64 add ls kl le_p
358continue
359end
360kl = vm_line_has ls le_p 1
361if gt kl 0
362put rv2_meta 1 vm_parse_u64 add ls kl le_p
363continue
364end
365kl = vm_line_has ls le_p 2
366if gt kl 0
367put rv2_meta 2 vm_parse_u64 add ls kl le_p
368continue
369end
370kl = vm_line_has ls le_p 3
371if gt kl 0
372put rv2_meta 3 vm_parse_u64 add ls kl le_p
373continue
374end
375kl = vm_line_has ls le_p 4
376if gt kl 0
377put rv2_meta 4 vm_parse_u64 add ls kl le_p
378continue
379end
380kl = vm_line_has ls le_p 5
381if gt kl 0
382put rv2_meta 5 vm_parse_u64 add ls kl le_p
383continue
384end
385kl = vm_line_has ls le_p 6
386if gt kl 0
387put rv2_pol_meta 1 vm_parse_u64 add ls kl le_p
388continue
389end
390end
391rc = rv2_check_promotion
392if eq rc RV2_OK
393r = write 1 vm_prom 0 len vm_prom
394r = write 1 rv2_comp_hex 0 64
395r = write 1 vm_nl 0 len vm_nl
396ret 0
397end
398r = write 1 vm_ref 0 len vm_ref
399vm_write_u64 rc
400r = write 1 vm_nl 0 len vm_nl
401ret 1
402end
403
404fn main to int
405ac = argcnt
406if lt ac 2
407r = write 2 vm_usage 0 len vm_usage
408ret 2
409end
410n = argread 1 vm_arg 0 64
411if le n 0
412r = write 2 vm_usage 0 len vm_usage
413ret 2
414end
415un = ulong n
416if vm_arg_eq un 0
417r = write 1 vm_ver 0 len vm_ver
418ret 0
419end
420if vm_arg_eq un 1
421ret vm_selfcheck
422end
423if vm_arg_eq un 2
424ret vm_verify_stdin
425end
426r = write 2 vm_usage 0 len vm_usage
427ret 2
428end