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 / om / visor / verify_om2.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Pure seeded OM-2 verification engine primitives backing src/omega_verify.c. |
| 3 | om2 |
| 4 | |
| 5 | note V0 structural realization bounds check: |
| 6 | note profile == 1 (AARCH64_PROFILE_V8A_BAREMETAL), 4 <= clen <= mcode, clen % 4 == 0, hasid != 0. |
| 7 | note Returns 0 OK, 1 bad profile, 2 bad clen, 3 missing id. |
| 8 | export fn om_ver_v0_real prof ulong clen ulong mcode ulong hasid ulong to long |
| 9 | if ne prof 1 |
| 10 | ret 1 |
| 11 | end |
| 12 | if or lt clen 4 or gt clen mcode ne rem clen 4 0 |
| 13 | ret 2 |
| 14 | end |
| 15 | if eq hasid 0 |
| 16 | ret 3 |
| 17 | end |
| 18 | ret 0 |
| 19 | end |
| 20 | |
| 21 | note V1 semantic reference evaluation: F(a, b, c) = (a + b) - c modulo 2^64. |
| 22 | export fn om_ver_v1_ref a ulong b ulong c ulong to ulong |
| 23 | ret sub add a b c |
| 24 | end |
| 25 | |
| 26 | note V1 default test vectors (7 triplets). Returns 0 if idx in 0..6, -1 otherwise. |
| 27 | export fn om_ver_v1_defvec idx ulong dst edit ulong 3 to long |
| 28 | if eq idx 0 |
| 29 | put dst 0 7 |
| 30 | put dst 1 11 |
| 31 | put dst 2 3 |
| 32 | ret 0 |
| 33 | end |
| 34 | if eq idx 1 |
| 35 | put dst 0 0 |
| 36 | put dst 1 0 |
| 37 | put dst 2 0 |
| 38 | ret 0 |
| 39 | end |
| 40 | if eq idx 2 |
| 41 | put dst 0 100 |
| 42 | put dst 1 200 |
| 43 | put dst 2 50 |
| 44 | ret 0 |
| 45 | end |
| 46 | if eq idx 3 |
| 47 | put dst 0 1000 |
| 48 | put dst 1 500 |
| 49 | put dst 2 300 |
| 50 | ret 0 |
| 51 | end |
| 52 | if eq idx 4 |
| 53 | put dst 0 1 |
| 54 | put dst 1 1 |
| 55 | put dst 2 1 |
| 56 | ret 0 |
| 57 | end |
| 58 | if eq idx 5 |
| 59 | put dst 0 50 |
| 60 | put dst 1 0 |
| 61 | put dst 2 10 |
| 62 | ret 0 |
| 63 | end |
| 64 | if eq idx 6 |
| 65 | put dst 0 18446744073709551614 |
| 66 | put dst 1 1 |
| 67 | put dst 2 0 |
| 68 | ret 0 |
| 69 | end |
| 70 | ret -1 |
| 71 | end |
| 72 | |
| 73 | fn mask_w width ulong to ulong |
| 74 | if ge width 64 |
| 75 | ret 18446744073709551615 |
| 76 | end |
| 77 | ret sub shl ulong 1 width 1 |
| 78 | end |
| 79 | |
| 80 | note Pure binary uint wrap evaluation for OP_ADD(3), OP_SUB(4), OP_MUL(5), OP_AND(9), OP_OR(10). |
| 81 | export fn om_ver_v2_eval op ulong width ulong a ulong b ulong to ulong |
| 82 | m = mask_w width |
| 83 | if eq op 3 |
| 84 | ret and add a b m |
| 85 | end |
| 86 | if eq op 4 |
| 87 | ret and sub a b m |
| 88 | end |
| 89 | if eq op 5 |
| 90 | ret and mul a b m |
| 91 | end |
| 92 | if eq op 9 |
| 93 | ret and and a b m |
| 94 | end |
| 95 | if eq op 10 |
| 96 | ret and or a b m |
| 97 | end |
| 98 | ret 0 |
| 99 | end |
| 100 | |
| 101 | note Run full V2 algebraic property suite in pure OM-2. |
| 102 | note Returns total check count (>= 0) on pass, or -1 on failure with info[0]=kind (1..7), info[1]=op, info[2]=x, info[3]=y. |
| 103 | export fn om_ver_v2_props info edit ulong 4 to long |
| 104 | cnt = ulong 0 |
| 105 | oparr = new ulong 4 0 |
| 106 | put oparr 0 3 |
| 107 | put oparr 1 5 |
| 108 | put oparr 2 9 |
| 109 | put oparr 3 10 |
| 110 | for o ulong 4 |
| 111 | op = get oparr o |
| 112 | x = ulong 0 |
| 113 | while lt x 32 |
| 114 | y = ulong 0 |
| 115 | while lt y 32 |
| 116 | cnt = add cnt 1 |
| 117 | r1 = om_ver_v2_eval op 64 x y |
| 118 | r2 = om_ver_v2_eval op 64 y x |
| 119 | if ne r1 r2 |
| 120 | put info 0 1 |
| 121 | put info 1 op |
| 122 | put info 2 x |
| 123 | put info 3 y |
| 124 | ret -1 |
| 125 | end |
| 126 | y = add y 5 |
| 127 | end |
| 128 | x = add x 7 |
| 129 | end |
| 130 | end |
| 131 | all1 = ulong 18446744073709551615 |
| 132 | for v ulong 64 |
| 133 | cnt = add cnt 1 |
| 134 | if ne om_ver_v2_eval 3 64 v 0 v |
| 135 | put info 0 2 |
| 136 | put info 1 3 |
| 137 | put info 2 v |
| 138 | put info 3 0 |
| 139 | ret -1 |
| 140 | end |
| 141 | cnt = add cnt 1 |
| 142 | if ne om_ver_v2_eval 5 64 v 1 v |
| 143 | put info 0 3 |
| 144 | put info 1 5 |
| 145 | put info 2 v |
| 146 | put info 3 1 |
| 147 | ret -1 |
| 148 | end |
| 149 | cnt = add cnt 1 |
| 150 | if ne om_ver_v2_eval 9 64 v all1 v |
| 151 | put info 0 4 |
| 152 | put info 1 9 |
| 153 | put info 2 v |
| 154 | put info 3 all1 |
| 155 | ret -1 |
| 156 | end |
| 157 | cnt = add cnt 1 |
| 158 | if ne om_ver_v2_eval 10 64 v 0 v |
| 159 | put info 0 5 |
| 160 | put info 1 10 |
| 161 | put info 2 v |
| 162 | put info 3 0 |
| 163 | ret -1 |
| 164 | end |
| 165 | end |
| 166 | cnt = add cnt 1 |
| 167 | if ne om_ver_v2_eval 3 64 all1 1 0 |
| 168 | put info 0 6 |
| 169 | put info 1 3 |
| 170 | put info 2 all1 |
| 171 | put info 3 1 |
| 172 | ret -1 |
| 173 | end |
| 174 | cnt = add cnt 1 |
| 175 | if ne om_ver_v2_eval 4 64 0 1 all1 |
| 176 | put info 0 6 |
| 177 | put info 1 4 |
| 178 | put info 2 0 |
| 179 | put info 3 1 |
| 180 | ret -1 |
| 181 | end |
| 182 | cnt = add cnt 1 |
| 183 | if ne om_ver_v2_eval 3 16 65535 1 0 |
| 184 | put info 0 7 |
| 185 | put info 1 3 |
| 186 | put info 2 65535 |
| 187 | put info 3 1 |
| 188 | ret -1 |
| 189 | end |
| 190 | put info 0 0 |
| 191 | put info 1 0 |
| 192 | put info 2 0 |
| 193 | put info 3 0 |
| 194 | ret long cnt |
| 195 | end |