Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/protocol/crumb-spec/ledger.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / protocol / crumb-spec / ledger.om` 253 lines ยท 6351 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note protocol/crumb-spec/ledger.om: pure-Omega port of crumb-spec (src/ledger.rs) 3 note Cryptographic BLAKE3 hash-chained ledger for archived/legacy crumb schema verification. 4 note Standing rule (DRA-97 / 2026-11-08): active workflow .crumb files remain retired; 5 note no .crumb files are created or read in active workflows. This unit locks the pure-Omega 6 note wire/hash contract for historical/archived crumb ledger verification. 7 note Compose after si/directives/om2.om and om/blake3/b3unit.om. 8 9 const CRUMB_OK ulong 0 10 const CRUMB_ERR_HASH_MISMATCH ulong 1 11 const CRUMB_ERR_PARENT_MISMATCH ulong 2 12 const CRUMB_ERR_CHRONO ulong 3 13 const CRUMB_ERR_INVALID_INDEX ulong 4 14 const CRUMB_ERR_MISSING_PARENT ulong 5 15 const CRUMB_ERR_INVALID_GENESIS ulong 6 16 const CRUMB_ERR_FULL ulong 7 17 const CRUMB_ERR_OVERFLOW ulong 8 18 19 const CRUMB_ACT_CREATE ulong 0 20 const CRUMB_ACT_MODIFY ulong 1 21 const CRUMB_ACT_DELETE ulong 2 22 const CRUMB_ACT_AUDIT ulong 3 23 const CRUMB_ACT_TEST ulong 4 24 const CRUMB_ACT_BUILD ulong 5 25 26 const CRUMB_MAX_EVENTS ulong 32 27 28 text cr_domain "CRUMB_LEDGER_EVENT_V1" 29 text cr_act_create "create" 30 text cr_act_modify "modify" 31 text cr_act_delete "delete" 32 text cr_act_audit "audit" 33 text cr_act_test "test" 34 text cr_act_build "build" 35 36 fn cr_put_u32_be dst edit uchar * pos ulong v uint to ulong 37 if gt add pos ulong 4 len dst 38 ret ulong 99999 39 end 40 put dst pos uchar and shr v uint 24 uint 255 41 put dst add pos ulong 1 uchar and shr v uint 16 uint 255 42 put dst add pos ulong 2 uchar and shr v uint 8 uint 255 43 put dst add pos ulong 3 uchar and v uint 255 44 ret add pos ulong 4 45 end 46 47 fn cr_put_u64_be dst edit uchar * pos ulong v ulong to ulong 48 if gt add pos ulong 8 len dst 49 ret ulong 99999 50 end 51 for i ulong 8 52 sh = mul sub ulong 7 i ulong 8 53 put dst add pos i uchar and shr v sh ulong 255 54 end 55 ret add pos ulong 8 56 end 57 58 fn cr_copy_bytes dst edit uchar * pos ulong src view uchar * to ulong 59 n = len src 60 if gt add pos n len dst 61 ret ulong 99999 62 end 63 if gt n ulong 1024 64 ret ulong 99999 65 end 66 i = ulong 0 67 while lt i n bound 1024 68 put dst add pos i get src i 69 i = add i ulong 1 70 end 71 ret add pos n 72 end 73 74 fn cr_put_lp_str dst edit uchar * pos ulong src view uchar * to ulong 75 p = cr_put_u32_be dst pos uint len src 76 if eq p ulong 99999 77 ret ulong 99999 78 end 79 ret cr_copy_bytes dst p src 80 end 81 82 fn cr_put_action dst edit uchar * pos ulong act ulong to ulong 83 if eq act CRUMB_ACT_CREATE 84 ret cr_put_lp_str dst pos cr_act_create 85 end 86 if eq act CRUMB_ACT_MODIFY 87 ret cr_put_lp_str dst pos cr_act_modify 88 end 89 if eq act CRUMB_ACT_DELETE 90 ret cr_put_lp_str dst pos cr_act_delete 91 end 92 if eq act CRUMB_ACT_AUDIT 93 ret cr_put_lp_str dst pos cr_act_audit 94 end 95 if eq act CRUMB_ACT_TEST 96 ret cr_put_lp_str dst pos cr_act_test 97 end 98 if eq act CRUMB_ACT_BUILD 99 ret cr_put_lp_str dst pos cr_act_build 100 end 101 ret ulong 99999 102 end 103 104 fn cr_hash_eq a view uchar 32 b view uchar 32 to bool 105 for i ulong 32 106 if ne get a i get b i 107 ret false 108 end 109 end 110 ret true 111 end 112 113 fn cr_is_zero_hash h view uchar 32 to bool 114 for i ulong 32 115 if ne get h i uchar 0 116 ret false 117 end 118 end 119 ret true 120 end 121 122 note Single-shot BLAKE3-256 over up to 1024 bytes using om/blake3/b3unit.om 123 fn cr_blake3_buf data view uchar * digest edit uchar 32 to ulong 124 n = len data 125 if gt n ulong 1024 126 ret CRUMB_ERR_OVERFLOW 127 end 128 st = new ulong 448 0 129 blk = new uchar 1024 0 130 i = ulong 0 131 while lt i n bound 1024 132 put blk i get data i 133 i = add i ulong 1 134 end 135 omb3 st blk n ulong 1 digest 136 ret CRUMB_OK 137 end 138 139 note Encode canonical LedgerEvent preimage matching crumb-spec src/ledger.rs: 140 note "CRUMB_LEDGER_EVENT_V1" || be64(index) || be64(timestamp) || 141 note be32(len(agent)) || agent || be32(len(action)) || action || 142 note be32(len(target)) || target || be32(len(intent)) || intent || 143 note payload_hash[32] || parent_hash[32] 144 note Split into two helpers to respect 6-parameter-slot limit. 145 fn cr_event_preimage_head buf edit uchar 1024 idx ulong ts ulong act ulong agent view uchar * to ulong 146 p = cr_copy_bytes buf ulong 0 cr_domain 147 if eq p ulong 99999 148 ret ulong 99999 149 end 150 p = cr_put_u64_be buf p idx 151 if eq p ulong 99999 152 ret ulong 99999 153 end 154 p = cr_put_u64_be buf p ts 155 if eq p ulong 99999 156 ret ulong 99999 157 end 158 p = cr_put_lp_str buf p agent 159 if eq p ulong 99999 160 ret ulong 99999 161 end 162 ret cr_put_action buf p act 163 end 164 165 fn cr_event_preimage_tail buf edit uchar 1024 pos ulong target view uchar * intent view uchar * to ulong 166 p = cr_put_lp_str buf pos target 167 if eq p ulong 99999 168 ret ulong 99999 169 end 170 ret cr_put_lp_str buf p intent 171 end 172 173 fn cr_event_finalize buf edit uchar 1024 pos ulong ph view uchar 32 par view uchar 32 dig edit uchar 32 to ulong 174 p = cr_copy_bytes buf pos ph 175 if eq p ulong 99999 176 ret CRUMB_ERR_OVERFLOW 177 end 178 p = cr_copy_bytes buf p par 179 if eq p ulong 99999 180 ret CRUMB_ERR_OVERFLOW 181 end 182 st = new ulong 448 0 183 omb3 st buf p ulong 1 dig 184 ret CRUMB_OK 185 end 186 187 note Verify an event chain stored in parallel arrays: 188 note indices[n], timestamps[n], hashes[n*32], parents[n*32], recomputed[n*32] 189 note Each slot i has 32 bytes at offset i*32. 190 fn cr_copy_slot32 flat view uchar 1024 idx ulong dst edit uchar 32 to void 191 base = mul idx ulong 32 192 for i ulong 32 193 put dst i get flat add base i 194 end 195 end 196 197 fn cr_put_slot32 flat edit uchar 1024 idx ulong src view uchar 32 to void 198 base = mul idx ulong 32 199 for i ulong 32 200 put flat add base i get src i 201 end 202 end 203 204 fn cr_verify_chain_meta count ulong indices view ulong 32 timestamps view ulong 32 hashes view uchar 1024 parents view uchar 1024 to ulong 205 if gt count CRUMB_MAX_EVENTS 206 ret CRUMB_ERR_FULL 207 end 208 hcur = new uchar 32 0 209 hprev = new uchar 32 0 210 pcur = new uchar 32 0 211 i = ulong 0 212 while lt i count bound 32 213 if ne get indices i i 214 ret CRUMB_ERR_INVALID_INDEX 215 end 216 cr_copy_slot32 parents i pcur 217 if eq i ulong 0 218 if not cr_is_zero_hash pcur 219 ret CRUMB_ERR_INVALID_GENESIS 220 end 221 else 222 prev_i = sub i ulong 1 223 cr_copy_slot32 hashes prev_i hprev 224 if not cr_hash_eq pcur hprev 225 ret CRUMB_ERR_PARENT_MISMATCH 226 end 227 if lt get timestamps i get timestamps prev_i 228 ret CRUMB_ERR_CHRONO 229 end 230 end 231 i = add i ulong 1 232 end 233 ret CRUMB_OK 234 end 235 236 fn cr_verify_parent count ulong ev_idx ulong ev_parent view uchar 32 hashes view uchar 1024 to ulong 237 if eq ev_idx ulong 0 238 if not cr_is_zero_hash ev_parent 239 ret CRUMB_ERR_INVALID_GENESIS 240 end 241 ret CRUMB_OK 242 end 243 par_i = sub ev_idx ulong 1 244 if ge par_i count 245 ret CRUMB_ERR_MISSING_PARENT 246 end 247 exp = new uchar 32 0 248 cr_copy_slot32 hashes par_i exp 249 if not cr_hash_eq ev_parent exp 250 ret CRUMB_ERR_PARENT_MISMATCH 251 end 252 ret CRUMB_OK 253 end