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 / protocol / crumb-spec / test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/crumb-spec/test.om: pure-Omega positive & negative control tests for crumb-spec BLAKE3 ledger. |
| 3 | note Ports all scenarios from crumb-spec src/lib.rs. |
| 4 | note Compose after si/directives/om2.om, om/blake3/b3unit.om, and protocol/crumb-spec/ledger.om. |
| 5 | |
| 6 | text ct_pass "PASS crumb-spec BLAKE3 hash-chained ledger all 7 test suites passed\n" |
| 7 | text ct_fail "FAIL crumb-spec ledger\n" |
| 8 | |
| 9 | text ct_agent "agent-atlas-prime" |
| 10 | text ct_t0 "crates/core/src/lib.rs" |
| 11 | text ct_i0 "Init core crate" |
| 12 | text ct_p0 "payload-content-step-0" |
| 13 | text ct_t1 "crates/core/src/lib.rs" |
| 14 | text ct_i1 "Implement protocol handler" |
| 15 | text ct_p1 "payload-content-step-1" |
| 16 | text ct_t2 "crates/core/tests/test.rs" |
| 17 | text ct_i2 "Add unit tests" |
| 18 | text ct_p2 "payload-content-step-2" |
| 19 | text ct_t3 "target/release/core" |
| 20 | text ct_i3 "Compile release binary" |
| 21 | text ct_p3 "payload-content-step-3" |
| 22 | text ct_evil "Malicious backdoor inserted" |
| 23 | |
| 24 | fn ct_compute_ev idx ulong ts ulong act ulong par view uchar 32 out_h edit uchar 32 to bool |
| 25 | ph = new uchar 32 0 |
| 26 | buf = new uchar 1024 0 |
| 27 | p = cr_event_preimage_head buf idx ts act ct_agent |
| 28 | if eq p ulong 99999 |
| 29 | ret false |
| 30 | end |
| 31 | if eq idx ulong 0 |
| 32 | if ne cr_blake3_buf ct_p0 ph CRUMB_OK |
| 33 | ret false |
| 34 | end |
| 35 | p = cr_event_preimage_tail buf p ct_t0 ct_i0 |
| 36 | end |
| 37 | if eq idx ulong 1 |
| 38 | if ne cr_blake3_buf ct_p1 ph CRUMB_OK |
| 39 | ret false |
| 40 | end |
| 41 | p = cr_event_preimage_tail buf p ct_t1 ct_i1 |
| 42 | end |
| 43 | if eq idx ulong 2 |
| 44 | if ne cr_blake3_buf ct_p2 ph CRUMB_OK |
| 45 | ret false |
| 46 | end |
| 47 | p = cr_event_preimage_tail buf p ct_t2 ct_i2 |
| 48 | end |
| 49 | if eq idx ulong 3 |
| 50 | if ne cr_blake3_buf ct_p3 ph CRUMB_OK |
| 51 | ret false |
| 52 | end |
| 53 | p = cr_event_preimage_tail buf p ct_t3 ct_i3 |
| 54 | end |
| 55 | if eq idx ulong 99 |
| 56 | if ne cr_blake3_buf ct_p0 ph CRUMB_OK |
| 57 | ret false |
| 58 | end |
| 59 | p = cr_event_preimage_head buf ulong 0 ts act ct_agent |
| 60 | if eq p ulong 99999 |
| 61 | ret false |
| 62 | end |
| 63 | p = cr_event_preimage_tail buf p ct_t0 ct_evil |
| 64 | end |
| 65 | if eq p ulong 99999 |
| 66 | ret false |
| 67 | end |
| 68 | rc = cr_event_finalize buf p ph par out_h |
| 69 | ret eq rc CRUMB_OK |
| 70 | end |
| 71 | |
| 72 | fn ct_run_all to bool |
| 73 | indices = new ulong 32 0 |
| 74 | ts = new ulong 32 0 |
| 75 | hashes = new uchar 1024 0 |
| 76 | parents = new uchar 1024 0 |
| 77 | zero = new uchar 32 0 |
| 78 | h0 = new uchar 32 0 |
| 79 | h1 = new uchar 32 0 |
| 80 | h2 = new uchar 32 0 |
| 81 | h3 = new uchar 32 0 |
| 82 | base_t = ulong 1700000000 |
| 83 | |
| 84 | note 1. Build 4-event hash chain |
| 85 | if not ct_compute_ev ulong 0 base_t CRUMB_ACT_CREATE zero h0 |
| 86 | ret false |
| 87 | end |
| 88 | put indices 0 ulong 0 |
| 89 | put ts 0 base_t |
| 90 | cr_put_slot32 parents ulong 0 zero |
| 91 | cr_put_slot32 hashes ulong 0 h0 |
| 92 | |
| 93 | if not ct_compute_ev ulong 1 add base_t ulong 10 CRUMB_ACT_MODIFY h0 h1 |
| 94 | ret false |
| 95 | end |
| 96 | put indices 1 ulong 1 |
| 97 | put ts 1 add base_t ulong 10 |
| 98 | cr_put_slot32 parents ulong 1 h0 |
| 99 | cr_put_slot32 hashes ulong 1 h1 |
| 100 | |
| 101 | if not ct_compute_ev ulong 2 add base_t ulong 20 CRUMB_ACT_TEST h1 h2 |
| 102 | ret false |
| 103 | end |
| 104 | put indices 2 ulong 2 |
| 105 | put ts 2 add base_t ulong 20 |
| 106 | cr_put_slot32 parents ulong 2 h1 |
| 107 | cr_put_slot32 hashes ulong 2 h2 |
| 108 | |
| 109 | if not ct_compute_ev ulong 3 add base_t ulong 30 CRUMB_ACT_BUILD h2 h3 |
| 110 | ret false |
| 111 | end |
| 112 | put indices 3 ulong 3 |
| 113 | put ts 3 add base_t ulong 30 |
| 114 | cr_put_slot32 parents ulong 3 h2 |
| 115 | cr_put_slot32 hashes ulong 3 h3 |
| 116 | |
| 117 | note 2. Untampered chain verifies |
| 118 | if ne cr_verify_chain_meta ulong 4 indices ts hashes parents CRUMB_OK |
| 119 | ret false |
| 120 | end |
| 121 | |
| 122 | note 3. Scenario 1: tamper genesis intent -> hash mismatch; rehash genesis -> event 1 ParentHashMismatch |
| 123 | h0_bad = new uchar 32 0 |
| 124 | if not ct_compute_ev ulong 99 base_t CRUMB_ACT_CREATE zero h0_bad |
| 125 | ret false |
| 126 | end |
| 127 | if cr_hash_eq h0 h0_bad |
| 128 | ret false |
| 129 | end |
| 130 | cr_put_slot32 hashes ulong 0 h0_bad |
| 131 | if ne cr_verify_chain_meta ulong 4 indices ts hashes parents CRUMB_ERR_PARENT_MISMATCH |
| 132 | ret false |
| 133 | end |
| 134 | note Restore genesis hash |
| 135 | cr_put_slot32 hashes ulong 0 h0 |
| 136 | |
| 137 | note 4. Scenario 2: chronological violation (ts[2] < ts[1]) |
| 138 | put ts 2 add base_t ulong 5 |
| 139 | if ne cr_verify_chain_meta ulong 4 indices ts hashes parents CRUMB_ERR_CHRONO |
| 140 | ret false |
| 141 | end |
| 142 | put ts 2 add base_t ulong 20 |
| 143 | |
| 144 | note 5. Scenario 3: non-zero genesis parent |
| 145 | put parents 0 uchar 1 |
| 146 | if ne cr_verify_chain_meta ulong 4 indices ts hashes parents CRUMB_ERR_INVALID_GENESIS |
| 147 | ret false |
| 148 | end |
| 149 | put parents 0 uchar 0 |
| 150 | |
| 151 | note 6. Scenario 4: invalid index sequence |
| 152 | put indices 2 ulong 9 |
| 153 | if ne cr_verify_chain_meta ulong 4 indices ts hashes parents CRUMB_ERR_INVALID_INDEX |
| 154 | ret false |
| 155 | end |
| 156 | put indices 2 ulong 2 |
| 157 | |
| 158 | note 7. Scenario 5: verify_parent (valid, missing parent, wrong parent) |
| 159 | if ne cr_verify_parent ulong 4 ulong 0 zero hashes CRUMB_OK |
| 160 | ret false |
| 161 | end |
| 162 | if ne cr_verify_parent ulong 4 ulong 2 h1 hashes CRUMB_OK |
| 163 | ret false |
| 164 | end |
| 165 | if ne cr_verify_parent ulong 4 ulong 5 h3 hashes CRUMB_ERR_MISSING_PARENT |
| 166 | ret false |
| 167 | end |
| 168 | if ne cr_verify_parent ulong 4 ulong 2 h0 hashes CRUMB_ERR_PARENT_MISMATCH |
| 169 | ret false |
| 170 | end |
| 171 | ret true |
| 172 | end |
| 173 | |
| 174 | fn main to int |
| 175 | if not ct_run_all |
| 176 | k = write int 1 ct_fail ulong 0 len ct_fail |
| 177 | if lt k long 0 |
| 178 | ret int 1 |
| 179 | end |
| 180 | ret int 1 |
| 181 | end |
| 182 | k = write int 1 ct_pass ulong 0 len ct_pass |
| 183 | if lt k long 0 |
| 184 | ret int 1 |
| 185 | end |
| 186 | ret int 0 |
| 187 | end |