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 / core / sovereign-core / om / qwen-native / flash / attest.om
| 1 | note Build-time seeded Omega attestor for Flash-Next (131 shards). Emits host bindings only after hashing each opened file and comparing stats on the same descriptor. |
| 2 | note Usage: attest MODEL_DIR [START COUNT]. Without START COUNT, emits the full install.om for shards 0..131. |
| 3 | global qa_path uchar 4300 |
| 4 | global qa_root uchar 4096 |
| 5 | global qa_input uchar 65536 |
| 6 | global qa_stat uchar 128 |
| 7 | global qa_before ulong 7 |
| 8 | global qa_info ulong 1 |
| 9 | text qa_declare "global qdiskpin ulong 917" |
| 10 | text qa_f38 "fn qdisk38 to void" |
| 11 | text qa_end "end" |
| 12 | text qa_put "put qdiskpin " |
| 13 | text qa_layer "/model-00" |
| 14 | text qa_suffix "-of-00131.safetensors" |
| 15 | fn qa_print s view uchar * to void |
| 16 | for i ulong len s |
| 17 | tkpc ulong get s i |
| 18 | end |
| 19 | end |
| 20 | fn qa_num arg ulong to ulong |
| 21 | b = new uchar 32 0 |
| 22 | n = argread arg b 0 31 |
| 23 | if le n 0 |
| 24 | exit 2 |
| 25 | end |
| 26 | v = ulong 0 |
| 27 | for i ulong ulong n |
| 28 | c = ulong get b i |
| 29 | if or lt c 48 gt c 57 |
| 30 | exit 2 |
| 31 | end |
| 32 | v = add mul v 10 sub c 48 |
| 33 | end |
| 34 | ret v |
| 35 | end |
| 36 | fn qa_word off ulong to ulong |
| 37 | v = ulong 0 |
| 38 | for i ulong 8 |
| 39 | v = or v shl ulong get qa_stat add i off mul i 8 |
| 40 | end |
| 41 | ret v |
| 42 | end |
| 43 | fn qa_value j ulong to ulong |
| 44 | if eq j 0 |
| 45 | ret qa_word 0 |
| 46 | end |
| 47 | if eq j 1 |
| 48 | ret qa_word 8 |
| 49 | end |
| 50 | if eq j 2 |
| 51 | ret qa_word 48 |
| 52 | end |
| 53 | ret qa_word add 88 mul sub j 3 8 |
| 54 | end |
| 55 | fn qa_cat p ulong s view uchar * to ulong |
| 56 | for i ulong len s |
| 57 | put qa_path add p i get s i |
| 58 | end |
| 59 | ret add p len s |
| 60 | end |
| 61 | fn qa_name j ulong to ulong |
| 62 | n = get qa_info 0 |
| 63 | for i ulong n |
| 64 | put qa_path i get qa_root i |
| 65 | end |
| 66 | p = qa_cat n qa_layer |
| 67 | f = add j 1 |
| 68 | put qa_path p uchar add 48 div f 100 |
| 69 | put qa_path add p 1 uchar add 48 rem div f 10 10 |
| 70 | put qa_path add p 2 uchar add 48 rem f 10 |
| 71 | ret qa_cat add p 3 qa_suffix |
| 72 | end |
| 73 | fn qa_hash fd int to void |
| 74 | hreset |
| 75 | while true bound 1048577 |
| 76 | r = read fd qa_input 0 len qa_input |
| 77 | if lt r 0 |
| 78 | exit 3 |
| 79 | end |
| 80 | if eq r 0 |
| 81 | break |
| 82 | end |
| 83 | for i ulong ulong r |
| 84 | if not hpush get qa_input i |
| 85 | exit 3 |
| 86 | end |
| 87 | end |
| 88 | end |
| 89 | if not hfinal |
| 90 | exit 3 |
| 91 | end |
| 92 | end |
| 93 | fn qa_shard j ulong to void |
| 94 | n = qa_name j |
| 95 | fd = fopen qa_path 0 n 557056 0 |
| 96 | if lt fd 0 |
| 97 | exit 2 |
| 98 | end |
| 99 | if ne fstat int fd qa_stat 0 128 0 |
| 100 | exit 3 |
| 101 | end |
| 102 | for i ulong 7 |
| 103 | put qa_before i qa_value i |
| 104 | end |
| 105 | qa_hash int fd |
| 106 | for c ulong 64 |
| 107 | if ne get hd c qa_expected j c |
| 108 | exit 4 |
| 109 | end |
| 110 | end |
| 111 | if ne fstat int fd qa_stat 0 128 0 |
| 112 | exit 3 |
| 113 | end |
| 114 | for i ulong 7 |
| 115 | if ne get qa_before i qa_value i |
| 116 | exit 5 |
| 117 | end |
| 118 | qa_print qa_put |
| 119 | tcpu add mul j 7 i |
| 120 | tkpc 32 |
| 121 | tcpu get qa_before i |
| 122 | tkpc 10 |
| 123 | end |
| 124 | r = fclose int fd |
| 125 | if ne r 0 |
| 126 | exit 3 |
| 127 | end |
| 128 | end |
| 129 | fn main to int |
| 130 | if and ne argcnt 2 ne argcnt 4 |
| 131 | ret 2 |
| 132 | end |
| 133 | n = argread 1 qa_root 0 4095 |
| 134 | if le n 0 |
| 135 | ret 2 |
| 136 | end |
| 137 | put qa_info 0 ulong n |
| 138 | if eq argcnt 2 |
| 139 | qa_print qa_declare |
| 140 | tkpc 10 |
| 141 | qa_print qa_f38 |
| 142 | tkpc 10 |
| 143 | for j ulong 131 |
| 144 | qa_shard j |
| 145 | end |
| 146 | qa_print qa_end |
| 147 | tkpc 10 |
| 148 | tkpfl |
| 149 | ret 0 |
| 150 | end |
| 151 | start = qa_num 2 |
| 152 | count = qa_num 3 |
| 153 | if or gt start 131 gt count sub 131 start |
| 154 | ret 2 |
| 155 | end |
| 156 | for k ulong count |
| 157 | qa_shard add start k |
| 158 | end |
| 159 | tkpfl |
| 160 | ret 0 |
| 161 | end |