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 / si / architecture / verify / authority.om

275 lines · 6543 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note si/architecture/verify/authority.om: pure-Omega port of aien-architecture-mv
3note verification engine: ADR/plan authority validator, capability register verifier,
4note architectural layer & evidence immutability invariant checker.
5note Compose after si/directives/om2.om and om/tls/sha2.om.
6
7const ARCH_OK ulong 0
8const ARCH_ERR_BAD_ADR_ID ulong 1
9const ARCH_ERR_NOT_BINDING ulong 2
10const ARCH_ERR_CYCLE_SUPERSEDE ulong 3
11const ARCH_ERR_UNQUALIFIED_REL ulong 4
12const ARCH_ERR_BAD_SHA ulong 5
13const ARCH_ERR_EMULATOR_AS_HW ulong 6
14const ARCH_ERR_DIRTY_TREE ulong 7
15const ARCH_ERR_NON_OMEGA_NEW ulong 8
16const ARCH_ERR_LAYER_INVERSION ulong 9
17const ARCH_ERR_BAD_LAYER ulong 10
18const ARCH_ERR_EVIDENCE_MUTATION ulong 11
19const ARCH_ERR_MISSING_RECEIPT ulong 12
20const ARCH_ERR_BAD_STATUS ulong 13
21
22const AUTH_PROPOSED ulong 0
23const AUTH_ACCEPTED ulong 1
24const AUTH_SUPERSEDED ulong 2
25const AUTH_DEPRECATED ulong 3
26const AUTH_REJECTED ulong 4
27
28const CAP_PLANNED ulong 0
29const CAP_IMPLEMENTED ulong 1
30const CAP_VERIFIED ulong 2
31const CAP_QUALIFIED_HW ulong 3
32const CAP_BLOCKED ulong 4
33
34const HW_HOST_EMULATOR ulong 0
35const HW_GB10 ulong 1
36const HW_BARE_METAL ulong 2
37
38const LANG_OMEGA ulong 1
39const LANG_C_LEGACY ulong 2
40const LANG_RUST_LEGACY ulong 3
41
42const EV_OP_ADD ulong 1
43const EV_OP_MODIFY ulong 2
44const EV_OP_RENAME ulong 3
45const EV_OP_DELETE ulong 4
46
47const LAYER_SEED ulong 0
48const LAYER_AIENUX ulong 1
49const LAYER_GPU ulong 2
50const LAYER_BRIDGE ulong 3
51const LAYER_CORE ulong 4
52const LAYER_PROTOCOL ulong 5
53const LAYER_APPS ulong 6
54const LAYER_SI ulong 7
55
56text arch_adr_pfx "ADR-"
57
58note --- Basic helpers ---
59
60fn arch_write_all fd int buf view uchar * to bool
61n = len buf
62if eq n ulong 0
63ret true
64end
65if gt n ulong 1048576
66ret false
67end
68off = ulong 0
69while lt off n bound 1048576
70remn = sub n off
71k = write fd buf off remn
72if le k long 0
73ret false
74end
75off = add off ulong k
76end
77ret true
78end
79
80fn arch_put_u64_le dst edit uchar * pos ulong v ulong to ulong
81if gt add pos ulong 8 len dst
82ret pos
83end
84for i ulong 8
85sh = mul i ulong 8
86put dst add pos i uchar and shr v sh ulong 255
87end
88ret add pos ulong 8
89end
90
91fn arch_is_lower_hex s view uchar * expected_len ulong to bool
92if ne len s expected_len
93ret false
94end
95if gt expected_len ulong 128
96ret false
97end
98i = ulong 0
99while lt i expected_len bound 128
100b = get s i
101ok = false
102if and ge b uchar 48 le b uchar 57
103ok = true
104end
105if and ge b uchar 97 le b uchar 102
106ok = true
107end
108if not ok
109ret false
110end
111i = add i ulong 1
112end
113ret true
114end
115
116fn arch_digest_eq a view uchar 32 b view uchar 32 to bool
117for i ulong 32
118if ne get a i get b i
119ret false
120end
121end
122ret true
123end
124
125note --- ADR & Plan Authority Validator ---
126note Validates "ADR-NNNN" (exact 8 bytes, 4 ASCII digits, value in 1..9999). Returns number or -1.
127
128fn arch_parse_adr_id s view uchar * to long
129if ne len s ulong 8
130ret long -1
131end
132for i ulong 4
133if ne get s i get arch_adr_pfx i
134ret long -1
135end
136end
137acc = ulong 0
138for j ulong 4
139b = get s add ulong 4 j
140if or lt b uchar 48 gt b uchar 57
141ret long -1
142end
143acc = add mul acc ulong 10 sub ulong b ulong 48
144end
145if eq acc ulong 0
146ret long -1
147end
148ret long acc
149end
150
151note Validates ADR status & supersession invariants (no self/backward supersession cycles).
152fn arch_validate_adr adr_id view uchar * status ulong superseded_by ulong to ulong
153num = arch_parse_adr_id adr_id
154if lt num long 0
155ret ARCH_ERR_BAD_ADR_ID
156end
157if gt status AUTH_REJECTED
158ret ARCH_ERR_BAD_STATUS
159end
160if eq status AUTH_SUPERSEDED
161if le superseded_by ulong num
162ret ARCH_ERR_CYCLE_SUPERSEDE
163end
164else
165if ne superseded_by ulong 0
166ret ARCH_ERR_CYCLE_SUPERSEDE
167end
168end
169ret ARCH_OK
170end
171
172note Only ACCEPTED ADRs govern live implementation; PROPOSED/open PR is never binding or qualified.
173fn arch_adr_is_binding status ulong to bool
174ret eq status AUTH_ACCEPTED
175end
176
177fn arch_check_release_authority status ulong commit_sha view uchar * dirty bool to ulong
178if dirty
179ret ARCH_ERR_DIRTY_TREE
180end
181if not arch_is_lower_hex commit_sha ulong 40
182ret ARCH_ERR_BAD_SHA
183end
184if ne status AUTH_ACCEPTED
185ret ARCH_ERR_UNQUALIFIED_REL
186end
187ret ARCH_OK
188end
189
190note --- Capability Register Verifier ---
191note Enforces:
192note - Valid capability status & language rule (new capabilities must be pure Omega)
193note - Dirty tree refused
194note - VERIFIED / QUALIFIED_HW require valid 40-char commit SHA & 64-char receipt SHA-256
195note - QUALIFIED_HW refuses HW_HOST_EMULATOR (host/emulator pass != hardware qualification)
196
197fn arch_verify_cap_lang is_new bool lang_class ulong to ulong
198if is_new
199if ne lang_class LANG_OMEGA
200ret ARCH_ERR_NON_OMEGA_NEW
201end
202end
203ret ARCH_OK
204end
205
206fn arch_verify_cap_receipts cap_status ulong commit_sha view uchar * receipt_sha view uchar * to ulong
207if gt cap_status CAP_BLOCKED
208ret ARCH_ERR_BAD_STATUS
209end
210if or eq cap_status CAP_VERIFIED eq cap_status CAP_QUALIFIED_HW
211if not arch_is_lower_hex commit_sha ulong 40
212ret ARCH_ERR_BAD_SHA
213end
214if not arch_is_lower_hex receipt_sha ulong 64
215ret ARCH_ERR_MISSING_RECEIPT
216end
217end
218ret ARCH_OK
219end
220
221fn arch_verify_cap_hw cap_status ulong hw_target ulong dirty bool to ulong
222if gt cap_status CAP_BLOCKED
223ret ARCH_ERR_BAD_STATUS
224end
225if dirty
226ret ARCH_ERR_DIRTY_TREE
227end
228if eq cap_status CAP_QUALIFIED_HW
229if eq hw_target HW_HOST_EMULATOR
230ret ARCH_ERR_EMULATOR_AS_HW
231end
232if gt hw_target HW_BARE_METAL
233ret ARCH_ERR_EMULATOR_AS_HW
234end
235end
236ret ARCH_OK
237end
238
239note --- Architectural Layer Dependency & Evidence Immutability Invariants ---
240note Layer ordering: 0=seed < 1=aienux < 2=gpu < 3=bridge < 4=core < 5=protocol < 6=apps < 7=si
241note A layer may depend only on itself or lower layers (to_layer <= from_layer).
242
243fn arch_layer_dep_check from_layer ulong to_layer ulong to ulong
244if or gt from_layer LAYER_SI gt to_layer LAYER_SI
245ret ARCH_ERR_BAD_LAYER
246end
247if gt to_layer from_layer
248ret ARCH_ERR_LAYER_INVERSION
249end
250ret ARCH_OK
251end
252
253note Evidence tree is additions-only: MODIFY, RENAME, DELETE are forbidden.
254fn arch_evidence_op_check op ulong to ulong
255if eq op EV_OP_ADD
256ret ARCH_OK
257end
258ret ARCH_ERR_EVIDENCE_MUTATION
259end
260
261note Canonical SHA-256 digest of an authority record (adr_num, status, cap_status, commit_sha).
262fn arch_record_digest adr_num ulong status ulong cap_status ulong commit_sha view uchar * dst edit uchar 32 to void
263ctx = new ulong 40 0
264hdr = new uchar 24 0
265w1 = arch_put_u64_le hdr ulong 0 adr_num
266w2 = arch_put_u64_le hdr ulong 8 status
267w3 = arch_put_u64_le hdr ulong 16 cap_status
268if or ne w1 ulong 8 or ne w2 ulong 16 ne w3 ulong 24
269trap 8
270end
271sha256_init ctx
272sha256_update ctx hdr
273sha256_update ctx commit_sha
274sha256_final ctx dst
275end