code wiki / _hdl_build / nx_surrogate_gate.nx
nx_surrogate_gate.nx source
↩ module page · 68 lines · 5669 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"
10
11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
12" as *u8); return ok }
13func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
14func m_url(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_URL, u, gsl(u)) }
15func m_pop(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_POPUP, u, gsl(u)) }
16func m_glob(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_GLOBAL, u, gsl(u)) }
17func m_sel(t: *i64, u: *u8) -> i64 { return sg_match(t, SM_SELECTOR, u, gsl(u)) }
18
19func main() -> i64 {
20 gw("surrogate SOVEREIGN gate (data-driven action-ladder table: classify + graduate + heal; SSOT of the sandbox)\n" as *u8)
21 var pass: i64 = 0
22 var ttl: i64 = 0
23 let t: *i64 = sg_new(); sg_seed(t)
24 let seed_n: i64 = t[0]
25
26 // K1: seeded table populated
27 ttl=ttl+1; pass=pass+grow("K1 seed table populated (>=14 rules)\x00" as *u8, (seed_n >= 14) as i64)
28 // K2: GA4 collect URL -> synthesize a native Response (never a dropped beacon)
29 let r2: i64 = m_url(t, "https://region1.google-analytics.com/g/collect?v=2&tid=X" as *u8)
30 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))
31 // K3: window.open target (any) -> fake-window surrogate (wildcard under SM_POPUP)
32 let r3: i64 = m_pop(t, "https://ads.exo.co/popunder" as *u8)
33 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))
34 // K4: FuckAdBlock global -> source-replay stub (byte-exact toString)
35 let r4: i64 = m_glob(t, "FuckAdBlock" as *u8)
36 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))
37 // K5: bait selector -> leave-intact + bait_fill
38 let r5: i64 = m_sel(t, "div.ad-slot.top" as *u8)
39 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))
40 // K6: MATCH-KIND ISOLATION: the popup "*" wildcard must NOT match a network-URL query
41 let r6: i64 = m_url(t, "https://cdn.site.com/app.bundle.js" as *u8)
42 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)
43 // K7: a GLOBAL rule must not match a URL query of the same text
44 let r7: i64 = m_url(t, "https://x.com/FuckAdBlock/loader" as *u8)
45 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)
46 // K8: miner loader -> BLOCK (containment, no gate)
47 let r8: i64 = m_url(t, "https://x.co/lib/coinhive.min.js" as *u8)
48 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))
49 // K9: ACTION LADDER graduation on re-wall: block -> synthesize -> scrub -> allow (bounded)
50 let br: i64 = sg_addc(t, SM_URL, "/testgate" as *u8, SC_TRACK, SA_BLOCK, SK_NONE, 80, SO_SEEDED, "" as *u8)
51 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)
52 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))
53 // K10: HEAL learns a new tracker signature -> it then classifies to synthesize
54 let before: i64 = t[0]
55 sg_learn(t, SM_URL, "newtrack.example/pxl" as *u8, SC_TRACK, SK_RESPONSE, "type=cors" as *u8)
56 let lr: i64 = m_url(t, "https://newtrack.example/pxl?id=9" as *u8)
57 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))
58 // K11: sg_classify_url one-call entry sets action+kind
59 let oa: *i64 = sys_mmap(8) as *i64; let ok: *i64 = sys_mmap(8) as *i64
60 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)
61 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))
62 // K12: synthesize rules carry a non-empty surrogate aux payload (the sandbox needs it)
63 ttl=ttl+1; pass=pass+grow("K12 synthesize rule carries a surrogate payload\x00" as *u8, (sg_aux_len(t, r2) > 0) as i64)
64
65 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
66 if pass == ttl { gw("verdict=GREEN (surrogate keystone: data-driven classify + action-ladder + heal-learn; the SSOT the sandbox reads)\n" as *u8); sys_exit(0); return 0 }
67 gw("verdict=RED\n" as *u8); sys_exit(1); return 1
68}