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
omega-mv / seed / ng / gate_ir_v2.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/ng/gate_ir_v2.om: Standalone Pure-OM-2 Verification Gate for Stage 0 (ΩIR v2). |
| 3 | note Verifies: |
| 4 | note Stage 1: In-process ΩIR v1 backward-compatibility, v2 contract round-trip, canonical |
| 5 | note per-function SEMANTIC_ID determinism & sensitivity, and 9 malformed v2/tag refusals. |
| 6 | note Stage 2: Infix frontend contract parsing (@pure/@exact/@tol/@err/@deadline/@hard_deadline/@power) |
| 7 | note and 6 fail-closed negative controls (including @ operator regression guard). |
| 8 | note Stage 3: OMPK v1/v2 contract & purity propagation in sem_pack.om and 4 negative controls. |
| 9 | note Stage 4 (when invoked as `gate_ir_v2 NG NGCHECK SCRATCH`): Live subprocess end-to-end |
| 10 | note verification using the real compiled `ng` and `ngcheck` binaries: |
| 11 | note - v1 backward compatibility (front-ir, ngcheck, ir-copy, sem-id) |
| 12 | note - v2 contract round-trip & structural purity PASS (closed pure callees) |
| 13 | note - infix-vs-prefix bit-identical SEMANTIC_ID & ΩIR v2 bytes |
| 14 | note - OMPK v2 @ng pack + @ng realize + tampered/malformed refusals |
| 15 | note - 7 fail-closed structural purity refusals (host, global write, global read, |
| 16 | note impure callee, edit param, exit, signed chk.add) -> ngcheck exit 22 (EFFECT) |
| 17 | note - 7 fail-closed malformed v2 / front-end contract refusals -> exit 13 / 11 / 30 |
| 18 | note |
| 19 | note Link order (program mode, no om2 header — ir.om provides om2 at line 1): |
| 20 | note seed/ng/src/ir.om seed/ng/sha256.om seed/ng/target/target_desc.om |
| 21 | note seed/ng/pack/sem_pack.om seed/ng/infix/infix_front.om seed/ng/gate_ir_v2.om |
| 22 | |
| 23 | global gv_dig uchar 24 |
| 24 | global gv_chk ulong 1 |
| 25 | global gv_neg ulong 1 |
| 26 | global gv_cli_chk ulong 1 |
| 27 | global gv_cli_neg ulong 1 |
| 28 | |
| 29 | global gv_b1 uchar 65536 |
| 30 | global gv_b2 uchar 65536 |
| 31 | global gv_b3 uchar 65536 |
| 32 | global gv_h1 uchar 32 |
| 33 | global gv_h2 uchar 32 |
| 34 | global gv_h3 uchar 32 |
| 35 | |
| 36 | note Subprocess CLI state (Stage 4) |
| 37 | global gv_ngp uchar 2048 |
| 38 | global gv_ngl ulong 1 |
| 39 | global gv_ckp uchar 2048 |
| 40 | global gv_ckl ulong 1 |
| 41 | global gv_scp uchar 2048 |
| 42 | global gv_scl ulong 1 |
| 43 | global gv_pa uchar 4096 |
| 44 | global gv_pl ulong 1 |
| 45 | global gv_av uchar 8192 |
| 46 | global gv_an ulong 2 |
| 47 | global gv_st uchar 4 |
| 48 | global gv_io uchar 131072 |
| 49 | global gv_io2 uchar 131072 |
| 50 | global gv_io3 uchar 131072 |
| 51 | |
| 52 | text gv_m_hdr "=== OMEGA NG STAGE 0 (OIR v2) VERIFICATION GATE ===\n" |
| 53 | text gv_m_pass "GATE-IR-V2 PASS checks=" |
| 54 | text gv_m_neg " neg_controls=" |
| 55 | text gv_m_cli " cli_checks=" |
| 56 | text gv_m_cneg " cli_neg=" |
| 57 | text gv_m_nl "\n" |
| 58 | text gv_m_fail "GATE-IR-V2 FAIL check=" |
| 59 | |
| 60 | text gv_h_fi "@ng front-ir\n" |
| 61 | text gv_h_ic "@ng ir-copy\n" |
| 62 | text gv_h_op "@ng opt\n" |
| 63 | text gv_h_sd "@ng sem-id\n" |
| 64 | text gv_h_pk "@ng pack\n" |
| 65 | text gv_h_rl "@ng realize\n" |
| 66 | |
| 67 | text gv_f_in "/in.bin" |
| 68 | text gv_f_out "/out.bin" |
| 69 | text gv_f_err "/err.bin" |
| 70 | text gv_f_ir1 "/v1.ir" |
| 71 | text gv_f_ir2 "/v2.ir" |
| 72 | text gv_f_ir2b "/v2_ix.ir" |
| 73 | text gv_f_pk2 "/v2.ompk" |
| 74 | text gv_f_s1 "/sem_px.txt" |
| 75 | text gv_f_s2 "/sem_ix.txt" |
| 76 | |
| 77 | text gv_pfx_acc "ACCEPT " |
| 78 | text gv_pfx_rlz "NG-REALIZE PASS" |
| 79 | text gv_sub_c0 " pure=1 tier=1 err=0 deadline=500 hard=0 power=15000\n" |
| 80 | text gv_sub_c1 " pure=1 tier=2 err=128 deadline=250 hard=1 power=9000\n" |
| 81 | |
| 82 | note ---- Source Fixtures ---- |
| 83 | text gv_src_v1 "om2\nfn step x ulong to ulong\nret add mul x 3 7\nend\nfn main to int\nret int and step 5 255\nend\n" |
| 84 | |
| 85 | text gv_src_v2_px "om2\n@pure\n@exact\n@deadline 500\n@power 15000\nfn sq x ulong to ulong\nret mul x x\nend\n@pure\n@tol 128\n@hard_deadline 250\n@power 9000\nfn mix x ulong y ulong to ulong\nret add sq x mul y 3\nend\nfn main to int\nret int and mix 4 5 255\nend\n" |
| 86 | |
| 87 | note Infix equivalent with DIFFERENT local names (a, b vs x, y), comments, and DIFFERENT attr order! |
| 88 | text gv_src_v2_ix "om2\n// Pure exact squarer in infix NG\n@power(15000)\n@deadline(500)\n@exact\n@pure\nfn sq(a: ulong) -> ulong {\n return a * a\n}\n// Pure bounded-error caller with hard deadline\n@power(9000)\n@hard_deadline(250)\n@err(128)\n@tol\n@pure\nfn mix(a: ulong, b: ulong) -> ulong {\n return sq(a) + (b * 3)\n}\nfn main() -> int {\n return int(mix(4, 5) & 255)\n}\n" |
| 89 | |
| 90 | note Structural purity negative controls (impure functions marked @pure -> ngcheck MUST refuse exit 22) |
| 91 | text gv_neg_host "om2\ntext msg \"hi\"\n@pure\nfn bad_io to ulong\nw = write 1 msg 0 len msg\nret ulong w\nend\nfn main to int\nret int and bad_io 255\nend\n" |
| 92 | text gv_neg_gwr "om2\nglobal g_cell ulong 4\n@pure\nfn bad_gwr x ulong to ulong\nput g_cell 0 x\nret x\nend\nfn main to int\nret int and bad_gwr 9 255\nend\n" |
| 93 | text gv_neg_grd "om2\nglobal g_cell ulong 4\n@pure\nfn bad_grd to ulong\nret get g_cell 0\nend\nfn main to int\nret int and bad_grd 255\nend\n" |
| 94 | text gv_neg_cal "om2\nglobal g_cell ulong 4\nfn imp_helper x ulong to ulong\nput g_cell 0 x\nret x\nend\n@pure\nfn bad_call x ulong to ulong\nret imp_helper x\nend\nfn main to int\nret int and bad_call 3 255\nend\n" |
| 95 | text gv_neg_edt "om2\n@pure\nfn bad_edit a edit ulong 4 to ulong\nret 1\nend\nfn main to int\nb = new ulong 4 0\nret int and bad_edit b 255\nend\n" |
| 96 | text gv_neg_ext "om2\n@pure\nfn bad_exit x ulong to ulong\nif eq x 0\nexit 1\nend\nret x\nend\nfn main to int\nret int and bad_exit 1 255\nend\n" |
| 97 | text gv_neg_chk "om2\n@pure\nfn bad_signed a int b int to int\nret add a b\nend\nfn main to int\nret bad_signed 1 2\nend\n" |
| 98 | |
| 99 | note Front-end malformed contract negative controls |
| 100 | text gv_neg_fe1 "om2\n@exact\n@tol 10\nfn f x ulong to ulong\nret x\nend\nfn main to int\nret int and f 1 255\nend\n" |
| 101 | text gv_neg_fe2 "om2\nfn main to int\n@pure\nret 0\nend\n" |
| 102 | |
| 103 | note Infix negative controls |
| 104 | text gv_ix_n1 "om2\n@exact\n@tol(10)\nfn f(x: ulong) -> ulong { return x }\nfn main() -> int { return int(f(1) & 255) }\n" |
| 105 | text gv_ix_n2 "om2\n@exact\n@err(5)\nfn f(x: ulong) -> ulong { return x }\nfn main() -> int { return int(f(1) & 255) }\n" |
| 106 | text gv_ix_n3 "om2\n@hard_deadline\nfn f(x: ulong) -> ulong { return x }\nfn main() -> int { return int(f(1) & 255) }\n" |
| 107 | text gv_ix_n4 "om2\n@bogus_contract\nfn f(x: ulong) -> ulong { return x }\nfn main() -> int { return int(f(1) & 255) }\n" |
| 108 | text gv_ix_n5 "om2\n@pure\nglobal g: [ulong; 4];\nfn main() -> int { return 0 }\n" |
| 109 | text gv_ix_n6 "om2\nfn main() -> int {\n x = ulong(1) @ 2\n return int(x)\n}\n" |
| 110 | |
| 111 | fn gv_wrt s view uchar * to void |
| 112 | r = write 1 s 0 len s |
| 113 | end |
| 114 | |
| 115 | fn gv_num v ulong to void |
| 116 | x = v |
| 117 | p = ulong 24 |
| 118 | for i ulong 21 |
| 119 | p = sub p 1 |
| 120 | put gv_dig p uchar add 48 rem x 10 |
| 121 | x = div x 10 |
| 122 | if eq x 0 |
| 123 | r = write 1 gv_dig p sub 24 p |
| 124 | ret |
| 125 | end |
| 126 | end |
| 127 | end |
| 128 | |
| 129 | fn gv_fail code ulong to int |
| 130 | gv_wrt gv_m_fail |
| 131 | gv_num code |
| 132 | gv_wrt gv_m_nl |
| 133 | ret int code |
| 134 | end |
| 135 | |
| 136 | fn gv_add_chk n ulong to void |
| 137 | put gv_chk 0 add get gv_chk 0 n |
| 138 | end |
| 139 | |
| 140 | fn gv_add_neg to void |
| 141 | put gv_neg 0 add get gv_neg 0 1 |
| 142 | end |
| 143 | |
| 144 | note Load buf[0..n) into arena region 0 (payload) for ir_read |
| 145 | fn gv_load_in_b1 n ulong to void |
| 146 | if ne ar_need 0 add n 16 0 |
| 147 | ar_die |
| 148 | end |
| 149 | for i ulong n bound 65536 |
| 150 | ar_bp 0 i get gv_b1 i |
| 151 | end |
| 152 | put ar_inl 0 n |
| 153 | end |
| 154 | |
| 155 | fn gv_load_in_b2 n ulong to void |
| 156 | if ne ar_need 0 add n 16 0 |
| 157 | ar_die |
| 158 | end |
| 159 | for i ulong n bound 65536 |
| 160 | ar_bp 0 i get gv_b2 i |
| 161 | end |
| 162 | put ar_inl 0 n |
| 163 | end |
| 164 | |
| 165 | fn gv_hash_fn f uint dst ulong to bool |
| 166 | m = ir_wfn_sem f |
| 167 | if gt m len sh_dat |
| 168 | ret false |
| 169 | end |
| 170 | for i ulong m bound 65536 |
| 171 | put sh_dat i ar_bg 1 i |
| 172 | end |
| 173 | sh_all m |
| 174 | for i ulong 32 |
| 175 | b = get sh_dig i |
| 176 | if eq dst 1 |
| 177 | put gv_h1 i b |
| 178 | else |
| 179 | if eq dst 2 |
| 180 | put gv_h2 i b |
| 181 | else |
| 182 | put gv_h3 i b |
| 183 | end |
| 184 | end |
| 185 | end |
| 186 | ret true |
| 187 | end |
| 188 | |
| 189 | fn gv_heq a ulong b ulong to bool |
| 190 | for i ulong 32 |
| 191 | va = uchar 0 |
| 192 | vb = uchar 0 |
| 193 | if eq a 1 |
| 194 | va = get gv_h1 i |
| 195 | else |
| 196 | if eq a 2 |
| 197 | va = get gv_h2 i |
| 198 | else |
| 199 | va = get gv_h3 i |
| 200 | end |
| 201 | end |
| 202 | if eq b 1 |
| 203 | vb = get gv_h1 i |
| 204 | else |
| 205 | if eq b 2 |
| 206 | vb = get gv_h2 i |
| 207 | else |
| 208 | vb = get gv_h3 i |
| 209 | end |
| 210 | end |
| 211 | if ne va vb |
| 212 | ret false |
| 213 | end |
| 214 | end |
| 215 | ret true |
| 216 | end |
| 217 | |
| 218 | note Build a small v1 module (main -> 42) |
| 219 | fn gv_build_v1 to ulong |
| 220 | ir_init |
| 221 | f = ir_fnew 2 0 8 |
| 222 | b = ir_blk f |
| 223 | c42 = ir_res ir_op b 1 8 42 0 |
| 224 | o = ir_op b 63 0 0 2 |
| 225 | ir_set o 0 ir_ftok f |
| 226 | ir_set o 1 c42 |
| 227 | ret ir_wr |
| 228 | end |
| 229 | |
| 230 | note Build a v2 module: f0 (@pure @exact deadline=500 power=15000), |
| 231 | note f1 (@pure @tol err=128 hard_deadline=250 power=9000 calling f0), f2 (export main) |
| 232 | fn gv_build_v2 to ulong |
| 233 | ir_init |
| 234 | f0 = ir_fnew 0 0 5 |
| 235 | ir_fset_mode f0 1 1 0 |
| 236 | ir_fset_phys f0 0 500 15000 |
| 237 | p0 = ir_fpar f0 5 |
| 238 | b0 = ir_blk f0 |
| 239 | om = ir_op b0 12 5 0 2 |
| 240 | ir_set om 0 p0 |
| 241 | ir_set om 1 p0 |
| 242 | r0 = ir_op b0 63 0 0 2 |
| 243 | ir_set r0 0 ir_ftok f0 |
| 244 | ir_set r0 1 ir_res om |
| 245 | |
| 246 | f1 = ir_fnew 0 0 5 |
| 247 | ir_fset_mode f1 1 2 1 |
| 248 | ir_fset_phys f1 128 250 9000 |
| 249 | p1 = ir_fpar f1 5 |
| 250 | b1 = ir_blk f1 |
| 251 | oc = ir_op b1 64 5 0 3 |
| 252 | ir_set oc 0 ir_ftok f1 |
| 253 | ir_set oc 1 f0 |
| 254 | ir_set oc 2 p1 |
| 255 | r1 = ir_op b1 63 0 0 2 |
| 256 | ir_set r1 0 ir_otok oc |
| 257 | ir_set r1 1 ir_res oc |
| 258 | |
| 259 | fm = ir_fnew 2 0 8 |
| 260 | bm = ir_blk fm |
| 261 | c42 = ir_res ir_op bm 1 8 42 0 |
| 262 | rm = ir_op bm 63 0 0 2 |
| 263 | ir_set rm 0 ir_ftok fm |
| 264 | ir_set rm 1 c42 |
| 265 | ret ir_wr |
| 266 | end |
| 267 | |
| 268 | note ---- Stage 1: In-Process ΩIR v1 Compatibility, v2 Round-Trip, SEMANTIC_ID & Malformed Refusals ---- |
| 269 | |
| 270 | fn gv_stage1_ir to int |
| 271 | note 1a. v1 round-trip & version/tag check |
| 272 | n1 = gv_build_v1 |
| 273 | if or lt n1 32 gt n1 65536 |
| 274 | ret gv_fail 10 |
| 275 | end |
| 276 | for i ulong n1 bound 65536 |
| 277 | put gv_b1 i ar_bg 1 i |
| 278 | end |
| 279 | if or ne get gv_b1 7 9 ne get gv_b1 21 49 |
| 280 | ret gv_fail 11 |
| 281 | end |
| 282 | if not gv_hash_fn 1 1 |
| 283 | ret gv_fail 12 |
| 284 | end |
| 285 | gv_load_in_b1 n1 |
| 286 | if ne ir_read 0 n1 0 |
| 287 | ret gv_fail 13 |
| 288 | end |
| 289 | if ne ir_ver 9 |
| 290 | ret gv_fail 14 |
| 291 | end |
| 292 | n1b = ir_wr |
| 293 | if ne n1b n1 |
| 294 | ret gv_fail 15 |
| 295 | end |
| 296 | for i ulong n1 bound 65536 |
| 297 | if ne ar_bg 1 i get gv_b1 i |
| 298 | ret gv_fail 16 |
| 299 | end |
| 300 | end |
| 301 | |
| 302 | note 1b. v2 contract round-trip & version/tag check |
| 303 | n2 = gv_build_v2 |
| 304 | if or lt n2 100 gt n2 65536 |
| 305 | ret gv_fail 17 |
| 306 | end |
| 307 | for i ulong n2 bound 65536 |
| 308 | put gv_b2 i ar_bg 1 i |
| 309 | end |
| 310 | if or ne get gv_b2 7 10 ne get gv_b2 21 50 |
| 311 | ret gv_fail 18 |
| 312 | end |
| 313 | note Confirm v1 main (h1) == v2 default-zero-contract main (h2) SEMANTIC_ID! |
| 314 | if not gv_hash_fn 3 2 |
| 315 | ret gv_fail 19 |
| 316 | end |
| 317 | if not gv_heq 1 2 |
| 318 | ret gv_fail 20 |
| 319 | end |
| 320 | note Snapshot f0 SEMANTIC_ID (h1) |
| 321 | if not gv_hash_fn 1 1 |
| 322 | ret gv_fail 21 |
| 323 | end |
| 324 | gv_load_in_b2 n2 |
| 325 | if ne ir_read 0 n2 0 |
| 326 | ret gv_fail 22 |
| 327 | end |
| 328 | if ne ir_ver 10 |
| 329 | ret gv_fail 23 |
| 330 | end |
| 331 | if or ne ulong get i_fpur 1 1 ne ulong get i_fprc 1 1 |
| 332 | ret gv_fail 24 |
| 333 | end |
| 334 | if or ne ulong get i_fhd 1 0 ne get i_ferr 1 0 |
| 335 | ret gv_fail 25 |
| 336 | end |
| 337 | if or ne get i_fdl 1 500 ne get i_fpwr 1 15000 |
| 338 | ret gv_fail 26 |
| 339 | end |
| 340 | if or ne ulong get i_fpur 2 1 ne ulong get i_fprc 2 2 |
| 341 | ret gv_fail 27 |
| 342 | end |
| 343 | if or ne ulong get i_fhd 2 1 ne get i_ferr 2 128 |
| 344 | ret gv_fail 28 |
| 345 | end |
| 346 | if or ne get i_fdl 2 250 ne get i_fpwr 2 9000 |
| 347 | ret gv_fail 29 |
| 348 | end |
| 349 | if not gv_hash_fn 1 2 |
| 350 | ret gv_fail 30 |
| 351 | end |
| 352 | if not gv_heq 1 2 |
| 353 | ret gv_fail 31 |
| 354 | end |
| 355 | note Changing power_mw on f0 MUST change its SEMANTIC_ID! |
| 356 | ir_fset_phys 1 0 500 15001 |
| 357 | if not gv_hash_fn 1 3 |
| 358 | ret gv_fail 32 |
| 359 | end |
| 360 | if gv_heq 1 3 |
| 361 | ret gv_fail 33 |
| 362 | end |
| 363 | note Restore f0 contract and verify exact byte-for-byte v2 ir_wr round-trip |
| 364 | ir_fset_phys 1 0 500 15000 |
| 365 | n2b = ir_wr |
| 366 | if ne n2b n2 |
| 367 | ret gv_fail 34 |
| 368 | end |
| 369 | for i ulong n2 bound 65536 |
| 370 | if ne ar_bg 1 i get gv_b2 i |
| 371 | ret gv_fail 35 |
| 372 | end |
| 373 | end |
| 374 | gv_add_chk 16 |
| 375 | |
| 376 | note 1c. 9 fail-closed malformed v2 / tag mismatch negative controls on ir_read |
| 377 | note f0 contract starts at offset 50 in gv_b2: |
| 378 | note [50]=pur(1) [51]=prc(1) [52]=hd(0) [53]=rsv(0) [54..61]=err(0) [62..69]=dl(500) [70..77]=pwr(15000) |
| 379 | if or ne get gv_b2 50 1 ne get gv_b2 51 1 |
| 380 | ret gv_fail 36 |
| 381 | end |
| 382 | |
| 383 | note NC-IR1: purity_flag = 2 -> class 13 |
| 384 | gv_load_in_b2 n2 |
| 385 | ar_bp 0 50 2 |
| 386 | if ne ir_read 0 n2 13 |
| 387 | ret gv_fail 37 |
| 388 | end |
| 389 | gv_add_neg |
| 390 | |
| 391 | note NC-IR2: precision_tier = 3 -> class 13 |
| 392 | gv_load_in_b2 n2 |
| 393 | ar_bp 0 51 3 |
| 394 | if ne ir_read 0 n2 13 |
| 395 | ret gv_fail 38 |
| 396 | end |
| 397 | gv_add_neg |
| 398 | |
| 399 | note NC-IR3: hard_deadline = 2 -> class 13 |
| 400 | gv_load_in_b2 n2 |
| 401 | ar_bp 0 52 2 |
| 402 | if ne ir_read 0 n2 13 |
| 403 | ret gv_fail 39 |
| 404 | end |
| 405 | gv_add_neg |
| 406 | |
| 407 | note NC-IR4: reserved = 1 -> class 13 |
| 408 | gv_load_in_b2 n2 |
| 409 | ar_bp 0 53 1 |
| 410 | if ne ir_read 0 n2 13 |
| 411 | ret gv_fail 40 |
| 412 | end |
| 413 | gv_add_neg |
| 414 | |
| 415 | note NC-IR5: @exact (tier=1) with err_bound = 1 -> class 13 |
| 416 | gv_load_in_b2 n2 |
| 417 | ar_bp 0 54 1 |
| 418 | if ne ir_read 0 n2 13 |
| 419 | ret gv_fail 41 |
| 420 | end |
| 421 | gv_add_neg |
| 422 | |
| 423 | note NC-IR6: unspecified tier (0) with err_bound = 7 -> class 13 |
| 424 | gv_load_in_b2 n2 |
| 425 | ar_bp 0 51 0 |
| 426 | ar_bp 0 54 7 |
| 427 | if ne ir_read 0 n2 13 |
| 428 | ret gv_fail 42 |
| 429 | end |
| 430 | gv_add_neg |
| 431 | |
| 432 | note NC-IR7: hard_deadline = 1 with deadline_us = 0 -> class 13 |
| 433 | gv_load_in_b2 n2 |
| 434 | ar_bp 0 52 1 |
| 435 | for j ulong 8 |
| 436 | ar_bp 0 add 62 j 0 |
| 437 | end |
| 438 | if ne ir_read 0 n2 13 |
| 439 | ret gv_fail 43 |
| 440 | end |
| 441 | gv_add_neg |
| 442 | |
| 443 | note NC-IR8: version 10 with v1 tag ("omega.ng.ir.v1") -> class 11 |
| 444 | gv_load_in_b2 n2 |
| 445 | ar_bp 0 21 49 |
| 446 | if ne ir_read 0 n2 11 |
| 447 | ret gv_fail 44 |
| 448 | end |
| 449 | gv_add_neg |
| 450 | |
| 451 | note NC-IR9: version 9 with v2 tag ("omega.ng.ir.v2") -> class 11 |
| 452 | gv_load_in_b1 n1 |
| 453 | ar_bp 0 21 50 |
| 454 | if ne ir_read 0 n1 11 |
| 455 | ret gv_fail 45 |
| 456 | end |
| 457 | gv_add_neg |
| 458 | gv_add_chk 9 |
| 459 | ret 0 |
| 460 | end |
| 461 | |
| 462 | note ---- Stage 2: Infix Frontend Contract Parsing & 6 Negative Controls ---- |
| 463 | |
| 464 | fn gv_run_ix src view uchar * to ulong |
| 465 | n = len src |
| 466 | for i ulong n bound 65536 |
| 467 | put ix_src i get src i |
| 468 | end |
| 469 | put ix_slen 0 n |
| 470 | ret ix_lower |
| 471 | end |
| 472 | |
| 473 | fn gv_stage2_infix to int |
| 474 | if ne gv_run_ix gv_src_v2_ix IX_OK |
| 475 | ret gv_fail 50 |
| 476 | end |
| 477 | if lt get ix_olen 0 64 |
| 478 | ret gv_fail 51 |
| 479 | end |
| 480 | gv_add_chk 2 |
| 481 | |
| 482 | if eq gv_run_ix gv_ix_n1 IX_OK |
| 483 | ret gv_fail 52 |
| 484 | end |
| 485 | gv_add_neg |
| 486 | if eq gv_run_ix gv_ix_n2 IX_OK |
| 487 | ret gv_fail 53 |
| 488 | end |
| 489 | gv_add_neg |
| 490 | if eq gv_run_ix gv_ix_n3 IX_OK |
| 491 | ret gv_fail 54 |
| 492 | end |
| 493 | gv_add_neg |
| 494 | if eq gv_run_ix gv_ix_n4 IX_OK |
| 495 | ret gv_fail 55 |
| 496 | end |
| 497 | gv_add_neg |
| 498 | if eq gv_run_ix gv_ix_n5 IX_OK |
| 499 | ret gv_fail 56 |
| 500 | end |
| 501 | gv_add_neg |
| 502 | note Regression guard: bare `@` inside expression MUST remain IX_ERR_INVALID_OP (2)! |
| 503 | if ne gv_run_ix gv_ix_n6 IX_ERR_INVALID_OP |
| 504 | ret gv_fail 57 |
| 505 | end |
| 506 | gv_add_neg |
| 507 | gv_add_chk 6 |
| 508 | ret 0 |
| 509 | end |
| 510 | |
| 511 | note ---- Stage 3: OMPK v1/v2 Contract & Purity Propagation + 4 Negative Controls ---- |
| 512 | |
| 513 | fn gv_stage3_pack to int |
| 514 | tdInitAll |
| 515 | tdCacheInit |
| 516 | pk_reset_all |
| 517 | |
| 518 | note 3a. OMPK v1 backward compatibility |
| 519 | n1 = gv_build_v1 |
| 520 | pk_reset_builder |
| 521 | pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 |
| 522 | for i ulong n1 bound 4096 |
| 523 | rc = pk_ir_push ar_bg 1 i |
| 524 | if ne rc PK_OK |
| 525 | ret gv_fail 60 |
| 526 | end |
| 527 | end |
| 528 | if ne pk_pack PK_OK |
| 529 | ret gv_fail 61 |
| 530 | end |
| 531 | if or ne pk_get_ver 1 ne pk_verify PK_OK |
| 532 | ret gv_fail 62 |
| 533 | end |
| 534 | if or ne pk_get_purity 0 ne pk_get_deadline_us 0 |
| 535 | ret gv_fail 63 |
| 536 | end |
| 537 | |
| 538 | note 3b. OMPK v2 with contract + canonical per-function SEMANTIC_ID |
| 539 | n2 = gv_build_v2 |
| 540 | for i ulong n2 bound 4096 |
| 541 | put gv_b3 i ar_bg 1 i |
| 542 | end |
| 543 | if not gv_hash_fn 2 1 |
| 544 | ret gv_fail 64 |
| 545 | end |
| 546 | pk_reset_builder |
| 547 | pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 |
| 548 | pk_set_func_id_from_sh |
| 549 | pk_set_contract 1 2 1 128 250 9000 |
| 550 | for i ulong n2 bound 4096 |
| 551 | rc = pk_ir_push get gv_b3 i |
| 552 | if ne rc PK_OK |
| 553 | ret gv_fail 65 |
| 554 | end |
| 555 | end |
| 556 | if ne pk_pack PK_OK |
| 557 | ret gv_fail 66 |
| 558 | end |
| 559 | if ne pk_verify PK_OK |
| 560 | ret gv_fail 67 |
| 561 | end |
| 562 | if or ne pk_get_ver 2 ne pk_get_purity 1 |
| 563 | ret gv_fail 68 |
| 564 | end |
| 565 | if or ne pk_get_precision 2 ne pk_get_hard_dl 1 |
| 566 | ret gv_fail 69 |
| 567 | end |
| 568 | if or ne pk_get_err_bound 128 ne pk_get_deadline_us 250 |
| 569 | ret gv_fail 70 |
| 570 | end |
| 571 | if ne pk_get_power_mw 9000 |
| 572 | ret gv_fail 71 |
| 573 | end |
| 574 | if ne pk_store_put PK_OK |
| 575 | ret gv_fail 72 |
| 576 | end |
| 577 | sl = get pk_last_slot 0 |
| 578 | if ne pk_store_load sl PK_OK |
| 579 | ret gv_fail 73 |
| 580 | end |
| 581 | if or ne pk_verify PK_OK ne pk_get_power_mw 9000 |
| 582 | ret gv_fail 74 |
| 583 | end |
| 584 | xFeat = tdGet TID_X925 TDF_FEAT |
| 585 | if ne pk_realize_on_arrive TID_X925 xFeat 1 7 PK_OK |
| 586 | ret gv_fail 75 |
| 587 | end |
| 588 | gv_add_chk 12 |
| 589 | |
| 590 | note 3c. 4 fail-closed OMPK v2 negative controls |
| 591 | note NC-PK1: malformed contract at pack time (@exact + err=5) -> PK_ERR_CONTRACT (22) |
| 592 | pk_reset_builder |
| 593 | pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 |
| 594 | pk_set_contract 1 1 0 5 100 1000 |
| 595 | rc = pk_ir_push 97 |
| 596 | if ne pk_pack PK_ERR_CONTRACT |
| 597 | ret gv_fail 76 |
| 598 | end |
| 599 | gv_add_neg |
| 600 | |
| 601 | note NC-PK2: tamper purity_flag byte [128] = 3 -> PK_ERR_CONTRACT (22) |
| 602 | if ne pk_store_load sl PK_OK |
| 603 | ret gv_fail 77 |
| 604 | end |
| 605 | put pk_buf 128 uchar 3 |
| 606 | if ne pk_verify PK_ERR_CONTRACT |
| 607 | ret gv_fail 78 |
| 608 | end |
| 609 | gv_add_neg |
| 610 | |
| 611 | note NC-PK3: 1-bit tamper in OMPK v2 payload -> PK_ERR_DIGEST (13) |
| 612 | if ne pk_store_load sl PK_OK |
| 613 | ret gv_fail 79 |
| 614 | end |
| 615 | put pk_buf PK_V2_HDR_LEN xor get pk_buf PK_V2_HDR_LEN uchar 1 |
| 616 | if ne pk_verify PK_ERR_DIGEST |
| 617 | ret gv_fail 80 |
| 618 | end |
| 619 | gv_add_neg |
| 620 | |
| 621 | note NC-PK4: corrupt OMPK v2 ext tag [132] -> PK_ERR_VERSION (11) |
| 622 | if ne pk_store_load sl PK_OK |
| 623 | ret gv_fail 81 |
| 624 | end |
| 625 | put pk_buf 132 uchar 0 |
| 626 | if ne pk_verify PK_ERR_VERSION |
| 627 | ret gv_fail 82 |
| 628 | end |
| 629 | gv_add_neg |
| 630 | gv_add_chk 4 |
| 631 | ret 0 |
| 632 | end |
| 633 | |
| 634 | note ---- Stage 4: Live Subprocess End-to-End with Real `ng` and `ngcheck` ---- |
| 635 | |
| 636 | fn gv_spath suf view uchar * to void |
| 637 | n = get gv_scl 0 |
| 638 | for i ulong n bound 2048 |
| 639 | put gv_pa i get gv_scp i |
| 640 | end |
| 641 | m = len suf |
| 642 | for j ulong m bound 128 |
| 643 | put gv_pa add n j get suf j |
| 644 | end |
| 645 | put gv_pl 0 add n m |
| 646 | end |
| 647 | |
| 648 | fn gv_wfile suf view uchar * n ulong use2 bool to bool |
| 649 | gv_spath suf |
| 650 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 651 | if lt fd 0 |
| 652 | ret false |
| 653 | end |
| 654 | o = ulong 0 |
| 655 | while lt o n bound 131072 |
| 656 | k = long 0 |
| 657 | if use2 |
| 658 | k = write int fd gv_io2 o sub n o |
| 659 | else |
| 660 | k = write int fd gv_io o sub n o |
| 661 | end |
| 662 | if le k 0 |
| 663 | r = fclose int fd |
| 664 | ret false |
| 665 | end |
| 666 | o = add o ulong k |
| 667 | end |
| 668 | r = fclose int fd |
| 669 | ret true |
| 670 | end |
| 671 | |
| 672 | fn gv_rfile suf view uchar * dst ulong to long |
| 673 | gv_spath suf |
| 674 | fd = fopen gv_pa 0 get gv_pl 0 0 0 |
| 675 | if lt fd 0 |
| 676 | ret long -1 |
| 677 | end |
| 678 | n = ulong 0 |
| 679 | while lt n 131072 bound 2048 |
| 680 | k = long 0 |
| 681 | if eq dst 1 |
| 682 | k = read int fd gv_io n sub 131072 n |
| 683 | else |
| 684 | if eq dst 2 |
| 685 | k = read int fd gv_io2 n sub 131072 n |
| 686 | else |
| 687 | k = read int fd gv_io3 n sub 131072 n |
| 688 | end |
| 689 | end |
| 690 | if lt k 0 |
| 691 | r = fclose int fd |
| 692 | ret long -1 |
| 693 | end |
| 694 | if eq k 0 |
| 695 | r = fclose int fd |
| 696 | ret long n |
| 697 | end |
| 698 | n = add n ulong k |
| 699 | end |
| 700 | r = fclose int fd |
| 701 | ret long n |
| 702 | end |
| 703 | |
| 704 | fn gv_write_in_txt hdr view uchar * body view uchar * to bool |
| 705 | gv_spath gv_f_in |
| 706 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 707 | if lt fd 0 |
| 708 | ret false |
| 709 | end |
| 710 | if gt len hdr 0 |
| 711 | k1 = write int fd hdr 0 len hdr |
| 712 | if ne k1 long len hdr |
| 713 | r = fclose int fd |
| 714 | ret false |
| 715 | end |
| 716 | end |
| 717 | k2 = write int fd body 0 len body |
| 718 | r = fclose int fd |
| 719 | ret eq k2 long len body |
| 720 | end |
| 721 | |
| 722 | fn gv_write_in_ix hdr view uchar * to bool |
| 723 | gv_spath gv_f_in |
| 724 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 725 | if lt fd 0 |
| 726 | ret false |
| 727 | end |
| 728 | k1 = write int fd hdr 0 len hdr |
| 729 | if ne k1 long len hdr |
| 730 | r = fclose int fd |
| 731 | ret false |
| 732 | end |
| 733 | n = get ix_olen 0 |
| 734 | o = ulong 0 |
| 735 | while lt o n bound 524288 |
| 736 | k2 = write int fd ix_out o sub n o |
| 737 | if le k2 0 |
| 738 | r = fclose int fd |
| 739 | ret false |
| 740 | end |
| 741 | o = add o ulong k2 |
| 742 | end |
| 743 | r = fclose int fd |
| 744 | ret true |
| 745 | end |
| 746 | |
| 747 | fn gv_write_in_bin hdr view uchar * n ulong use2 bool to bool |
| 748 | gv_spath gv_f_in |
| 749 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 750 | if lt fd 0 |
| 751 | ret false |
| 752 | end |
| 753 | if gt len hdr 0 |
| 754 | k1 = write int fd hdr 0 len hdr |
| 755 | if ne k1 long len hdr |
| 756 | r = fclose int fd |
| 757 | ret false |
| 758 | end |
| 759 | end |
| 760 | o = ulong 0 |
| 761 | while lt o n bound 131072 |
| 762 | k2 = long 0 |
| 763 | if use2 |
| 764 | k2 = write int fd gv_io2 o sub n o |
| 765 | else |
| 766 | k2 = write int fd gv_io o sub n o |
| 767 | end |
| 768 | if le k2 0 |
| 769 | r = fclose int fd |
| 770 | ret false |
| 771 | end |
| 772 | o = add o ulong k2 |
| 773 | end |
| 774 | r = fclose int fd |
| 775 | ret true |
| 776 | end |
| 777 | |
| 778 | fn gv_exec useNg bool to ulong |
| 779 | put gv_av 0 1 |
| 780 | put gv_av 1 0 |
| 781 | if useNg |
| 782 | n = get gv_ngl 0 |
| 783 | put gv_av 2 uchar and n 255 |
| 784 | put gv_av 3 uchar shr n 8 |
| 785 | for i ulong n bound 2048 |
| 786 | put gv_av add 4 i get gv_ngp i |
| 787 | end |
| 788 | put gv_an 0 add 4 n |
| 789 | else |
| 790 | n = get gv_ckl 0 |
| 791 | put gv_av 2 uchar and n 255 |
| 792 | put gv_av 3 uchar shr n 8 |
| 793 | for i ulong n bound 2048 |
| 794 | put gv_av add 4 i get gv_ckp i |
| 795 | end |
| 796 | put gv_an 0 add 4 n |
| 797 | end |
| 798 | gv_spath gv_f_in |
| 799 | fi = fopen gv_pa 0 get gv_pl 0 0 0 |
| 800 | gv_spath gv_f_out |
| 801 | fo = fopen gv_pa 0 get gv_pl 0 577 420 |
| 802 | gv_spath gv_f_err |
| 803 | fe = fopen gv_pa 0 get gv_pl 0 577 420 |
| 804 | if or lt fi 0 or lt fo 0 lt fe 0 |
| 805 | ret 255 |
| 806 | end |
| 807 | pid = fork |
| 808 | if lt pid 0 |
| 809 | ret 254 |
| 810 | end |
| 811 | if eq pid 0 |
| 812 | r = dupfd int fi 0 0 |
| 813 | r = dupfd int fo 1 0 |
| 814 | r = dupfd int fe 2 0 |
| 815 | r = execprog gv_av 0 get gv_an 0 |
| 816 | exit 127 |
| 817 | end |
| 818 | r = fclose int fi |
| 819 | r = fclose int fo |
| 820 | r = fclose int fe |
| 821 | w = waitpid int pid gv_st 0 4 0 |
| 822 | if ne w pid |
| 823 | ret 253 |
| 824 | end |
| 825 | if ne get gv_st 0 0 |
| 826 | ret add 256 ulong get gv_st 0 |
| 827 | end |
| 828 | ret ulong get gv_st 1 |
| 829 | end |
| 830 | |
| 831 | fn gv_io_starts pfx view uchar * n ulong to bool |
| 832 | m = len pfx |
| 833 | if lt n m |
| 834 | ret false |
| 835 | end |
| 836 | for i ulong m bound 64 |
| 837 | if ne get gv_io i get pfx i |
| 838 | ret false |
| 839 | end |
| 840 | end |
| 841 | ret true |
| 842 | end |
| 843 | |
| 844 | fn gv_io_contains sub_s view uchar * n ulong to bool |
| 845 | m = len sub_s |
| 846 | if or eq m 0 lt n m |
| 847 | ret false |
| 848 | end |
| 849 | lim = add sub n m 1 |
| 850 | for i ulong lim bound 131072 |
| 851 | ok = true |
| 852 | for j ulong m bound 128 |
| 853 | if ne get gv_io add i j get sub_s j |
| 854 | ok = false |
| 855 | break |
| 856 | end |
| 857 | end |
| 858 | if ok |
| 859 | ret true |
| 860 | end |
| 861 | end |
| 862 | ret false |
| 863 | end |
| 864 | |
| 865 | fn gv_cli_v1_compat to int |
| 866 | note 1. Plain prefix .om -> @ng front-ir -> v1 (ver=9, omega.ng.ir.v1) -> ngcheck ACCEPT -> ir-copy exact -> sem-id OK |
| 867 | if not gv_write_in_txt gv_h_fi gv_src_v1 |
| 868 | ret gv_fail 100 |
| 869 | end |
| 870 | if ne gv_exec true 0 |
| 871 | ret gv_fail 101 |
| 872 | end |
| 873 | n1 = gv_rfile gv_f_out 1 |
| 874 | if lt n1 32 |
| 875 | ret gv_fail 102 |
| 876 | end |
| 877 | if or ne get gv_io 7 9 ne get gv_io 21 49 |
| 878 | ret gv_fail 103 |
| 879 | end |
| 880 | if not gv_wfile gv_f_ir1 ulong n1 false |
| 881 | ret gv_fail 104 |
| 882 | end |
| 883 | n1r = gv_rfile gv_f_ir1 2 |
| 884 | if not gv_write_in_bin gv_m_nl 0 true |
| 885 | ret gv_fail 105 |
| 886 | end |
| 887 | note Feed raw v1.ir to ngcheck (empty hdr -> write raw bytes) |
| 888 | gv_spath gv_f_in |
| 889 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 890 | if lt fd 0 |
| 891 | ret gv_fail 105 |
| 892 | end |
| 893 | kw = write int fd gv_io2 0 ulong n1r |
| 894 | rc0 = fclose int fd |
| 895 | if ne kw n1r |
| 896 | ret gv_fail 105 |
| 897 | end |
| 898 | if ne gv_exec false 0 |
| 899 | ret gv_fail 106 |
| 900 | end |
| 901 | an = gv_rfile gv_f_out 1 |
| 902 | if not gv_io_starts gv_pfx_acc ulong an |
| 903 | ret gv_fail 107 |
| 904 | end |
| 905 | if not gv_write_in_bin gv_h_ic ulong n1r true |
| 906 | ret gv_fail 108 |
| 907 | end |
| 908 | if ne gv_exec true 0 |
| 909 | ret gv_fail 109 |
| 910 | end |
| 911 | cn = gv_rfile gv_f_out 1 |
| 912 | if ne cn n1r |
| 913 | ret gv_fail 110 |
| 914 | end |
| 915 | for i ulong ulong cn bound 131072 |
| 916 | if ne get gv_io i get gv_io2 i |
| 917 | ret gv_fail 111 |
| 918 | end |
| 919 | end |
| 920 | if not gv_write_in_bin gv_h_sd ulong n1r true |
| 921 | ret gv_fail 112 |
| 922 | end |
| 923 | if ne gv_exec true 0 |
| 924 | ret gv_fail 113 |
| 925 | end |
| 926 | put gv_cli_chk 0 add get gv_cli_chk 0 5 |
| 927 | ret 0 |
| 928 | end |
| 929 | |
| 930 | fn gv_cli_v2_rt to int |
| 931 | note 2. Prefix v2 .om -> @ng front-ir -> v2 (ver=10, omega.ng.ir.v2) -> ngcheck ACCEPT -> ir-copy -> opt -> sem-id |
| 932 | if not gv_write_in_txt gv_h_fi gv_src_v2_px |
| 933 | ret gv_fail 120 |
| 934 | end |
| 935 | if ne gv_exec true 0 |
| 936 | ret gv_fail 121 |
| 937 | end |
| 938 | n2 = gv_rfile gv_f_out 1 |
| 939 | if lt n2 80 |
| 940 | ret gv_fail 122 |
| 941 | end |
| 942 | if or ne get gv_io 7 10 ne get gv_io 21 50 |
| 943 | ret gv_fail 123 |
| 944 | end |
| 945 | if not gv_wfile gv_f_ir2 ulong n2 false |
| 946 | ret gv_fail 124 |
| 947 | end |
| 948 | n2r = gv_rfile gv_f_ir2 2 |
| 949 | gv_spath gv_f_in |
| 950 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 951 | if lt fd 0 |
| 952 | ret gv_fail 125 |
| 953 | end |
| 954 | kw = write int fd gv_io2 0 ulong n2r |
| 955 | rc0 = fclose int fd |
| 956 | if ne gv_exec false 0 |
| 957 | ret gv_fail 126 |
| 958 | end |
| 959 | an = gv_rfile gv_f_out 1 |
| 960 | if not gv_io_starts gv_pfx_acc ulong an |
| 961 | ret gv_fail 127 |
| 962 | end |
| 963 | note @ng ir-copy byte-exact on v2 |
| 964 | if not gv_write_in_bin gv_h_ic ulong n2r true |
| 965 | ret gv_fail 128 |
| 966 | end |
| 967 | if ne gv_exec true 0 |
| 968 | ret gv_fail 129 |
| 969 | end |
| 970 | cn = gv_rfile gv_f_out 1 |
| 971 | if ne cn n2r |
| 972 | ret gv_fail 130 |
| 973 | end |
| 974 | for i ulong ulong cn bound 131072 |
| 975 | if ne get gv_io i get gv_io2 i |
| 976 | ret gv_fail 131 |
| 977 | end |
| 978 | end |
| 979 | ret 0 |
| 980 | end |
| 981 | |
| 982 | fn gv_cli_v2_opt_sem to int |
| 983 | n2r = gv_rfile gv_f_ir2 2 |
| 984 | if lt n2r 80 |
| 985 | ret gv_fail 132 |
| 986 | end |
| 987 | note @ng opt preserves v2 contracts and still passes ngcheck |
| 988 | if not gv_write_in_bin gv_h_op ulong n2r true |
| 989 | ret gv_fail 132 |
| 990 | end |
| 991 | if ne gv_exec true 0 |
| 992 | ret gv_fail 133 |
| 993 | end |
| 994 | on = gv_rfile gv_f_out 1 |
| 995 | if or lt on 80 ne get gv_io 7 10 |
| 996 | ret gv_fail 134 |
| 997 | end |
| 998 | gv_spath gv_f_in |
| 999 | fd2 = fopen gv_pa 0 get gv_pl 0 577 420 |
| 1000 | kw2 = write int fd2 gv_io 0 ulong on |
| 1001 | rc2 = fclose int fd2 |
| 1002 | if ne gv_exec false 0 |
| 1003 | ret gv_fail 135 |
| 1004 | end |
| 1005 | note @ng sem-id on prefix v2 -> verify exact contract tags & save to /sem_px.txt |
| 1006 | if not gv_write_in_bin gv_h_sd ulong n2r true |
| 1007 | ret gv_fail 136 |
| 1008 | end |
| 1009 | if ne gv_exec true 0 |
| 1010 | ret gv_fail 137 |
| 1011 | end |
| 1012 | s1n = gv_rfile gv_f_out 1 |
| 1013 | if lt s1n 140 |
| 1014 | ret gv_fail 138 |
| 1015 | end |
| 1016 | if not gv_io_contains gv_sub_c0 ulong s1n |
| 1017 | ret gv_fail 139 |
| 1018 | end |
| 1019 | if not gv_io_contains gv_sub_c1 ulong s1n |
| 1020 | ret gv_fail 140 |
| 1021 | end |
| 1022 | if not gv_wfile gv_f_s1 ulong s1n false |
| 1023 | ret gv_fail 141 |
| 1024 | end |
| 1025 | ret 0 |
| 1026 | end |
| 1027 | |
| 1028 | fn gv_cli_v2_infix to int |
| 1029 | note 3. Infix v2 .om -> ix_lower -> @ng front-ir -> ngcheck ACCEPT -> @ng sem-id -> BIT-IDENTICAL to prefix! |
| 1030 | n2r = gv_rfile gv_f_ir2 2 |
| 1031 | if ne gv_run_ix gv_src_v2_ix IX_OK |
| 1032 | ret gv_fail 142 |
| 1033 | end |
| 1034 | if not gv_write_in_ix gv_h_fi |
| 1035 | ret gv_fail 143 |
| 1036 | end |
| 1037 | if ne gv_exec true 0 |
| 1038 | ret gv_fail 144 |
| 1039 | end |
| 1040 | n2x = gv_rfile gv_f_out 1 |
| 1041 | if ne n2x n2r |
| 1042 | ret gv_fail 145 |
| 1043 | end |
| 1044 | for i ulong ulong n2x bound 131072 |
| 1045 | if ne get gv_io i get gv_io2 i |
| 1046 | ret gv_fail 146 |
| 1047 | end |
| 1048 | end |
| 1049 | if not gv_wfile gv_f_ir2b ulong n2x false |
| 1050 | ret gv_fail 147 |
| 1051 | end |
| 1052 | if not gv_write_in_bin gv_h_sd ulong n2x false |
| 1053 | ret gv_fail 148 |
| 1054 | end |
| 1055 | if ne gv_exec true 0 |
| 1056 | ret gv_fail 149 |
| 1057 | end |
| 1058 | s2n = gv_rfile gv_f_out 1 |
| 1059 | s1r = gv_rfile gv_f_s1 3 |
| 1060 | if ne s2n s1r |
| 1061 | ret gv_fail 150 |
| 1062 | end |
| 1063 | for i ulong ulong s2n bound 131072 |
| 1064 | if ne get gv_io i get gv_io3 i |
| 1065 | ret gv_fail 151 |
| 1066 | end |
| 1067 | end |
| 1068 | ret 0 |
| 1069 | end |
| 1070 | |
| 1071 | fn gv_cli_v2_pack to int |
| 1072 | note 4. OMPK v2 via @ng pack -> @ng realize -> NG-REALIZE PASS + 2 OMPK v2 CLI negative controls |
| 1073 | n2r = gv_rfile gv_f_ir2 2 |
| 1074 | if not gv_write_in_bin gv_h_pk ulong n2r true |
| 1075 | ret gv_fail 152 |
| 1076 | end |
| 1077 | if ne gv_exec true 0 |
| 1078 | ret gv_fail 153 |
| 1079 | end |
| 1080 | pkn = gv_rfile gv_f_out 1 |
| 1081 | if lt pkn 200 |
| 1082 | ret gv_fail 154 |
| 1083 | end |
| 1084 | if or ne get gv_io 0 79 ne get gv_io 4 2 |
| 1085 | ret gv_fail 155 |
| 1086 | end |
| 1087 | if or ne get gv_io 128 1 ne get gv_io 129 1 |
| 1088 | ret gv_fail 156 |
| 1089 | end |
| 1090 | if not gv_wfile gv_f_pk2 ulong pkn false |
| 1091 | ret gv_fail 157 |
| 1092 | end |
| 1093 | pkr = gv_rfile gv_f_pk2 2 |
| 1094 | if not gv_write_in_bin gv_h_rl ulong pkr true |
| 1095 | ret gv_fail 158 |
| 1096 | end |
| 1097 | if ne gv_exec true 0 |
| 1098 | ret gv_fail 159 |
| 1099 | end |
| 1100 | rln = gv_rfile gv_f_out 1 |
| 1101 | if not gv_io_starts gv_pfx_rlz ulong rln |
| 1102 | ret gv_fail 160 |
| 1103 | end |
| 1104 | note CLI Neg OMPK-1: corrupt v2 purity byte [128]=9 -> @ng realize MUST exit 22 (PK_ERR_CONTRACT) |
| 1105 | put gv_io2 128 uchar 9 |
| 1106 | if not gv_write_in_bin gv_h_rl ulong pkr true |
| 1107 | ret gv_fail 161 |
| 1108 | end |
| 1109 | if ne gv_exec true 22 |
| 1110 | ret gv_fail 162 |
| 1111 | end |
| 1112 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1113 | note CLI Neg OMPK-2: 1-bit tamper in OMPK v2 payload -> @ng realize MUST exit 13 (PK_ERR_DIGEST) |
| 1114 | pkr = gv_rfile gv_f_pk2 2 |
| 1115 | last = sub ulong pkr 1 |
| 1116 | put gv_io2 last xor get gv_io2 last uchar 1 |
| 1117 | if not gv_write_in_bin gv_h_rl ulong pkr true |
| 1118 | ret gv_fail 163 |
| 1119 | end |
| 1120 | if ne gv_exec true 13 |
| 1121 | ret gv_fail 164 |
| 1122 | end |
| 1123 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1124 | put gv_cli_chk 0 add get gv_cli_chk 0 10 |
| 1125 | ret 0 |
| 1126 | end |
| 1127 | |
| 1128 | fn gv_cli_v2_and_infix to int |
| 1129 | r = gv_cli_v2_rt |
| 1130 | if ne r 0 |
| 1131 | ret r |
| 1132 | end |
| 1133 | r = gv_cli_v2_opt_sem |
| 1134 | if ne r 0 |
| 1135 | ret r |
| 1136 | end |
| 1137 | r = gv_cli_v2_infix |
| 1138 | if ne r 0 |
| 1139 | ret r |
| 1140 | end |
| 1141 | ret gv_cli_v2_pack |
| 1142 | end |
| 1143 | |
| 1144 | note Helper: compile impure @pure source with @ng front-ir, then confirm ngcheck refuses with exit 22 (EFFECT)! |
| 1145 | fn gv_cli_neg_impure src view uchar * fail_code ulong to int |
| 1146 | if not gv_write_in_txt gv_h_fi src |
| 1147 | ret gv_fail fail_code |
| 1148 | end |
| 1149 | if ne gv_exec true 0 |
| 1150 | ret gv_fail add fail_code 1 |
| 1151 | end |
| 1152 | n = gv_rfile gv_f_out 1 |
| 1153 | if lt n 32 |
| 1154 | ret gv_fail add fail_code 2 |
| 1155 | end |
| 1156 | gv_spath gv_f_in |
| 1157 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 1158 | if lt fd 0 |
| 1159 | ret gv_fail add fail_code 2 |
| 1160 | end |
| 1161 | kw = write int fd gv_io 0 ulong n |
| 1162 | rc = fclose int fd |
| 1163 | if ne gv_exec false 22 |
| 1164 | ret gv_fail add fail_code 3 |
| 1165 | end |
| 1166 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1167 | ret 0 |
| 1168 | end |
| 1169 | |
| 1170 | fn gv_cli_neg_purity to int |
| 1171 | r = gv_cli_neg_impure gv_neg_host 170 |
| 1172 | if ne r 0 |
| 1173 | ret r |
| 1174 | end |
| 1175 | r = gv_cli_neg_impure gv_neg_gwr 175 |
| 1176 | if ne r 0 |
| 1177 | ret r |
| 1178 | end |
| 1179 | r = gv_cli_neg_impure gv_neg_grd 180 |
| 1180 | if ne r 0 |
| 1181 | ret r |
| 1182 | end |
| 1183 | r = gv_cli_neg_impure gv_neg_cal 185 |
| 1184 | if ne r 0 |
| 1185 | ret r |
| 1186 | end |
| 1187 | r = gv_cli_neg_impure gv_neg_edt 190 |
| 1188 | if ne r 0 |
| 1189 | ret r |
| 1190 | end |
| 1191 | r = gv_cli_neg_impure gv_neg_ext 195 |
| 1192 | if ne r 0 |
| 1193 | ret r |
| 1194 | end |
| 1195 | r = gv_cli_neg_impure gv_neg_chk 200 |
| 1196 | if ne r 0 |
| 1197 | ret r |
| 1198 | end |
| 1199 | ret 0 |
| 1200 | end |
| 1201 | |
| 1202 | fn gv_cli_neg_mut_one off ulong val uchar exp_rc ulong fail_code ulong to int |
| 1203 | n2 = gv_rfile gv_f_ir2 2 |
| 1204 | if lt n2 80 |
| 1205 | ret gv_fail fail_code |
| 1206 | end |
| 1207 | put gv_io2 off val |
| 1208 | gv_spath gv_f_in |
| 1209 | fd = fopen gv_pa 0 get gv_pl 0 577 420 |
| 1210 | kw = write int fd gv_io2 0 ulong n2 |
| 1211 | rc = fclose int fd |
| 1212 | if ne gv_exec false exp_rc |
| 1213 | ret gv_fail add fail_code 1 |
| 1214 | end |
| 1215 | if not gv_write_in_bin gv_h_ic ulong n2 true |
| 1216 | ret gv_fail add fail_code 2 |
| 1217 | end |
| 1218 | if ne gv_exec true exp_rc |
| 1219 | ret gv_fail add fail_code 3 |
| 1220 | end |
| 1221 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1222 | ret 0 |
| 1223 | end |
| 1224 | |
| 1225 | fn gv_cli_neg_malformed to int |
| 1226 | note Verify exact f0 contract offset in /v2.ir (offset 50: pur=1, prc=1, hd=0, rsv=0) |
| 1227 | n2 = gv_rfile gv_f_ir2 2 |
| 1228 | if or lt n2 80 or ne get gv_io2 50 1 ne get gv_io2 51 1 |
| 1229 | ret gv_fail 210 |
| 1230 | end |
| 1231 | note NC-M1: purity_flag = 2 -> ngcheck 13 & ir-copy 13 |
| 1232 | r = gv_cli_neg_mut_one 50 2 13 211 |
| 1233 | if ne r 0 |
| 1234 | ret r |
| 1235 | end |
| 1236 | note NC-M2: precision_tier = 3 -> ngcheck 13 & ir-copy 13 |
| 1237 | r = gv_cli_neg_mut_one 51 3 13 215 |
| 1238 | if ne r 0 |
| 1239 | ret r |
| 1240 | end |
| 1241 | note NC-M3: reserved = 1 -> ngcheck 13 & ir-copy 13 |
| 1242 | r = gv_cli_neg_mut_one 53 1 13 219 |
| 1243 | if ne r 0 |
| 1244 | ret r |
| 1245 | end |
| 1246 | note NC-M4: @exact (tier=1) + err_bound = 1 -> ngcheck 13 & ir-copy 13 |
| 1247 | r = gv_cli_neg_mut_one 54 1 13 223 |
| 1248 | if ne r 0 |
| 1249 | ret r |
| 1250 | end |
| 1251 | note NC-M5: ver 10 + omega.ng.ir.v1 tag -> ngcheck 11 & ir-copy 11 |
| 1252 | r = gv_cli_neg_mut_one 21 49 11 227 |
| 1253 | if ne r 0 |
| 1254 | ret r |
| 1255 | end |
| 1256 | note NC-FE1: conflicting @exact + @tol in prefix frontend -> @ng front-ir exits 30 |
| 1257 | if not gv_write_in_txt gv_h_fi gv_neg_fe1 |
| 1258 | ret gv_fail 231 |
| 1259 | end |
| 1260 | if ne gv_exec true 30 |
| 1261 | ret gv_fail 232 |
| 1262 | end |
| 1263 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1264 | note NC-FE2: @pure inside function body -> @ng front-ir exits 30 |
| 1265 | if not gv_write_in_txt gv_h_fi gv_neg_fe2 |
| 1266 | ret gv_fail 233 |
| 1267 | end |
| 1268 | if ne gv_exec true 30 |
| 1269 | ret gv_fail 234 |
| 1270 | end |
| 1271 | put gv_cli_neg 0 add get gv_cli_neg 0 1 |
| 1272 | ret 0 |
| 1273 | end |
| 1274 | |
| 1275 | fn gv_stage4_cli to int |
| 1276 | nl = argread 1 gv_ngp 0 2047 |
| 1277 | cl = argread 2 gv_ckp 0 2047 |
| 1278 | sl = argread 3 gv_scp 0 2047 |
| 1279 | if or lt nl 1 or lt cl 1 lt sl 1 |
| 1280 | ret gv_fail 99 |
| 1281 | end |
| 1282 | put gv_ngl 0 ulong nl |
| 1283 | put gv_ckl 0 ulong cl |
| 1284 | put gv_scl 0 ulong sl |
| 1285 | r = makedir gv_scp 0 ulong sl 493 |
| 1286 | rc = gv_cli_v1_compat |
| 1287 | if ne rc 0 |
| 1288 | ret rc |
| 1289 | end |
| 1290 | rc = gv_cli_v2_and_infix |
| 1291 | if ne rc 0 |
| 1292 | ret rc |
| 1293 | end |
| 1294 | rc = gv_cli_neg_purity |
| 1295 | if ne rc 0 |
| 1296 | ret rc |
| 1297 | end |
| 1298 | ret gv_cli_neg_malformed |
| 1299 | end |
| 1300 | |
| 1301 | fn main to int |
| 1302 | z = ar_need 0 65536 |
| 1303 | ar_init |
| 1304 | put gv_chk 0 0 |
| 1305 | put gv_neg 0 0 |
| 1306 | put gv_cli_chk 0 0 |
| 1307 | put gv_cli_neg 0 0 |
| 1308 | gv_wrt gv_m_hdr |
| 1309 | |
| 1310 | rc = gv_stage1_ir |
| 1311 | if ne rc 0 |
| 1312 | ret rc |
| 1313 | end |
| 1314 | rc = gv_stage2_infix |
| 1315 | if ne rc 0 |
| 1316 | ret rc |
| 1317 | end |
| 1318 | rc = gv_stage3_pack |
| 1319 | if ne rc 0 |
| 1320 | ret rc |
| 1321 | end |
| 1322 | if ne get gv_neg 0 19 |
| 1323 | ret gv_fail 98 |
| 1324 | end |
| 1325 | |
| 1326 | if ge argcnt 4 |
| 1327 | rc = gv_stage4_cli |
| 1328 | if ne rc 0 |
| 1329 | ret rc |
| 1330 | end |
| 1331 | if ne get gv_cli_neg 0 16 |
| 1332 | ret gv_fail 240 |
| 1333 | end |
| 1334 | end |
| 1335 | |
| 1336 | gv_wrt gv_m_pass |
| 1337 | gv_num get gv_chk 0 |
| 1338 | gv_wrt gv_m_neg |
| 1339 | gv_num get gv_neg 0 |
| 1340 | gv_wrt gv_m_cli |
| 1341 | gv_num get gv_cli_chk 0 |
| 1342 | gv_wrt gv_m_cneg |
| 1343 | gv_num get gv_cli_neg 0 |
| 1344 | gv_wrt gv_m_nl |
| 1345 | ret 0 |
| 1346 | end |