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/aienux/crates/aienos-anchor/anchor_test.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 / aienux / crates / aienos-anchor / anchor_test.om` 166 lines ยท 3572 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-anchor/anchor_test.om: Behavioral self-test for aienos-anchor. 3 note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-anchor/anchor.om aienux/crates/aienos-anchor/anchor_test.om 4 5 text at_k1 "host.arch" 6 text at_v1 "aarch64" 7 text at_v2 "aarch64-gb10" 8 text at_src "boot-verify" 9 text at_k2 "missing.key" 10 11 fn main to int 12 anchor_init 13 key_a = new uchar 32 0x11 14 key_b = new uchar 32 0x22 15 rc = anchor_add_trusted key_a 16 if ne rc ANCHOR_OK 17 ret 1 18 end 19 20 note 1. Unknown key before any admission 21 if ne anchor_query at_k1 ANCHOR_ANS_UNKNOWN 22 ret 2 23 end 24 25 note 2. Admit fact seq 0 26 anchor_stage_hdr 0 ANCHOR_KIND_ADMIT 1000 27 rc = anchor_stage_kv at_k1 at_v1 28 if ne rc ANCHOR_OK 29 ret 3 30 end 31 rc = anchor_stage_source at_src 32 if ne rc ANCHOR_OK 33 ret 4 34 end 35 anchor_sign_staged key_a 36 rc = anchor_append_staged 37 if ne rc ANCHOR_OK 38 ret 5 39 end 40 if ne anchor_query at_k1 ANCHOR_ANS_KNOWN 41 ret 6 42 end 43 if ne get anchor_q_res 2 0 44 ret 7 45 end 46 47 note 3. Reject untrusted signer 48 anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001 49 rc = anchor_stage_kv at_k1 at_v2 50 if ne rc ANCHOR_OK 51 ret 8 52 end 53 anchor_sign_staged key_b 54 if ne anchor_append_staged ANCHOR_ERR_UNTRUSTED 55 ret 9 56 end 57 58 note 4. Reject out-of-order seq 59 anchor_stage_hdr 5 ANCHOR_KIND_ADMIT 1001 60 rc = anchor_stage_kv at_k1 at_v2 61 anchor_sign_staged key_a 62 if ne anchor_append_staged ANCHOR_ERR_OUT_OF_ORDER 63 ret 10 64 end 65 66 note 5. Reject broken chain prev 67 anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001 68 rc = anchor_stage_kv at_k1 at_v2 69 bad_prev = new uchar 32 0x99 70 anchor_stage_prev bad_prev 71 anchor_sign_staged key_a 72 if ne anchor_append_staged ANCHOR_ERR_BROKEN_CHAIN 73 ret 11 74 end 75 76 note 6. Reject tampered signature 77 anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001 78 rc = anchor_stage_kv at_k1 at_v2 79 anchor_sign_staged key_a 80 put anchor_st_sig 0 xor get anchor_st_sig 0 1 81 if ne anchor_append_staged ANCHOR_ERR_BAD_SIG 82 ret 12 83 end 84 85 note 7. Reject retract with non-empty value 86 anchor_stage_hdr 1 ANCHOR_KIND_RETRACT 1002 87 rc = anchor_stage_kv at_k1 at_v1 88 anchor_sign_staged key_a 89 if ne anchor_append_staged ANCHOR_ERR_RETRACT_VALUE 90 ret 13 91 end 92 93 note 8. Reject retract of unknown key 94 empty_v = new uchar 1 0 95 anchor_stage_hdr 1 ANCHOR_KIND_RETRACT 1002 96 rc = anchor_stage_kv at_k2 part empty_v 0 0 97 anchor_sign_staged key_a 98 if ne anchor_append_staged ANCHOR_ERR_RETRACT_UNKNOWN 99 ret 14 100 end 101 102 note 9. Valid update seq 1 then retract seq 2 103 anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1002 104 rc = anchor_stage_kv at_k1 at_v2 105 anchor_sign_staged key_a 106 if ne anchor_append_staged ANCHOR_OK 107 ret 15 108 end 109 anchor_stage_hdr 2 ANCHOR_KIND_RETRACT 1003 110 rc = anchor_stage_kv at_k1 part empty_v 0 0 111 anchor_sign_staged key_a 112 if ne anchor_append_staged ANCHOR_OK 113 ret 16 114 end 115 if ne anchor_query at_k1 ANCHOR_ANS_RETRACTED 116 ret 17 117 end 118 if ne get anchor_q_res 2 2 119 ret 18 120 end 121 122 note 10. Export all 3 entries and replay into a fresh anchor 123 logbuf = new uchar 2048 0 124 pos = ulong 0 125 saved_head = new uchar 32 0 126 for i ulong 32 127 put saved_head i get anchor_head i 128 end 129 ebuf = new uchar 512 0 130 for idx ulong 3 131 elen = anchor_export_entry idx ebuf 132 for j ulong elen bound 512 133 put logbuf add pos j get ebuf j 134 end 135 pos = add pos elen 136 end 137 138 anchor_init 139 rc = anchor_add_trusted key_a 140 if ne rc ANCHOR_OK 141 ret 19 142 end 143 rc = anchor_replay logbuf pos 144 if ne rc ANCHOR_OK 145 ret 20 146 end 147 if ne get anchor_cnt 0 3 148 ret 21 149 end 150 for i ulong 32 151 if ne get anchor_head i get saved_head i 152 ret 22 153 end 154 end 155 156 note 11. Tampered log byte must refuse replay 157 put logbuf 20 xor get logbuf 20 0xff 158 anchor_init 159 rc = anchor_add_trusted key_a 160 rc = anchor_replay logbuf pos 161 if eq rc ANCHOR_OK 162 ret 23 163 end 164 165 ret 0 166 end