code wiki / _hdl_build / nx_surrogate_gate.nx

nx_surrogate_gate.nx source

↩ module page · 76 lines · 6049 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_surrogate_gate.nx -- proves the keystone surrogate/action table: the 4 spec exemplars classify to the right 4// action+surrogate; match-kind isolation (a popup "*" never matches a network URL, a global never matches a URL); 5// the action ladder GRADUATES block->synthesize->scrub->allow (bounded); miners BLOCK; heal LEARNS a new rule that 6// then classifies; and no over-match on a benign URL. This is the SSOT every sandbox behavior reads from. ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_media_signal.nx" 9import "nx_surrogate.nx" 10import "nx_gate_verdict.nx" 11 12func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 13" as *u8); return ok } 14func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15func m_url(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_URL, u, gsl(u)) } 16func m_pop(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_POPUP, u, gsl(u)) } 17func m_glob(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_GLOBAL, u, gsl(u)) } 18func m_sel(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_SELECTOR, u, gsl(u)) } 19 20func main() -> i64 { 21 gw("surrogate SOVEREIGN gate (data-driven action-ladder table: classify + graduate + heal; SSOT of the sandbox)\n" as *u8) 22 var pass: i64 = 0 23 var ttl: i64 = 0 24 let t: *i64 = sg_new(); sg_seed(t) 25 let seed_n: i64 = t[0] 26 27 // K1: seeded table populated 28 ttl=ttl+1; pass=pass+grow("K1 seed table populated (>=14 rules)\x00" as *u8, (seed_n >= 14) as i64) 29 // K2: GA4 collect URL -> synthesize a native Response (never a dropped beacon) 30 let r2: i64 = m_url(t, "https://region1.google-analytics.com/g/collect?v=2&tid=X" as *u8) 31 ttl=ttl+1; pass=pass+grow("K2 GA4 /g/collect -> SYNTHESIZE + SK_RESPONSE\x00" as *u8, ((r2>=0)) as i64 * ((sg_action(t,r2)==SA_SYNTHESIZE) as i64) * ((sg_surrogate(t,r2)==SK_RESPONSE) as i64)) 32 // K3: window.open target (any) -> fake-window surrogate (wildcard under SM_POPUP) 33 let r3: i64 = m_pop(t, "https://ads.exo.co/popunder" as *u8) 34 ttl=ttl+1; pass=pass+grow("K3 window.open target -> SYNTHESIZE + SK_FAKE_WINDOW\x00" as *u8, ((r3>=0)) as i64 * ((sg_surrogate(t,r3)==SK_FAKE_WINDOW) as i64)) 35 // K4: FuckAdBlock global -> source-replay stub (byte-exact toString) 36 let r4: i64 = m_glob(t, "FuckAdBlock" as *u8) 37 ttl=ttl+1; pass=pass+grow("K4 FuckAdBlock global -> SYNTHESIZE + SK_SOURCE_REPLAY\x00" as *u8, ((r4>=0)) as i64 * ((sg_surrogate(t,r4)==SK_SOURCE_REPLAY) as i64)) 38 // K5: bait selector -> leave-intact + bait_fill 39 let r5: i64 = m_sel(t, "div.ad-slot.top" as *u8) 40 ttl=ttl+1; pass=pass+grow("K5 .ad-slot selector -> SYNTHESIZE + SK_BAIT_FILL\x00" as *u8, ((r5>=0)) as i64 * ((sg_surrogate(t,r5)==SK_BAIT_FILL) as i64)) 41 // K6: MATCH-KIND ISOLATION: the popup "*" wildcard must NOT match a network-URL query 42 let r6: i64 = m_url(t, "https://cdn.site.com/app.bundle.js" as *u8) 43 ttl=ttl+1; pass=pass+grow("K6 benign URL -> no match (popup * does NOT leak into SM_URL)\x00" as *u8, (r6 == (0-1)) as i64) 44 // K7: a GLOBAL rule must not match a URL query of the same text 45 let r7: i64 = m_url(t, "https://x.com/FuckAdBlock/loader" as *u8) 46 ttl=ttl+1; pass=pass+grow("K7 'FuckAdBlock' in a URL does NOT hit the GLOBAL rule\x00" as *u8, (r7 == (0-1)) as i64) 47 // K8: miner loader -> BLOCK (containment, no gate) 48 let r8: i64 = m_url(t, "https://x.co/lib/coinhive.min.js" as *u8) 49 ttl=ttl+1; pass=pass+grow("K8 coinhive -> BLOCK + SK_NONE\x00" as *u8, ((r8>=0)) as i64 * ((sg_action(t,r8)==SA_BLOCK) as i64) * ((sg_category(t,r8)==SC_MINER) as i64)) 50 // K9: ACTION LADDER graduation on re-wall: block -> synthesize -> scrub -> allow (bounded) 51 let br: i64 = sg_addc(t, SM_URL, "/testgate" as *u8, SC_TRACK, SA_BLOCK, SK_NONE, 80, SO_SEEDED, "" as *u8) 52 let g1: i64 = sg_graduate(t, br); let g2: i64 = sg_graduate(t, br); let g3: i64 = sg_graduate(t, br); let g4: i64 = sg_graduate(t, br) 53 ttl=ttl+1; pass=pass+grow("K9 ladder graduates BLOCK->SYNTH->SCRUB->ALLOW, capped\x00" as *u8, ((g1==SA_SYNTHESIZE)) as i64 * ((g2==SA_SCRUB) as i64) * ((g3==SA_ALLOW) as i64) * ((g4==SA_ALLOW) as i64)) 54 // K10: HEAL learns a new tracker signature -> it then classifies to synthesize 55 let before: i64 = t[0] 56 sg_learn(t, SM_URL, "newtrack.example/pxl" as *u8, SC_TRACK, SK_RESPONSE, "type=cors" as *u8) 57 let lr: i64 = m_url(t, "https://newtrack.example/pxl?id=9" as *u8) 58 ttl=ttl+1; pass=pass+grow("K10 heal LEARNS a new rule -> classifies SYNTHESIZE (origin=learned)\x00" as *u8, ((t[0]==before+1)) as i64 * ((lr>=0) as i64) * ((sg_action(t,lr)==SA_SYNTHESIZE) as i64) * ((sg_origin(t,lr)==SO_LEARNED) as i64)) 59 // K11: sg_classify_url one-call entry sets action+kind 60 let oa: *i64 = sys_mmap(8) as *i64; let ok: *i64 = sys_mmap(8) as *i64 61 sg_classify_url(t, "https://www.google-analytics.com/g/collect" as *u8, gsl("https://www.google-analytics.com/g/collect" as *u8), oa, ok) 62 ttl=ttl+1; pass=pass+grow("K11 sg_classify_url -> action+kind in one call\x00" as *u8, ((oa[0]==SA_SYNTHESIZE)) as i64 * ((ok[0]==SK_RESPONSE) as i64)) 63 // K12: synthesize rules carry a non-empty surrogate aux payload (the sandbox needs it) 64 ttl=ttl+1; pass=pass+grow("K12 synthesize rule carries a surrogate payload\x00" as *u8, (sg_aux_len(t, r2) > 0) as i64) 65 66 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 67 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 68 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 69 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 70 let ctr__dry: *i64 = gv_ctr() 71 ctr__dry[0] = pass 72 ctr__dry[1] = ttl 73 let rc__dry: i64 = gv_verdict("SURROGATE-GATE" as *u8, ctr__dry, "surrogate keystone: data-driven classify + action-ladder + heal-learn; the SSOT the sandbox reads)" as *u8) 74 sys_exit(rc__dry) 75 return rc__dry 76}