interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / protocol / crumb-spec / test.om

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