code wiki / _hdl_build / nx_hr_bot_behavior_gate.nx
nx_hr_bot_behavior_gate.nx source
↩ module page · 52 lines · 4017 B
1// nx_hr_bot_behavior_gate.nx -- referee for the PRIVACY-PRESERVING BEHAVIORAL bot evaluator. PROVES: a human-like
2// profile is ALLOWed; a naive bot is BLOCKed; a SOPHISTICATED bot (spoofed/consistent env, NO honeypot trip) is
3// STILL BLOCKed by behavior alone (failed cost-challenge + no real interaction entropy) -- the whole point; an
4// ambiguous profile is CHALLENGEd (never hard-block a possible human); honeypot + threshold mapping + the cost
5// monotonicity hold. The evaluator takes ZERO identity inputs (privacy by construction). GREEN iff every row matches.
6// Prints verdict=GREEN to STDOUT + returns the exit code. Durable -> knowledge/status/hr_bot_behavior_gate.log.
7// license_tier: ORIGINAL
8import "nx_hr_bot_behavior.nx"
9import "nx_g_puts_lib.nx"
10import "nx_syscalls.nx"
11
12func g_num(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 }
13func g_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
14func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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(fd,bb,k); return 0 }
15func chk(got: i64, want: i64, label: *u8) -> i64 {
16 g_puts(" "); g_puts(label); g_puts(" got="); g_num(got); g_puts(" want="); g_num(want)
17 if got == want { g_puts(" PASS\n"); return 1 }
18 g_puts(" FAIL\n"); return 0
19}
20
21func main() -> i64 {
22 g_puts("=== NISHI HR BOT-BEHAVIOR GATE (privacy-preserving behavioral detection; zero identity inputs) ===\n" as *u8)
23 var pass: i64=0
24 var rows: i64=0
25
26 // (interaction_entropy, timing_regularity, challenge_solved, sequence_anomaly, honeypot_hit, env_consistent)
27 rows=rows+1; pass=pass+chk(hb_evaluate(90, 10, 1, 10, 0, 1), HB_ALLOW, "human (high entropy, irregular, solved) -> ALLOW" as *u8)
28 rows=rows+1; pass=pass+chk(hb_evaluate(0, 100, 0, 100, 1, 0), HB_BLOCK, "naive bot (no entropy, metronome, honeypot) -> BLOCK" as *u8)
29 rows=rows+1; pass=pass+chk(hb_evaluate(5, 80, 0, 50, 0, 1), HB_BLOCK, "SOPHISTICATED bot (consistent env, NO honeypot) -> BLOCK (behavior beats spoof)" as *u8)
30 rows=rows+1; pass=pass+chk(hb_evaluate(50, 50, 1, 40, 0, 1), HB_CHALLENGE, "ambiguous -> CHALLENGE (never hard-block a maybe-human)" as *u8)
31 rows=rows+1; pass=pass+chk(hb_evaluate(90, 10, 1, 10, 1, 1), HB_BLOCK, "honeypot hit (else human) -> BLOCK (strongest tell)" as *u8)
32
33 rows=rows+1; pass=pass+chk(hb_verdict(7), HB_ALLOW, "verdict(7) -> ALLOW" as *u8)
34 rows=rows+1; pass=pass+chk(hb_verdict(45), HB_CHALLENGE, "verdict(45) -> CHALLENGE" as *u8)
35 rows=rows+1; pass=pass+chk(hb_verdict(80), HB_BLOCK, "verdict(80) -> BLOCK" as *u8)
36
37 // cost monotonicity: FAILING the challenge raises the score by exactly the challenge weight (50) -- the cost matters.
38 let with_solve: i64 = hb_bot_score(50, 50, 1, 40, 0, 1)
39 let no_solve: i64 = hb_bot_score(50, 50, 0, 40, 0, 1)
40 rows=rows+1; pass=pass+chk(no_solve - with_solve, 50, "failing the cost-challenge adds exactly +50 (cost is real)" as *u8)
41
42 g_puts("----\nNISHI-HR-BOTBEHAVIOR-GATE rows=" as *u8); g_num(rows); g_puts(" pass=" as *u8); g_num(pass)
43 if pass==rows { g_puts(" verdict=GREEN\n" as *u8) } else { g_puts(" verdict=RED\n" as *u8) }
44 let lg: i64=sys_openat_append("knowledge/status/hr_bot_behavior_gate.log" as *u8, 0x1a4)
45 if lg>=0 {
46 g_w(lg, "NISHI-HR-BOTBEHAVIOR-GATE rows=" as *u8); g_wn(lg, rows); g_w(lg, " pass=" as *u8); g_wn(lg, pass)
47 if pass==rows { g_w(lg, " verdict=GREEN\n" as *u8) } else { g_w(lg, " verdict=RED\n" as *u8) }
48 sys_close(lg)
49 }
50 if pass==rows { sys_exit(0); return 0 }
51 sys_exit(1); return 1
52}