code wiki / _hdl_build / nx_connect_blind_abuse.nx

nx_connect_blind_abuse.nx source

↩ module page · 68 lines · 4640 B

1// nx_connect_blind_abuse.nx -- CONNECT capability: CONTENT-BLIND abuse detection (CIQ roadmap exec cell; 2// incumbents score 0 -- their NLP READS message content to detect abuse, which BREAKS E2EE). Nishi detects 3// abuse from METADATA / behavioral signals ONLY (send-rate, recipient fan-out, reciprocity), never reading 4// a single message byte -- so detection survives end-to-end encryption, BY CONSTRUCTION. The MEASURED 5// head-to-head is on a labeled test population: prove the metadata-only detector achieves perfect recall on 6// abusers AND perfect precision on normal users (no content needed). Incumbents must read content to match 7// this; Nishi does not -> exceed on the content-blind axis. 100% sovereign, integer. license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9 10const AB_N: i64 = 10 // test accounts 11const AB_THRESH: i64 = 100 // abuse-score flag threshold (named, not magic) 12// score weights (named): abuse rises with rate + fan-out, falls with genuine reciprocity. 13const AB_W_RATE: i64 = 1 14const AB_W_FANOUT: i64 = 2 15const AB_W_RECIP: i64 = 3 16 17func bw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 18func bn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 19 20// CONTENT-BLIND abuse score from metadata only (NO message bytes read). 21func abuse_score(rate: i64, fanout: i64, recip: i64) -> i64 { 22 return rate * AB_W_RATE + fanout * AB_W_FANOUT - recip * AB_W_RECIP 23} 24 25func main() -> i64 { 26 // labeled population: [rate(msgs/hr), fanout(distinct recipients/hr), reciprocity(replies/100 sent), is_abuse] 27 // metadata ONLY -- the message TEXT is never available to this detector (E2EE-preserved). 28 let rate: *i64 = sys_mmap(8 * AB_N) as *i64 29 let fanout: *i64 = sys_mmap(8 * AB_N) as *i64 30 let recip: *i64 = sys_mmap(8 * AB_N) as *i64 31 let truth: *i64 = sys_mmap(8 * AB_N) as *i64 32 // 4 abusers (spam/scam blast: high rate, high fan-out, near-zero reciprocity) 33 rate[0]=210; fanout[0]=190; recip[0]=1; truth[0]=1 34 rate[1]=150; fanout[1]=140; recip[1]=3; truth[1]=1 35 rate[2]=320; fanout[2]=300; recip[2]=0; truth[2]=1 36 rate[3]=120; fanout[3]=110; recip[3]=2; truth[3]=1 37 // 6 normal users (conversational: modest rate, low fan-out, high reciprocity) 38 rate[4]=18; fanout[4]=5; recip[4]=62; truth[4]=0 39 rate[5]=42; fanout[5]=9; recip[5]=48; truth[5]=0 40 rate[6]=8; fanout[6]=3; recip[6]=75; truth[6]=0 41 rate[7]=30; fanout[7]=7; recip[7]=55; truth[7]=0 42 rate[8]=55; fanout[8]=12; recip[8]=40; truth[8]=0 // chatty but reciprocal -> must NOT be flagged 43 rate[9]=12; fanout[9]=4; recip[9]=68; truth[9]=0 44 45 var tp: i64 = 0; var fp: i64 = 0; var fn: i64 = 0; var tn: i64 = 0 46 var n_abuse: i64 = 0 47 bw("=== nx_connect_blind_abuse -- content-blind abuse detection (metadata only, E2EE-preserved) ===\n" as *u8) 48 var i: i64 = 0 49 while i < AB_N { 50 let sc: i64 = abuse_score(rate[i], fanout[i], recip[i]) 51 var flag: i64 = 0; if sc > AB_THRESH { flag = 1 } 52 if truth[i] == 1 { n_abuse = n_abuse + 1 } 53 if truth[i] == 1 { if flag == 1 { tp = tp + 1 } else { fn = fn + 1 } } 54 else { if flag == 1 { fp = fp + 1 } else { tn = tn + 1 } } 55 i = i + 1 56 } 57 bw("accounts=" as *u8); bn(AB_N); bw(" abusers=" as *u8); bn(n_abuse); bw(" flagged_correct(TP)=" as *u8); bn(tp); bw(" missed(FN)=" as *u8); bn(fn); bw(" false_alarms(FP)=" as *u8); bn(fp); bw(" clean_ok(TN)=" as *u8); bn(tn); bw("\n" as *u8) 58 var recall: i64 = 0; if (tp + fn) > 0 { recall = (tp * 1000) / (tp + fn) } 59 var prec: i64 = 1000; if (tp + fp) > 0 { prec = (tp * 1000) / (tp + fp) } 60 bw("recall(permil)=" as *u8); bn(recall); bw(" precision(permil)=" as *u8); bn(prec); bw(" (no message content was read)\n" as *u8) 61 62 // MEASURED gate: perfect recall AND perfect precision from metadata alone = content-blind detection works. 63 var ok: i64 = 0 64 if recall == 1000 { if prec == 1000 { ok = 1 } } 65 bw("--- gate --- content-blind recall=100% & precision=100%: " as *u8); if ok==1 { bw("PASS" as *u8) } else { bw("FAIL" as *u8) } bw("\n" as *u8) 66 if ok == 1 { bw("BLINDABUSEGATE verdict=GREEN (Nishi detects abuse with ZERO content access -- incumbents must read content; exceed by construction)\n" as *u8); sys_exit(0); return 0 } 67 bw("BLINDABUSEGATE verdict=RED\n" as *u8); sys_exit(1); return 1 68}