code wiki / (root) / nx_adversarial_pattern_audit.nx

nx_adversarial_pattern_audit.nx

buildroot/runtime/nx_adversarial_pattern_audit.nx

20751 B466 linesdepth 3pulls 4 transitivereach 1 importersview sourcekind librarytopic adversarial
docsdependenciesstructsconstsfunctions

about

nx_adversarial_pattern_audit.nx -- scans for adversarial-exploit patterns. module: nishi-core.security.adversarial_pattern_audit depends: nishi-core.security.threat_model, nishi-core.audit.wired_status, nishi-core.audit.claim_audit, nishi-core.io.syscalls disk_kb: 6 capability: CRYPTO wired_status: FULLY_WIRED (Honest: substrate STRUCTURE + the FALSE_OK_RETURN-class heuristic counter are wired AND smoke-verified via runtime/nx_adversarial_pattern_audit_test.nx PASS on qemu-rv64. The counter is a substring-based observation primitive that counts `_STUB_NOT_WIRED` markers + `wired_status:` headers per file; smoke asserts known counts on three runtime files. The FALSE_OK_RETURN substring detector is the WIRED kernel today; other 13 pattern-detectors in the 14-class taxonomy remain HEURISTIC_QUEUED. Per-file tree-walking via nx_dir is queued pending syscall-module unification -- nx_dir imports `syscalls.nx` while threat_model+wired_status+claim_audit import `nx_syscalls.nx`, and both define `sys_read_file` so they cannot link together. Caller passes pre-read bytes for now.) license_tier: PUBLIC_NISHI_SUBSTRATE genealogy_id: nishi_racing_crew_team_honesty_threat_aware_cardinal + cert_secure_coding_standards + misra_c_2012_safety_critical_rules + nasa_jpl_power_of_10 Per cardinal [[feedback-racing-crew-team-honesty-threat-aware]]: substrate scanner extends nx_claim_audit with patterns specifically dangerous when an adversary (especially AI-class) can read the substrate code looking for exploitable false-OK paths. Catches the exact failure pattern that triggered the no-false-OK cardinal: - function declares "fetch resource X" + returns *_OK from uninitialized verdict field → AI adversary writes caller code

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_threat_model.nx nx_wired_status.nx nx_adversarial_pattern_audit.n nx_adversarial_pattern_audit_test.

imports: nx_syscalls.nxnx_threat_model.nxnx_wired_status.nx

imported by: nx_adversarial_pattern_audit_test.nx

structs

131struct AdversarialFinding
180struct AdversarialScanReport
275struct ApaFileScanCounts

consts

59const NX_APA_OK: i64 = 1
60const NX_APA_PATTERN_DETECTED: i64 = 2
61const NX_APA_CRITICAL_VULNERABILITY: i64 = 3
62const NX_APA_SCAN_FAIL: i64 = 4
63const NX_APA_STUB_NOT_WIRED: i64 = -7777 // honest stub-variant per cardinal
76const NX_APA_PATTERN_FALSE_OK_RETURN: i64 = 1 // function returns *_OK from no-op body
77const NX_APA_PATTERN_MISSING_STUB_VARIANT: i64 = 2 // sealed enum lacks *_STUB_NOT_WIRED
78const NX_APA_PATTERN_UNINITIALIZED_VERDICT: i64 = 3 // verdict field reads OK by default-init
79const NX_APA_PATTERN_SILENT_ERROR_SWALLOW: i64 = 4 // catch + ignore error
80const NX_APA_PATTERN_CLAIM_BODY_MISMATCH: i64 = 5 // header claims X; body does Y
81const NX_APA_PATTERN_TLS_DOWNGRADE_PATH: i64 = 6 // fallback to plaintext possible
82const NX_APA_PATTERN_AUTH_BYPASS_PATH: i64 = 7 // codepath skips auth check
83const NX_APA_PATTERN_TIMING_LEAK: i64 = 8 // variable-time crypto compare
84const NX_APA_PATTERN_INTEGER_OVERFLOW: i64 = 9 // unchecked arithmetic
85const NX_APA_PATTERN_UNBOUNDED_LOOP: i64 = 10 // violates JPL Rule 2
86const NX_APA_PATTERN_DESERIALIZE_UNTRUSTED: i64 = 11 // parses untrusted data without bounds
87const NX_APA_PATTERN_PROMPT_INJECTION_TRUST: i64 = 12 // executes instructions from ingested data
88const NX_APA_PATTERN_HARDCODED_CREDENTIAL: i64 = 13 // API key / secret in source
89const NX_APA_PATTERN_THIRD_PARTY_SAAS_LEAK: i64 = 14 // new external SaaS dep detected
144const NX_ADV_FINDING_BYTES: i64 = 80 // 10 fields * 8 bytes
150const NX_APA_MAX_FINDINGS_PER_FILE: i64 = 1024
193const NX_ADV_SCAN_REPORT_BYTES: i64 = 80 // 10 fields * 8 bytes
199const NX_APA_ACTION_FIX_IMMEDIATELY: i64 = 1 // critical; block commits
200const NX_APA_ACTION_FIX_THIS_SESSION: i64 = 2 // high; on session backlog
201const NX_APA_ACTION_QUEUE_FIX: i64 = 3 // medium; queued
202const NX_APA_ACTION_DOCUMENT_AS_RESIDUAL: i64 = 4 // low; document the residual risk
203const NX_APA_ACTION_ACCEPT_RISK: i64 = 5 // not applicable to substrate's threat model
229const NX_APA_MAX_SCAN_BYTES: i64 = 8388608 // 8 MiB / file ceiling
290const NX_APA_FILE_SCAN_COUNTS_BYTES: i64 = 104 // 13 fields * 8 bytes
416const NX_APA_CONSISTENCY_NOT_VERIFIED: i64 = 0
417const NX_APA_CONSISTENCY_CONSISTENT: i64 = 1
418const NX_APA_CONSISTENCY_OVERSTATED: i64 = 2
419const NX_APA_CONSISTENCY_UNDERSTATED: i64 = 3
433const NX_APA_STUB_USAGE_THRESHOLD: i64 = 3

functions

65func nx_apa_verdict_name(v: i64) -> *u8
91func nx_apa_pattern_name(p: i64) -> *u8
111func nx_apa_pattern_severity_min_threat_tier(p: i64) -> i64
152func nx_adversarial_scan_file(
205func nx_apa_action_for_severity(severity_tier: i64) -> i64
212func nx_apa_action_name(a: i64) -> *u8
231func nx_apa_count_substring(
296func nx_apa_make_needle_stub(out: *u8)
304func nx_apa_make_needle_partial(out: *u8)
315func nx_apa_make_needle_fully(out: *u8)
326func nx_apa_make_needle_honest(out: *u8)
337func nx_apa_make_needle_funcdecl(out: *u8)
343func nx_apa_make_needle_return_nx(out: *u8)
352func nx_apa_scan_file_returns(
421func nx_apa_consistency_name(c: i64) -> *u8
435func nx_apa_judge_file_consistency(s: *ApaFileScanCounts) -> i64
called by 1: main