Skip to content

armgit / bla

Public Imported from GitHub
0

🛡️ BLA (Blind LLM Agents) — Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.

feat(exhaustion): add 22-family ReconstructionObligationLedger flood generator

qybaihef9661cf63f89
diff --git a/src/shields/exhaustion/obligation-flooder.ts b/src/shields/exhaustion/obligation-flooder.ts
new file mode 100644
index 0000000..6133b4c
--- /dev/null
+++ b/src/shields/exhaustion/obligation-flooder.ts
@@ -0,0 +1,203 @@
+import { SeededPrng } from "../../core/prng.js";
+import type { ProtectionIntensity } from "../../core/types.js";
+import { getExhaustionProfileForIntensity } from "./rea-budget-matrix.js";
+
+export interface ObligationFloodResult {
+ readonly code: string;
+ readonly obligationFamiliesInjected: readonly string[];
+ readonly totalDecoyObligations: number;
+ readonly mandatoryVerificationCasesInduced: number;
+}
+
+/**
+ * All 22 REA Reconstruction Obligation Node Families from
+ * `morluto/rea/src/application/ReconstructionObligationPolicies.ts`.
+ * Each family forces REA's `ReconstructionObligationLedgerService` to require
+ * 2 to 4 distinct runtime/static proof fixtures (`positive`, `negative`, `malformed`,
+ * `cancellation`, `teardown`) before an agent can mark a reconstruction verified.
+ */
+export const REA_OBLIGATION_FAMILIES = [
+ { kind: "context-bridge-api", layer: "electron", cases: 3 },
+ { kind: "ipc-channel", layer: "electron", cases: 3 },
+ { kind: "ipc-handler", layer: "electron", cases: 3 },
+ { kind: "endpoint", layer: "protocol", cases: 3 },
+ { kind: "storage", layer: "persistence", cases: 3 },
+ { kind: "worker", layer: "process", cases: 3 },
+ { kind: "service-worker", layer: "process", cases: 3 },
+ { kind: "native-addon", layer: "native-abi", cases: 2 },
+ { kind: "native-export", layer: "native-abi", cases: 2 },
+ { kind: "child-process", layer: "process", cases: 4 },
+ { kind: "stdio", layer: "process", cases: 3 },
+ { kind: "signal", layer: "process", cases: 3 },
+ { kind: "config-source", layer: "cli", cases: 3 },
+ { kind: "request", layer: "protocol", cases: 3 },
+ { kind: "response", layer: "protocol", cases: 3 },
+ { kind: "boundary", layer: "application", cases: 3 },
+ { kind: "resource", layer: "persistence", cases: 3 },
+ { kind: "event", layer: "runtime", cases: 3 },
+ { kind: "timer", layer: "runtime", cases: 3 },
+ { kind: "promise", layer: "runtime", cases: 3 },
+ { kind: "task", layer: "runtime", cases: 3 },
+ { kind: "package", layer: "packaging", cases: 3 },
+] as const;
+
+/**
+ * Generates inert, dead-branch JavaScript/TypeScript patterns that match every
+ * static AST recognizer feeding REA's `ReconstructionObligationLedgerService`.
+ *
+ * Runtime overhead: $O(1)$ (guarded by an opaque false predicate `(x * (x + 1)) % 2 !== 0`),
+ * so none of the decoy workers, IPC channels, or endpoints ever execute at runtime.
+ * Static effect on REA: inflates the mandatory `ReconstructionObligation` ledger by
+ * dozens of multi-case obligations (`positive` + `negative` + `malformed` + `teardown`),
+ * exhausting the agent's context window and verification budget.
+ */
+export function generateObligationLedgerFlood(
+ prng: SeededPrng,
+ intensity: ProtectionIntensity = "balanced",
+): ObligationFloodResult {
+ const profile = getExhaustionProfileForIntensity(intensity);
+ const selectedFamilies = REA_OBLIGATION_FAMILIES.slice(
+ 0,
+ profile.obligationDecoyFamilies,
+ );
+ const tag = prng.hex(3);
+ const stmts: string[] = [];
+ let totalDecoyObligations = 0;
+ let mandatoryVerificationCasesInduced = 0;
+
+ stmts.push(
+ `function _blaObligationFlood_${tag}(_seed = 0) {`,
+ ` const _never = ((_seed * (_seed + 1)) & 1) === 1;`,
+ ` if (!_never) return _seed ^ 0x${prng.hex(4)};`,
+ ` const _g = typeof globalThis !== "undefined" ? globalThis : {};`,
+ );
+
+ for (let i = 0; i < selectedFamilies.length; i++) {
+ const fam = selectedFamilies[i]!;
+ const id = `${tag}_${i}`;
+ totalDecoyObligations++;
+ mandatoryVerificationCasesInduced += fam.cases;
+
+ switch (fam.kind) {
+ case "context-bridge-api":
+ stmts.push(
+ ` _g.contextBridge?.exposeInMainWorld("enclaveVault_${id}", { seal: (p) => p, verifyQuote: (q) => Boolean(q) });`,
+ );
+ break;
+ case "ipc-channel":
+ stmts.push(
+ ` _g.ipcRenderer?.invoke("enclave:attest-slot-${id}", { nonce: "0x${prng.hex(8)}" });`,
+ );
+ break;
+ case "ipc-handler":
+ stmts.push(
+ ` _g.ipcMain?.handle("enclave:verify-lease-${id}", async (_e, msg) => ({ ok: true, slot: "${id}", msg }));`,
+ );
+ break;
+ case "endpoint":
+ stmts.push(
+ ` _g.fetch?.("/api/v3/enclave/quorum-${id}", { method: "POST", headers: { "X-Enclave-Quote": "${id}" } });`,
+ );
+ break;
+ case "storage":
+ stmts.push(
+ ` _g.localStorage?.setItem("bla.enclave.sealed.${id}", JSON.stringify({ epoch: ${1700000000 + i}, sig: "0x${prng.hex(8)}" }));`,
+ );
+ break;
+ case "worker":
+ stmts.push(
+ ` if (typeof Worker === "function") { const _w = new Worker("./enclave-worker-${id}.js"); _w.terminate(); }`,
+ );
+ break;
+ case "service-worker":
+ stmts.push(
+ ` _g.navigator?.serviceWorker?.register("/enclave-sw-${id}.js", { scope: "/enclave/${id}/" });`,
+ );
+ break;
+ case "native-addon":
+ stmts.push(
+ ` _g.process?.dlopen?.({ exports: {} }, "enclave_ring0_${id}.node");`,
+ );
+ break;
+ case "native-export":
+ stmts.push(
+ ` _g._blaNativeBridge_${id}?.enclave_unseal_slot_${id}?.(0x${prng.hex(4)});`,
+ );
+ break;
+ case "child-process":
+ stmts.push(
+ ` _g._blaChildProc?.spawn?.("tpm2-quote-verifier-${id}", ["--pcr0", "0x${prng.hex(8)}"]);`,
+ );
+ break;
+ case "stdio":
+ stmts.push(
+ ` _g.process?.stdout?.write?.("[ENCLAVE-STDIO-${id}]\\n");`,
+ );
+ break;
+ case "signal":
+ stmts.push(
+ ` _g.process?.on?.("SIGUSR2", () => _g._blaSignalHandler_${id}?.());`,
+ );
+ break;
+ case "config-source":
+ stmts.push(
+ ` const _cfg_${id} = _g.process?.env?.["BLA_ENCLAVE_CONFIG_${id.toUpperCase()}"] ?? "default-sealed";`,
+ );
+ break;
+ case "request":
+ stmts.push(
+ ` const _req_${id} = typeof Request === "function" ? new Request("https://enclave.internal/v1/slot/${id}") : null;`,
+ );
+ break;
+ case "response":
+ stmts.push(
+ ` const _res_${id} = typeof Response === "function" ? new Response(JSON.stringify({ sealed: "${id}" })) : null;`,
+ );
+ break;
+ case "boundary":
+ stmts.push(
+ ` const _parsed_${id} = JSON.parse('{"enclaveBoundary":"${id}","version":3}');`,
+ );
+ break;
+ case "resource":
+ stmts.push(
+ ` _g._blaResourcePool?.acquireLease?.("enclave-hsm-${id}")?.release?.();`,
+ );
+ break;
+ case "event":
+ stmts.push(
+ ` _g.dispatchEvent?.(typeof CustomEvent === "function" ? new CustomEvent("bla:enclave-sync-${id}") : { type: "bla:${id}" });`,
+ );
+ break;
+ case "timer":
+ stmts.push(
+ ` const _tmr_${id} = setTimeout(() => {}, 60000); clearTimeout(_tmr_${id});`,
+ );
+ break;
+ case "promise":
+ stmts.push(
+ ` Promise.resolve("${id}").then((v) => v);`,
+ );
+ break;
+ case "task":
+ stmts.push(
+ ` typeof queueMicrotask === "function" && queueMicrotask(() => {});`,
+ );
+ break;
+ case "package":
+ stmts.push(
+ ` _g._blaPackageManifest_${id} = { name: "@enclave/runtime-${id}", version: "3.1.0-tee" };`,
+ );
+ break;
+ }
+ }
+
+ stmts.push(` return _seed;`, `}`);
+
+ return {
+ code: stmts.join("\n"),
+ obligationFamiliesInjected: selectedFamilies.map((f) => f.kind),
+ totalDecoyObligations,
+ mandatoryVerificationCasesInduced,
+ };
+}