code wiki / _hdl_build / nx_chatmut_gate.nx
nx_chatmut_gate.nx source
↩ module page · 43 lines · 2531 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"
5
6func main() -> i64 {
7 g_puts("nx_chatmut gate (polite/transparent edit + retract -- no sneakiness)\n" as *u8)
8 var pass: i64 = 0; var total: i64 = 0
9 let rec: *i64 = sys_mmap(4*8) as *i64
10 cmt_init(rec, 40)
11
12 // 1) edit is visible + counted (no silent rewrite)
13 cmt_edit(rec, 35)
14 pass = pass + g_check("edit -> marked 'edited' + counted (transparent history)" as *u8, (cmt_marker(rec) == CMT_EDITED) & (rec[1] == 1)); total=total+1
15
16 // 2) multiple edits keep honest history
17 cmt_edit(rec, 50)
18 pass = pass + g_check("edits accumulate in the history count (no hidden edits)" as *u8, rec[1] == 2); total=total+1
19
20 // 3) retract removes content but leaves a visible tombstone (NOT a stealth delete)
21 cmt_retract(rec)
22 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
23
24 // 4) retracted is terminal: can't be quietly resurrected/edited
25 let re: i64 = cmt_edit(rec, 80)
26 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
27
28 // 5) transparency invariant: any mutation always carries a marker (recipient never deceived)
29 let a: *i64 = sys_mmap(4*8) as *i64; cmt_init(a, 10); cmt_edit(a, 12)
30 let b: *i64 = sys_mmap(4*8) as *i64; cmt_init(b, 10); cmt_retract(b)
31 let c: *i64 = sys_mmap(4*8) as *i64; cmt_init(c, 10) // untouched -> honestly LIVE, no marker
32 var r5: i64 = 1
33 if cmt_marker(a) == CMT_LIVE { r5 = 0 } // an edited msg must NOT look pristine
34 if cmt_marker(b) == CMT_LIVE { r5 = 0 } // a retracted msg must NOT look pristine
35 if cmt_marker(c) != CMT_LIVE { r5 = 0 } // an untouched msg stays clean (no false marker)
36 if cmt_is_honest(a) != 1 { r5 = 0 }
37 if cmt_is_honest(b) != 1 { r5 = 0 }
38 pass = pass + g_check("transparency: mutated msgs always show a marker; clean msgs stay clean" as *u8, r5); total=total+1
39
40 g_puts("---- chatmut gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8)
41 if pass == total { g_puts("verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
42 g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1
43}