code wiki / _hdl_build / nx_aid.nx
nx_aid.nx
buildroot/runtime/_hdl_build/nx_aid.nx
about
nx_aid.nx -- LIB: CHARITY ANTI-SCAM integrity (R-AID, pillar 4 of seed-to-feed). Operator: "the descamming
capabilities so that food banks and other charitable orgs can make sure that people in need get the food not
people exploiting it." An ADDITIVE, auditable aid ledger + exploit-pattern detection that DISTINGUISHES the
needy from exploiters WITHOUT ever punishing need.
TWO ETHICAL GUARANTEES, enforced by construction (not promised):
(A) PRIVACY-FIRST -- recipients are opaque tokens (rid), never PII. Sovereign data, not harvested.
(B) FAIL-OPEN -- the automated system NEVER auto-denies (ad_auto_deny == 0 for EVERYONE, always). It only
RAISES a risk level for a HUMAN to review. A false positive can never block a hungry person; a real
exploiter is surfaced for a person to decide. "People in need get the food; exploiters get reviewed."
Descam signals (all measured from the recorded ledger, data-driven thresholds in aid:policy -- rule 11):
- DUPLICATE: claiming from too many DISTINCT orgs within the period (double-dipping across charities).
- VOLUME: claim value in the period far exceeds the household's expected need.
- RESELLER: units in the period far exceed any household's use (a reselling signature).
Sovereign seg-store (knowledge/store/aid-*, NO TSV), integer-only. license_tier: ORIGINAL
dependencies 3 imports · 1 importers
imports: nx_food_science.nxnx_seg_store.nxnx_syscalls.nx
imported by: nx_aid_gate.nx
structs
| none |
consts
| 20 | const K_MAGIC_4096: i64 = 4096 |
functions
| 22 | func ad_put(prefix: *u8, key: *u8, val: *u8) -> i64 |
| 33 | func ad_seed_policy(prefix: *u8) -> i64 { return ad_put(prefix, "aid:policy" as *u8, "2\t30\t5000\t150\t20" as *u8) } |
| 34 | func ad_policy_int(prefix: *u8, f: i64) -> i64 |
| 44 | func ad_recip_key(rid: *u8, out: *u8) -> i64 { var o: i64 = 0; o = as_append(out, o, "aid:recip:" as *u8); o = as_append(out, o, rid); out[o] = 0 as u8; return o } |
| 45 | func ad_claimn_key(rid: *u8, out: *u8) -> i64 { var o: i64 = 0; o = as_append(out, o, "aid:claimn:" as *u8); o = as_append(out, o, rid); out[o] = 0 as u8; return o } |
| 46 | func ad_claim_key(rid: *u8, seq: i64, out: *u8) -> i64 |
| 53 | func ad_add_recipient(prefix: *u8, rid: *u8, household: i64, need_tier: i64, enrolled_day: i64, cite: *u8) -> i64 |
| 90 | func ad_recip_int(prefix: *u8, rid: *u8, f: i64) -> i64 |
| 100 | func ad_claimn(prefix: *u8, rid: *u8) -> i64 |
| 108 | func ad_record_claim(prefix: *u8, rid: *u8, oid: *u8, day: i64, value_cents: i64, units: i64, note: *u8) -> i64 |
| 125 | func ad_claim_str(prefix: *u8, rid: *u8, seq: i64, f: i64, out: *u8) -> i64 |
| 132 | func ad_claim_int(prefix: *u8, rid: *u8, seq: i64, f: i64) -> i64 called by 4: ad_in_periodad_value_in_periodad_units_in_periodmain calls 3: sys_mmapad_claim_strfd_atoi |
| 140 | func ad_in_period(prefix: *u8, rid: *u8, seq: i64, now_day: i64) -> i64 called by 3: ad_distinct_orgsad_value_in_periodad_units_in_period calls 2: ad_policy_intad_claim_int |
| 149 | func ad_distinct_orgs(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 166 | func ad_value_in_period(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 173 | func ad_units_in_period(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 182 | func ad_dup_flag(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 186 | func ad_expected_value(prefix: *u8, rid: *u8) -> i64 |
| 191 | func ad_volume_flag(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 196 | func ad_reseller_flag(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 205 | func ad_risk(prefix: *u8, rid: *u8, now_day: i64) -> i64 |
| 212 | func ad_auto_deny(prefix: *u8, rid: *u8, now_day: i64) -> i64 { return 0 } called by 1: main |
| 214 | func ad_needs_review(prefix: *u8, rid: *u8, now_day: i64) -> i64 { if ad_risk(prefix, rid, now_day) >= 1 { return 1 } return 0 } |
| 216 | func ad_risk_label(r: i64) -> *u8 called by 1: ad_render_review |
| 223 | func ad_render_review(prefix: *u8, now_day: i64, out: *u8) -> i64 |