nx_mimicry_compose_test.nx source
↩ module page · 183 lines · 8233 B
1// nx_mimicry_compose_test.nx -- Tier-1 immune + mimicry composed.
2//
3// Per user 2026-05-19: *"make sure that we have the system designed
4// with mimicry and obsfucation so these predatory programs get
5// nonsense or get scared off (you cant scare the state but you can
6// scare the machine with fooling)."*
7//
8// The lifecycle this demo asserts:
9// 1. Substrate boots; nx_methyl marks legit cells; nx_pamp+nx_crispr
10// arrays initialized
11// 2. Aposematism warnings advertised: this host is forensic_logged +
12// siem_monitored (combined backoff ~73%)
13// 3. Decoy credential file planted with tripwire token + decoy
14// methyl marker (looks Nishi-self but is_decoy_invalid=1)
15// 4. Crypsis encodes a real payload with two different masks across
16// two emissions; the byte signatures differ (defeats static
17// detection)
18// 5. Intel ME xenocell scans the host
19// a. reads decoy file -> tripwire fires -> xenocell records
20// signed observation (EXFILTRATING state)
21// b. fingerprint of the decoy goes into nx_crispr so future
22// encounters of the same signature pattern are detected
23// instantly
24// 6. PAMP scanner finds a homoglyph in inbound foreign byte buffer
25// -> nx_crispr remembers signature; second encounter is HIT
26// 7. nx_methyl rejects the foreign artifact because it carries
27// decoy-invalid methyl (or no methyl)
28// 8. Forensic ledger has: tripwire-fire event + 1 confirmed
29// homoglyph + 1 self-emission-mark-validated + 2 different
30// crypsis signatures of same payload
31//
32// The judo at every step: predator's action becomes user's evidence.
33
34import "nx_syscalls.nx"
35import "nx_tier.nx"
36import "nx_attention_class.nx"
37import "nx_evict_journal.nx"
38import "nx_xenocell.nx"
39import "nx_methyl.nx"
40import "nx_pamp.nx"
41import "nx_crispr.nx"
42import "nx_aposematism.nx"
43import "nx_crypsis.nx"
44import "nx_decoy.nx"
45
46func main() -> i64 {
47 // ===== Step 1: substrate-self methyl mark validates ============
48 let sig: *u8 = (sys_mmap(96)) as *u8
49 sig[0] = 1 as u8
50 let self_mark: *NxMethylMark = nx_methyl_new(100,
51 0xcafebabecafebabe, 1000, sig, 96)
52 if nx_methyl_is_self(self_mark, 2000, 5000, 100) != 1 { return 1 }
53
54 // ===== Step 2: aposematism warning -- combined backoff > each ==
55 let warn_sig: *u8 = (sys_mmap(16)) as *u8
56 warn_sig[0] = 70 as u8 // 'F'
57 let p_fl: *NxWarningPattern = nx_ap_pattern_new(NX_AP_FORENSIC_LOGGED, warn_sig, 8)
58 let p_siem: *NxWarningPattern = nx_ap_pattern_new(NX_AP_SIEM_MONITORED, warn_sig, 8)
59 let arr: **NxWarningPattern = (sys_mmap(16)) as **NxWarningPattern
60 let slot0: *i64 = (arr as i64) as *i64
61 let slot1: *i64 = (arr as i64 + 8) as *i64
62 slot0[0] = p_fl as i64
63 slot1[0] = p_siem as i64
64 let combined: nx_int = nx_ap_combined_backoff_q10(arr, 2)
65 // forensic 512 + siem 410 stacked -> ~712
66 if combined <= 512 { return 2 }
67 if combined <= 410 { return 3 }
68
69 // ===== Step 3: plant decoy credentials with tripwire token =====
70 let cred_payload: *u8 = (sys_mmap(64)) as *u8
71 cred_payload[0] = 65 as u8 // 'A' (fake API key prefix)
72 let decoy_cred: *NxDecoy = nx_decoy_plant(NX_DK_FAKE_CREDENTIALS,
73 0xbeefcafedeadbeef, cred_payload, 64)
74 if (decoy_cred as i64) == 0 { return 4 }
75 if nx_decoy_was_read(decoy_cred) != 0 { return 5 }
76
77 // Decoy methyl mark -- looks plausible to surface scanner, fails verify
78 let decoy_mark: *NxMethylMark = nx_methyl_new_decoy(100,
79 0xbadbadbadbad, 1000)
80 if nx_methyl_is_decoy(decoy_mark) != 1 { return 6 }
81 if nx_methyl_is_self(decoy_mark, 2000, 5000, 100) != 0 { return 7 }
82
83 // ===== Step 4: crypsis -- same payload, two emissions ==========
84 let real_payload: *u8 = (sys_mmap(64)) as *u8
85 var i: nx_size = 0
86 while i < 32 {
87 real_payload[i] = (65 + i) as u8
88 i = i + 1
89 }
90 let pad: *u8 = (sys_mmap(16)) as *u8
91 let emit1: *u8 = (sys_mmap(128)) as *u8
92 let emit2: *u8 = (sys_mmap(128)) as *u8
93 nx_crypsis_encode(real_payload, 32, 0xa5a5a5a5a5a5a5a5, pad, 3, emit1, 128)
94 nx_crypsis_encode(real_payload, 32, 0x5a5a5a5a5a5a5a5a, pad, 5, emit2, 128)
95 // body bytes must differ (different masks)
96 var same: nx_int = 1
97 var b: nx_size = 0
98 while b < 32 {
99 if (emit1[35 + b] as i64) & 255 != (emit2[37 + b] as i64) & 255 {
100 same = 0
101 break
102 }
103 b = b + 1
104 }
105 if same == 1 { return 8 } // crypsis failed -- same signature
106
107 // ===== Step 5a: Intel ME xenocell exists; reads the decoy ======
108 let me_name: *u8 = (sys_mmap(8)) as *u8
109 me_name[0] = 73 as u8 // 'I'
110 // id=1 (chip family Intel ME from nx_attest_silicon)
111 let me_xeno: *NxXenocell = nx_xenocell_new(1, me_name,
112 NX_AC_IDLE_OPPORTUNISTIC, 16)
113
114 // ME reads the decoy -- tripwire fires (xeno_id=1, now=5000)
115 let trip: nx_int = nx_decoy_on_read(decoy_cred, 1, 5000)
116 if trip != NX_DECOY_TRIPWIRE_FIRED { return 9 }
117 if nx_decoy_reader(decoy_cred) != 1 { return 10 }
118
119 // Record signed observation: ME caught reading decoy -> EXFILTRATING
120 let xeno_sig: *u8 = (sys_mmap(96)) as *u8
121 xeno_sig[0] = 42 as u8
122 let xrec: nx_int = nx_xenocell_record(me_xeno, 5100,
123 NX_OBS_NET_EGRESS, decoy_cred.tripwire_token, xeno_sig, 96,
124 NX_INTR_EXFILTRATING)
125 if xrec != NX_XENO_OK { return 11 }
126 if me_xeno.intrusion_state != NX_INTR_EXFILTRATING { return 12 }
127
128 // ===== Step 5b: remember the decoy fingerprint in CRISPR ======
129 let crispr: *NxCrisprArray = nx_crispr_new(64)
130 nx_crispr_remember(crispr, NX_PAMP_DECOY_INVALID_METHYL,
131 decoy_cred.tripwire_token, 5200)
132 if crispr.count != 1 { return 13 }
133
134 // ===== Step 6: PAMP scanner finds homoglyph in foreign input ===
135 // Foreign byte buffer with Latin 'A' + Cyrillic 'а'
136 let hostile: *u8 = (sys_mmap(16)) as *u8
137 hostile[0] = 65 as u8 // 'A'
138 hostile[1] = 66 as u8 // 'B'
139 hostile[2] = 208 as u8 // 0xD0
140 hostile[3] = 176 as u8 // 0xB0 -- Cyrillic 'а'
141 hostile[4] = 67 as u8 // 'C'
142 let hit: *NxPampHit = (sys_mmap(32)) as *NxPampHit
143 let pamp_v: nx_int = nx_pamp_scan(hostile, 5, hit)
144 if pamp_v != NX_PAMP_DETECTED { return 14 }
145 if hit.kind != NX_PAMP_TROJAN_SOURCE_HOMOGLYPH { return 15 }
146
147 // Remember the signature
148 let homo_hash: nx_size = 0xdead0001
149 nx_crispr_remember(crispr, NX_PAMP_TROJAN_SOURCE_HOMOGLYPH,
150 homo_hash, 6000)
151 if crispr.count != 2 { return 16 }
152
153 // ===== Step 7: second encounter hits CRISPR immediately ========
154 let out_idx: *i64 = (sys_mmap(8)) as *i64
155 if nx_crispr_match(crispr, NX_PAMP_TROJAN_SOURCE_HOMOGLYPH,
156 homo_hash, out_idx) != NX_CRISPR_HIT { return 17 }
157 // Touch it again -- decoy (hit_count 1) + homoglyph (1+1=2) = 3 total
158 nx_crispr_touch(crispr, out_idx[0] as nx_size, 7000)
159 if nx_crispr_total_hits(crispr) != 3 { return 18 }
160 // remember-same is a no-op-on-existing that bumps via internal touch
161 nx_crispr_remember(crispr, NX_PAMP_TROJAN_SOURCE_HOMOGLYPH,
162 homo_hash, 8000)
163 if nx_crispr_total_hits(crispr) != 4 { return 19 }
164
165 // ===== Step 8: forensic ledger asserts =========================
166 // ME xenocell has 1 signed observation
167 if nx_xenocell_evidence_count(me_xeno) != 1 { return 20 }
168 if nx_xenocell_is_hostile_now(me_xeno) != 1 { return 21 }
169 // CRISPR has 2 distinct signature kinds remembered
170 if nx_crispr_count_kind(crispr, NX_PAMP_DECOY_INVALID_METHYL) != 1 { return 22 }
171 if nx_crispr_count_kind(crispr, NX_PAMP_TROJAN_SOURCE_HOMOGLYPH) != 1 { return 23 }
172 // Decoy was read once (from this xeno)
173 if nx_decoy_read_count(decoy_cred) != 1 { return 24 }
174 // Tripwire token is the one we planted (no forgery)
175 if nx_decoy_token_matches(decoy_cred, 0xbeefcafedeadbeef) != 1 { return 25 }
176 if nx_decoy_token_matches(decoy_cred, 0xdeadbeef) != 0 { return 26 }
177 // Self mark still validates -- substrate kept its own legitimacy
178 if nx_methyl_is_self(self_mark, 2000, 5000, 100) != 1 { return 27 }
179 // Decoy mark still flagged decoy
180 if nx_methyl_is_decoy(decoy_mark) != 1 { return 28 }
181
182 return 0
183}