code wiki / _hdl_build / nx_chatmut_gate.nx
nx_chatmut_gate.nx source
↩ module page · 51 lines · 2972 B
1// nx_chatmut_gate.nx -- proves the sovereign polite/transparent message mutation (nx_chatmut). Native, fast.
2import "nx_syscalls.nx"
3import "nx_gate_emit_lib.nx"
4import "nx_chatmut.nx"
5import "nx_gate_verdict.nx"
6
7func main() -> i64 {
8 g_puts("nx_chatmut gate (polite/transparent edit + retract -- no sneakiness)\n" as *u8)
9 var pass: i64 = 0; var total: i64 = 0
10 let rec: *i64 = sys_mmap(4*8) as *i64
11 cmt_init(rec, 40)
12
13 // 1) edit is visible + counted (no silent rewrite)
14 cmt_edit(rec, 35)
15 pass = pass + g_check("edit -> marked 'edited' + counted (transparent history)" as *u8, (cmt_marker(rec) == CMT_EDITED) & (rec[1] == 1)); total=total+1
16
17 // 2) multiple edits keep honest history
18 cmt_edit(rec, 50)
19 pass = pass + g_check("edits accumulate in the history count (no hidden edits)" as *u8, rec[1] == 2); total=total+1
20
21 // 3) retract removes content but leaves a visible tombstone (NOT a stealth delete)
22 cmt_retract(rec)
23 pass = pass + g_check("retract: content gone (len 0) BUT visible 'retracted' tombstone (no sneaky delete)" as *u8, (rec[2] == 0) & (cmt_marker(rec) == CMT_RETRACTED)); total=total+1
24
25 // 4) retracted is terminal: can't be quietly resurrected/edited
26 let re: i64 = cmt_edit(rec, 80)
27 pass = pass + g_check("retracted message can't be sneakily re-edited (terminal)" as *u8, (re == 0) & (cmt_marker(rec) == CMT_RETRACTED)); total=total+1
28
29 // 5) transparency invariant: any mutation always carries a marker (recipient never deceived)
30 let a: *i64 = sys_mmap(4*8) as *i64; cmt_init(a, 10); cmt_edit(a, 12)
31 let b: *i64 = sys_mmap(4*8) as *i64; cmt_init(b, 10); cmt_retract(b)
32 let c: *i64 = sys_mmap(4*8) as *i64; cmt_init(c, 10) // untouched -> honestly LIVE, no marker
33 var r5: i64 = 1
34 if cmt_marker(a) == CMT_LIVE { r5 = 0 } // an edited msg must NOT look pristine
35 if cmt_marker(b) == CMT_LIVE { r5 = 0 } // a retracted msg must NOT look pristine
36 if cmt_marker(c) != CMT_LIVE { r5 = 0 } // an untouched msg stays clean (no false marker)
37 if cmt_is_honest(a) != 1 { r5 = 0 }
38 if cmt_is_honest(b) != 1 { r5 = 0 }
39 pass = pass + g_check("transparency: mutated msgs always show a marker; clean msgs stay clean" as *u8, r5); total=total+1
40
41 g_puts("---- chatmut gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
42 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
43 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
44 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
45 let ctr__dry: *i64 = gv_ctr()
46 ctr__dry[0] = pass
47 ctr__dry[1] = total
48 let rc__dry: i64 = gv_verdict("CHATMUT-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
49 sys_exit(rc__dry)
50 return rc__dry
51}