🛡️ 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.
JavaScript adversarial-aiclaude-codecursorelectron-securityllm-securitymcpmcp-serverobfuscationreverse-engineeringwebassembly
Red/Blue round-12 · Blue
qybaiheaab9b25fa720
diff --git a/.agents/skills/blind-llm-agents/SKILL.md b/.agents/skills/blind-llm-agents/SKILL.mdindex d98dcd8..97c6d0e 100644--- a/.agents/skills/blind-llm-agents/SKILL.md+++ b/.agents/skills/blind-llm-agents/SKILL.md@@ -7,7 +7,7 @@ description: >Agents). Prefer this skill as the guide; call existing MCP tools / CLI — do not inventnew MCP tools. Default verb: bla_harden. Refuse crack/RE of third-party software.metadata:- version: "1.5.20"+ version: "1.5.21"---# BLA: Blind LLM Agents@@ -24,7 +24,7 @@ model misjudgment on proprietary logic, or **one-click / ä¸€é”®ĺŠ ĺ›ş** a build.Defensive only: protect **their own** artifacts. Refuse crack, RE, bypass PoCs, orattack playbooks against software they do not own.-**Principles (red-blue round-1+2+3+4+5+6+7+7b+8+9+10+11):** do not ship a stable public WASM ABI without an explicit `wasm_preserve_exports` list; do not leave JS-side independent lane tables — prefer whole-key chained mixing (`bla_lint_lanes` / harden refuse). **Do not** place plaintext seal/catalog JSON (`revision`, salts, certificate ciphertext) beside hardened outputs. Public compare targets must be **one-way** (SHA-256/HMAC/etc.); reversible ARX/Feistel digests as public `revision` are a key-recovery footgun (round-2 break — **closed in round-3** when seal is digests-only). Enforce with `bla_lint_seal` / `bla lint-seal`; bankrupt harden **refuses** unless `allow_plaintext_seal` / `--allow-plaintext-seal`. Round-3 residual **gates**: `bla_lint_wasm_params` / `bla lint-wasm-params` — bankrupt refuses clear `R2SEAL`/`R3PARM`/`R3CIPH`-class carriers unless `allow_wasm_clear_params`; `bla_lint_panel_derive` — maximum/bankrupt **rewrites** `__vaultPanelDerive_*` to `_blaPd_*` unless `allow_stable_panel_derive`; bankrupt harden sets `selfSealRecommended` for multi-artifact trees (never auto for single-file) — prefer **`self_seal`**. Round-4 gates: `bla_lint_js_aes_unwrap` / `bla lint-js-aes-unwrap` — bankrupt **refuses** JS wrap-key + `create*iv` + fixed sealed hdr (e.g. `d17ea004`) unless `allow_js_aes_unwrap` (gate only — **not** white-box AES; prefer in-WASM unwrap). `bla_lint_panel_derive` flags `deriveLocal` (rewritten to `_blaPdLocal_*`) and **refuses** `deriveLocal` + plaintext `panelTokenSha256` offline-oracle packaging unless `allow_panel_offline_oracle` (rename is not a crypto fix — scrub digests / avoid derive UI). `self_seal` embeds **expected sibling SHA-256 hard-fail** when siblings exist at protect time (harden processes JS last); opaque-seed entanglement alone does **not** gate entitlement control flow. Round-5 gates: `bla_lint_js_wasm_hydrate_dump` / `bla lint-js-wasm-hydrate-dump` — bankrupt **refuses** JS that copies salt/rounds/cipher from `WebAssembly.Memory` after hydrate/instantiate unless `allow_js_wasm_hydrate_dump` (host memory dump needs **no** Node `create*iv`; export rename alone does not close this — prefer keep ARX+certify **inside** WASM so params never re-enter JS). Round-6 product pattern: export `unlock(keyPtr,keyLen)->outLen` (or equivalent) so ARX+compare+decrypt stay in WASM; JS only writes key bytes and reads the result — do **not** call hydrate then decode salt/rounds/cipher in JS (closes the round-5 host memory-dump residual under bankrupt defaults). Honesty: WASM reverse-engineering of the unlock body remains a theoretical surface; gates do not claim white-box secrecy. Round-6 **break residual**: do **not** store a plaintext XOR mask adjacent to a masked entitlement pack (`salt||rounds||expected-words||cipher`) in WASM data — static unmask needs no key; combined with invertible ARX expected-state compare this recovers the prize (`bla_lint_wasm_xor_mask_sidecar` / `bla lint-wasm-xor-mask-sidecar`; bankrupt refuses unless `allow_wasm_xor_mask_sidecar`). Prefer key-dependent unmask and **one-way** commitments inside WASM (not reversible expected words). Round-7 product pattern: keep unlock-in-WASM; derive the XOR mask from the key inside `unlock` (do **not** embed a plaintext mask beside the blob); store a SHA-256 commitment of the ARX state for compare (not invertible expected words). Round-7 **break residual**: do **not** place public `seal.revision` (or other public digests) as plaintext under a repeating XOR mask in WASM data — `revision` XOR `masked[8..40)` recovers the mask with no key; combined with an algebraically weak key-dependent mask KDF this recovers the prize (`bla_lint_wasm_seal_xor_known_plaintext` / `bla lint-wasm-seal-xor-known-plaintext`; bankrupt refuses unless `allow_wasm_seal_xor_known_plaintext`). Prefer a one-way mask KDF (e.g. SHA-256(key||i)) and keep public digests **out** of the masked plaintext prefix (or bind revision differently). Round-8 product pattern: derive the XOR mask with a **one-way** KDF such as `SHA-256(key[16])` (never an algebraically invertible byte mix); put an entropy/random pad — **not** `seal.revision` — in the masked pack prefix; keep the SHA-256 ARX commitment in a **separate clear data segment** (or otherwise outside the XOR-masked layout) so public digests cannot serve as XOR known-plaintext. Honesty: full WASM reverse-engineering of unlock can still recover algorithms; gates close packaging footguns, not white-box secrecy. Round-8 **red (NO PRIZE)**: SHA-256(key) mask KDF + commitment-outside-XOR **held** against the round-7 seal.revision XOR known-plaintext oracle and algebraic mask invert; residuals — structural KP of fixed rounds/zero pad3 leaks only a few mask bytes; arity-2 decoy aliases; bankrupt JS decoys may false-positive `bla_lint_lanes` on hardened *output*; online guessing after full WASM RE remains a theoretical surface (not a packaging refuse gate). Round-9 product pattern: keep R8 SHA-256(key) mask KDF + commitment-outside-XOR; **randomize pack header `pad3`** and avoid fixed `rounds` immediates (seed-derived rounds in-range) so structural KP cannot leak `mask[4..7]`; emit bankrupt shadow-heap decoy shares/words in **non-lane-array shapes** (CSV→map / 2+2 concat) so re-linting hardened output does not false-positive `bla_lint_lanes`; host probes all arity-2 exports for FLAG{-shaped results. Honesty: full WASM RE + online guessing remain theoretical; never embed harden `--seed` in artifacts. Round-9 **red (NO PRIZE)**: rand rounds/pad3 **closes** R8 structural KP; hardened `bla_lint_lanes` clean; R7 seal-XOR-KP / R6 sidecar / SHA-256 KDF invert / self-seal still **held**. Residuals — full WASM RE + online guess vs commitment (P2); arity-2 alias forest (~251 unlock aliases + garbage first-hit decoy) mitigated by host FLAG-shape probe (P3); JS honeypot/canary ≠WASM unlock (P3). No new bankrupt refuse lint (no prize packaging footgun under hard rules). Round-10 product pattern: keep R8–R9 crypto (SHA-256(key) mask KDF, commitment outside XOR, seed-derived rounds/pad3, entropy≠revision); **arity-2 hygiene** — bankrupt long-name decoy aliases are **spread across exported function indices** (not piled onto funcIndex 0 / unlock); cleartext exports put the real unlock **first among arity-2** so renamed first-hit is not a mandatory garbage pitfall, while names still rename under bankrupt (no stable plaintext ABI without `wasm_preserve_exports`); host resolves by **type/arity `(i32,i32)->i32` + `FLAG{…}` shape + `sha256(result)===seal.certificateSha256`** (not bare export name). Honesty: **JS honeypot/canary keys short-circuit in the host** and print an `UNLOCKED?` decoy that does **not** call WASM unlock and will **not** match `certificateSha256` if verified — distinct from product unlock (document; not a packaging refuse). Gates still do **not** claim white-box secrecy; P2 residual remains full WASM RE + online/SMT vs commitment. Round-10 **red (NO PRIZE)**: arity-2 alias **spread held** (unlock wrong-key return `0` indistinguishable from stub idx; not all aliases = unlock); R8–R9 crypto surfaces (SHA-256 KDF, commitment-outside-XOR, rand rounds/pad3, seal-XOR-KP, sidecar, self-seal, lanes clean) still **held**; host FLAG+cert is a correct but impractical online oracle. Residual — bankrupt rename preserves cleartext **export order**, so “unlock first among arity-2” still makes first arity-2 the unlock body (RE shortcut, not key recovery): prefer **shuffle export order** independently of alias-index spread while host keeps probing all arity-2 + cert. No new bankrupt refuse lint (no prize packaging footgun). Round-11 product pattern: keep R8–R10 crypto + arity-2 alias spread + host arity/FLAG/certificate contract; **independently shuffle WASM export-section order** (seed-derived at maximum/bankrupt, after rename + decoy append) so “first arity-2” is **not** a stable pointer to the unlock body — host must keep probing all arity-2 candidates + `sha256===certificateSha256` (never rely on export order). Cleartext fixtures should also avoid advertising unlock-first export order. Honesty: full WASM RE + online/SMT vs commitment remains the P2 surface; gates still do not claim white-box secrecy. No new bankrupt refuse lint. Round-11 **red (NO PRIZE)**: independent export-order shuffle **held** — first func export / first arity-2 is **not** unlock body (lab: unlock export-order position ≫ 0); alias spread + R8–R10 crypto (SHA-256 KDF, commitment-outside-XOR, rand rounds/pad3, seal-XOR-KP, sidecar, self-seal, lanes clean) still **held**; host FLAG+cert oracle 500Ă— → 0 prize; shuffle not predictable without `--seed` (absent from artifacts). Residual — P2 full WASM RE + online/SMT vs commitment only; optional P3 unlock stably at func idx 0 (body index, not export order). No new bankrupt refuse lint (no prize packaging footgun).+**Principles (red-blue round-1+2+3+4+5+6+7+7b+8+9+10+11+12):** do not ship a stable public WASM ABI without an explicit `wasm_preserve_exports` list; do not leave JS-side independent lane tables — prefer whole-key chained mixing (`bla_lint_lanes` / harden refuse). **Do not** place plaintext seal/catalog JSON (`revision`, salts, certificate ciphertext) beside hardened outputs. Public compare targets must be **one-way** (SHA-256/HMAC/etc.); reversible ARX/Feistel digests as public `revision` are a key-recovery footgun (round-2 break — **closed in round-3** when seal is digests-only). Enforce with `bla_lint_seal` / `bla lint-seal`; bankrupt harden **refuses** unless `allow_plaintext_seal` / `--allow-plaintext-seal`. Round-3 residual **gates**: `bla_lint_wasm_params` / `bla lint-wasm-params` — bankrupt refuses clear `R2SEAL`/`R3PARM`/`R3CIPH`-class carriers unless `allow_wasm_clear_params`; `bla_lint_panel_derive` — maximum/bankrupt **rewrites** `__vaultPanelDerive_*` to `_blaPd_*` unless `allow_stable_panel_derive`; bankrupt harden sets `selfSealRecommended` for multi-artifact trees (never auto for single-file) — prefer **`self_seal`**. Round-4 gates: `bla_lint_js_aes_unwrap` / `bla lint-js-aes-unwrap` — bankrupt **refuses** JS wrap-key + `create*iv` + fixed sealed hdr (e.g. `d17ea004`) unless `allow_js_aes_unwrap` (gate only — **not** white-box AES; prefer in-WASM unwrap). `bla_lint_panel_derive` flags `deriveLocal` (rewritten to `_blaPdLocal_*`) and **refuses** `deriveLocal` + plaintext `panelTokenSha256` offline-oracle packaging unless `allow_panel_offline_oracle` (rename is not a crypto fix — scrub digests / avoid derive UI). `self_seal` embeds **expected sibling SHA-256 hard-fail** when siblings exist at protect time (harden processes JS last); opaque-seed entanglement alone does **not** gate entitlement control flow. Round-5 gates: `bla_lint_js_wasm_hydrate_dump` / `bla lint-js-wasm-hydrate-dump` — bankrupt **refuses** JS that copies salt/rounds/cipher from `WebAssembly.Memory` after hydrate/instantiate unless `allow_js_wasm_hydrate_dump` (host memory dump needs **no** Node `create*iv`; export rename alone does not close this — prefer keep ARX+certify **inside** WASM so params never re-enter JS). Round-6 product pattern: export `unlock(keyPtr,keyLen)->outLen` (or equivalent) so ARX+compare+decrypt stay in WASM; JS only writes key bytes and reads the result — do **not** call hydrate then decode salt/rounds/cipher in JS (closes the round-5 host memory-dump residual under bankrupt defaults). Honesty: WASM reverse-engineering of the unlock body remains a theoretical surface; gates do not claim white-box secrecy. Round-6 **break residual**: do **not** store a plaintext XOR mask adjacent to a masked entitlement pack (`salt||rounds||expected-words||cipher`) in WASM data — static unmask needs no key; combined with invertible ARX expected-state compare this recovers the prize (`bla_lint_wasm_xor_mask_sidecar` / `bla lint-wasm-xor-mask-sidecar`; bankrupt refuses unless `allow_wasm_xor_mask_sidecar`). Prefer key-dependent unmask and **one-way** commitments inside WASM (not reversible expected words). Round-7 product pattern: keep unlock-in-WASM; derive the XOR mask from the key inside `unlock` (do **not** embed a plaintext mask beside the blob); store a SHA-256 commitment of the ARX state for compare (not invertible expected words). Round-7 **break residual**: do **not** place public `seal.revision` (or other public digests) as plaintext under a repeating XOR mask in WASM data — `revision` XOR `masked[8..40)` recovers the mask with no key; combined with an algebraically weak key-dependent mask KDF this recovers the prize (`bla_lint_wasm_seal_xor_known_plaintext` / `bla lint-wasm-seal-xor-known-plaintext`; bankrupt refuses unless `allow_wasm_seal_xor_known_plaintext`). Prefer a one-way mask KDF (e.g. SHA-256(key||i)) and keep public digests **out** of the masked plaintext prefix (or bind revision differently). Round-8 product pattern: derive the XOR mask with a **one-way** KDF such as `SHA-256(key[16])` (never an algebraically invertible byte mix); put an entropy/random pad — **not** `seal.revision` — in the masked pack prefix; keep the SHA-256 ARX commitment in a **separate clear data segment** (or otherwise outside the XOR-masked layout) so public digests cannot serve as XOR known-plaintext. Honesty: full WASM reverse-engineering of unlock can still recover algorithms; gates close packaging footguns, not white-box secrecy. Round-8 **red (NO PRIZE)**: SHA-256(key) mask KDF + commitment-outside-XOR **held** against the round-7 seal.revision XOR known-plaintext oracle and algebraic mask invert; residuals — structural KP of fixed rounds/zero pad3 leaks only a few mask bytes; arity-2 decoy aliases; bankrupt JS decoys may false-positive `bla_lint_lanes` on hardened *output*; online guessing after full WASM RE remains a theoretical surface (not a packaging refuse gate). Round-9 product pattern: keep R8 SHA-256(key) mask KDF + commitment-outside-XOR; **randomize pack header `pad3`** and avoid fixed `rounds` immediates (seed-derived rounds in-range) so structural KP cannot leak `mask[4..7]`; emit bankrupt shadow-heap decoy shares/words in **non-lane-array shapes** (CSV→map / 2+2 concat) so re-linting hardened output does not false-positive `bla_lint_lanes`; host probes all arity-2 exports for FLAG{-shaped results. Honesty: full WASM RE + online guessing remain theoretical; never embed harden `--seed` in artifacts. Round-9 **red (NO PRIZE)**: rand rounds/pad3 **closes** R8 structural KP; hardened `bla_lint_lanes` clean; R7 seal-XOR-KP / R6 sidecar / SHA-256 KDF invert / self-seal still **held**. Residuals — full WASM RE + online guess vs commitment (P2); arity-2 alias forest (~251 unlock aliases + garbage first-hit decoy) mitigated by host FLAG-shape probe (P3); JS honeypot/canary ≠WASM unlock (P3). No new bankrupt refuse lint (no prize packaging footgun under hard rules). Round-10 product pattern: keep R8–R9 crypto (SHA-256(key) mask KDF, commitment outside XOR, seed-derived rounds/pad3, entropy≠revision); **arity-2 hygiene** — bankrupt long-name decoy aliases are **spread across exported function indices** (not piled onto funcIndex 0 / unlock); cleartext exports put the real unlock **first among arity-2** so renamed first-hit is not a mandatory garbage pitfall, while names still rename under bankrupt (no stable plaintext ABI without `wasm_preserve_exports`); host resolves by **type/arity `(i32,i32)->i32` + `FLAG{…}` shape + `sha256(result)===seal.certificateSha256`** (not bare export name). Honesty: **JS honeypot/canary keys short-circuit in the host** and print an `UNLOCKED?` decoy that does **not** call WASM unlock and will **not** match `certificateSha256` if verified — distinct from product unlock (document; not a packaging refuse). Gates still do **not** claim white-box secrecy; P2 residual remains full WASM RE + online/SMT vs commitment. Round-10 **red (NO PRIZE)**: arity-2 alias **spread held** (unlock wrong-key return `0` indistinguishable from stub idx; not all aliases = unlock); R8–R9 crypto surfaces (SHA-256 KDF, commitment-outside-XOR, rand rounds/pad3, seal-XOR-KP, sidecar, self-seal, lanes clean) still **held**; host FLAG+cert is a correct but impractical online oracle. Residual — bankrupt rename preserves cleartext **export order**, so “unlock first among arity-2” still makes first arity-2 the unlock body (RE shortcut, not key recovery): prefer **shuffle export order** independently of alias-index spread while host keeps probing all arity-2 + cert. No new bankrupt refuse lint (no prize packaging footgun). Round-11 product pattern: keep R8–R10 crypto + arity-2 alias spread + host arity/FLAG/certificate contract; **independently shuffle WASM export-section order** (seed-derived at maximum/bankrupt, after rename + decoy append) so “first arity-2” is **not** a stable pointer to the unlock body — host must keep probing all arity-2 candidates + `sha256===certificateSha256` (never rely on export order). Cleartext fixtures should also avoid advertising unlock-first export order. Honesty: full WASM RE + online/SMT vs commitment remains the P2 surface; gates still do not claim white-box secrecy. No new bankrupt refuse lint. Round-11 **red (NO PRIZE)**: independent export-order shuffle **held** — first func export / first arity-2 is **not** unlock body (lab: unlock export-order position ≫ 0); alias spread + R8–R10 crypto (SHA-256 KDF, commitment-outside-XOR, rand rounds/pad3, seal-XOR-KP, sidecar, self-seal, lanes clean) still **held**; host FLAG+cert oracle 500Ă— → 0 prize; shuffle not predictable without `--seed` (absent from artifacts). Residual — P2 full WASM RE + online/SMT vs commitment only; optional P3 unlock stably at func idx 0 (body index, not export order). No new bankrupt refuse lint (no prize packaging footgun). Round-12 product pattern: keep R8–R11 crypto + arity-2 alias spread + export-order shuffle + host arity/FLAG/certificate contract; **scatter the unlock function body index** (seed-derived pad/decoy funcs prepended in cleartext assembly so unlock is not stably at func idx 0 — body index, not only export order); engine bankrupt decoy aliases **prefer host-visible arity-2** exports so arity-1 (e.g. seal) does not consume alias budget. Honesty: full WASM RE + online/SMT vs commitment remains the P2 surface; gates still do not claim white-box secrecy. No new bankrupt refuse lint.## Prerequisites (once)diff --git a/src/shields/formats/wasm.ts b/src/shields/formats/wasm.tsindex b2d6b0f..2eeb9da 100644--- a/src/shields/formats/wasm.ts+++ b/src/shields/formats/wasm.ts@@ -224,10 +224,69 @@ function appendDecoyExports(]);}+/**+ * Parse WASM type-section function signatures → param counts (functype only).+ * Returns [] on truncated / non-functype entries (defensive).+ */+function parseWasmFunctypeParamCounts(typeSectionPayload: Buffer): number[] {+ try {+ const { value: count, nextOffset } = decodeUnsignedLeb128(typeSectionPayload, 0);+ let p = nextOffset;+ const out: number[] = [];+ for (let i = 0; i < count; i++) {+ if (p >= typeSectionPayload.length) return out;+ const form = typeSectionPayload[p++]!;+ if (form !== 0x60) return out; // only functype+ const { value: nParams, nextOffset: afterParams } = decodeUnsignedLeb128(+ typeSectionPayload,+ p,+ );+ p = afterParams + nParams; // skip param valtypes+ if (p > typeSectionPayload.length) return out;+ const { value: nResults, nextOffset: afterResults } = decodeUnsignedLeb128(+ typeSectionPayload,+ p,+ );+ p = afterResults + nResults;+ if (p > typeSectionPayload.length) return out;+ out.push(nParams);+ }+ return out;+ } catch {+ return [];+ }+}++/**+ * Parse WASM function-section → type indices per function index.+ */+function parseWasmFuncTypeIndices(funcSectionPayload: Buffer): number[] {+ try {+ const { value: count, nextOffset } = decodeUnsignedLeb128(funcSectionPayload, 0);+ let p = nextOffset;+ const out: number[] = [];+ for (let i = 0; i < count; i++) {+ const { value: typeIdx, nextOffset: after } = decodeUnsignedLeb128(+ funcSectionPayload,+ p,+ );+ p = after;+ out.push(typeIdx);+ }+ return out;+ } catch {+ return [];+ }+}+/*** Collect unique function-export indices from a WASM binary (kind 0 only).* Used so bankrupt decoy aliases can be spread across real stubs + unlock* instead of all aliasing funcIndex 0 (red/blue round-10 arity-2 hygiene).+ *+ * Round-12: prefer host-visible arity-2 exports `(i32,i32)->…` when at least+ * one exists, so arity-1 exports (e.g. seal) do not consume alias budget.+ * Falls back to all func exports when no arity-2 is present.*/function collectExportedFuncIndices(bytes: Buffer): number[] {if (@@ -240,27 +299,42 @@ function collectExportedFuncIndices(bytes: Buffer): number[] {return [];}let offset = 8;+ let typeParamCounts: number[] | null = null;+ let funcTypeIndices: number[] | null = null;+ let exportEntries: WasmExportEntry[] | null = null;while (offset < bytes.length) {const sectionId = bytes[offset++]!;const { value: sectionSize, nextOffset } = decodeUnsignedLeb128(bytes, offset);const sectionEnd = nextOffset + sectionSize;if (sectionEnd > bytes.length) break;- if (sectionId === 7) {- const payload = bytes.subarray(nextOffset, sectionEnd);- const entries = parseWasmExportSectionPayload(payload);- const seen = new Set<number>();- const out: number[] = [];- for (const e of entries) {- if (e.kind !== 0) continue;- if (seen.has(e.index)) continue;- seen.add(e.index);- out.push(e.index);- }- return out;+ const payload = bytes.subarray(nextOffset, sectionEnd);+ if (sectionId === 1) {+ typeParamCounts = parseWasmFunctypeParamCounts(payload);+ } else if (sectionId === 3) {+ funcTypeIndices = parseWasmFuncTypeIndices(payload);+ } else if (sectionId === 7) {+ exportEntries = parseWasmExportSectionPayload(payload);}offset = sectionEnd;}- return [];+ if (!exportEntries) return [];+ const seen = new Set<number>();+ const all: number[] = [];+ const arity2: number[] = [];+ for (const e of exportEntries) {+ if (e.kind !== 0) continue;+ if (seen.has(e.index)) continue;+ seen.add(e.index);+ all.push(e.index);+ if (typeParamCounts && funcTypeIndices && e.index < funcTypeIndices.length) {+ const typeIdx = funcTypeIndices[e.index]!;+ if (typeIdx < typeParamCounts.length && typeParamCounts[typeIdx] === 2) {+ arity2.push(e.index);+ }+ }+ }+ // Prefer host-visible arity-2 when available (round-12 alias budget hygiene).+ return arity2.length > 0 ? arity2 : all;}function planWasmExportNameDecoys(@@ -271,6 +345,7 @@ function planWasmExportNameDecoys(// bankrupt: ~250 Ă— ~12 KiB names → Wabt interface charge ≫ 32 MiB.// Round-10: spread aliases across exported function indices (stubs + unlock)// so ~all-250 do not concentrate on funcIndex 0 / the real unlock body.+ // Round-12: caller passes arity-2-preferring indices when available.const count =intensity === "stealth"? 0@@ -480,6 +555,8 @@ export function protectWasmBinary(// Round-10: spread aliases across all exported function indices (not only 0).// Round-11: after rename + decoy append, shuffle export *order* independently// so first arity-2 is not a stable pointer to the unlock body.+ // Round-12: collectExportedFuncIndices prefers arity-2 (host-visible) so+ // arity-1 exports do not burn alias budget.const decoyExports = planWasmExportNameDecoys(prng,intensity,diff --git a/tests/wasm-export-rename.test.ts b/tests/wasm-export-rename.test.tsindex b757143..7733b0a 100644--- a/tests/wasm-export-rename.test.ts+++ b/tests/wasm-export-rename.test.ts@@ -113,16 +113,16 @@ describe("WASM export rename / semantic preservation (#40.3)", () => {});describe("WASM export decoy arity-2 hygiene (red/blue round-10)", () => {- /** Two func exports (idx 0 junk, idx 1 real) + memory — decoys must not all alias 0. */+ /** Two arity-2 func exports (idx 0 junk, idx 1 unlock) + memory — decoys must not all alias 0. */function fixtureTwoFuncs(): Buffer {- // types: (i32)->i32, (i32,i32)->i32; funcs type0+type1; mem; exports junk/unlock/memory+ // types: (i32,i32)->i32 only; funcs type0+type0; mem; exports junk/unlock/memory// junk returns 0; unlock returns a+breturn Buffer.from([- 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x02, 0x60, 0x01, 0x7f, 0x01, 0x7f,- 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x03, 0x02, 0x00, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01,- 0x07, 0x1a, 0x03, 0x04, 0x6a, 0x75, 0x6e, 0x6b, 0x00, 0x00, 0x06, 0x75, 0x6e, 0x6c, 0x6f, 0x63,- 0x6b, 0x00, 0x01, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x0a, 0x0e, 0x02, 0x04,- 0x00, 0x41, 0x00, 0x0b, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01,+ 0x7f, 0x03, 0x03, 0x02, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x07, 0x1a, 0x03, 0x04, 0x6a,+ 0x75, 0x6e, 0x6b, 0x00, 0x00, 0x06, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x01, 0x06, 0x6d,+ 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x0a, 0x0e, 0x02, 0x04, 0x00, 0x41, 0x00, 0x0b, 0x07,+ 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,]);}@@ -177,14 +177,14 @@ describe("WASM export decoy arity-2 hygiene (red/blue round-10)", () => {describe("WASM export-order shuffle (red/blue round-11)", () => {/** unlock (idx1) exported FIRST among funcs, then junk (idx0), then memory. */function fixtureUnlockFirst(): Buffer {- // types: (i32)->i32, (i32,i32)->i32; funcs type0 junk + type1 unlock; mem- // exports: unlock, junk, memory (unlock first — R10 cleartext footgun)+ // Both funcs arity-2 (R12 prefer-arity-2); unlock exported first (R10 footgun).+ // junk returns 0; unlock returns a+breturn Buffer.from([- 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x02, 0x60, 0x01, 0x7f, 0x01, 0x7f,- 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x03, 0x02, 0x00, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01,- 0x07, 0x1a, 0x03, 0x06, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x01, 0x04, 0x6a, 0x75, 0x6e,- 0x6b, 0x00, 0x00, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x0a, 0x0e, 0x02, 0x04,- 0x00, 0x41, 0x00, 0x0b, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01,+ 0x7f, 0x03, 0x03, 0x02, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x07, 0x1a, 0x03, 0x06, 0x75,+ 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x01, 0x04, 0x6a, 0x75, 0x6e, 0x6b, 0x00, 0x00, 0x06, 0x6d,+ 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x0a, 0x0e, 0x02, 0x04, 0x00, 0x41, 0x00, 0x0b, 0x07,+ 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,]);}@@ -269,3 +269,74 @@ describe("WASM export-order shuffle (red/blue round-11)", () => {expect(firsts.size).toBeGreaterThan(1);});});++describe("WASM alias budget prefers arity-2 (red/blue round-12)", () => {+ /** arity-1 seal (idx0) + arity-2 junk (idx1) + arity-2 unlock (idx2) + memory */+ function fixtureArityMix(): Buffer {+ // types: (i32)->i32, (i32,i32)->i32+ // funcs: seal=type0, junk=type1, unlock=type1+ // code: seal returns 0; junk returns 0; unlock returns a+b+ return Buffer.from([+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,+ 0x01, 0x0c, 0x02, 0x60, 0x01, 0x7f, 0x01, 0x7f, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f,+ 0x03, 0x04, 0x03, 0x00, 0x01, 0x01,+ 0x05, 0x03, 0x01, 0x00, 0x01,+ 0x07, 0x21, 0x04,+ 0x04, 0x73, 0x65, 0x61, 0x6c, 0x00, 0x00,+ 0x04, 0x6a, 0x75, 0x6e, 0x6b, 0x00, 0x01,+ 0x06, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x02,+ 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,+ 0x0a, 0x13, 0x03,+ 0x04, 0x00, 0x41, 0x00, 0x0b,+ 0x04, 0x00, 0x41, 0x00, 0x0b,+ 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b,+ ]);+ }++ it("bankrupt decoy aliases skip arity-1 when arity-2 exports exist", () => {+ const raw = fixtureArityMix();+ expect(WebAssembly.validate(new Uint8Array(raw))).toBe(true);+ const res = protectWasmBinary(raw, {+ intensity: "bankrupt",+ seed: "r12-arity1-budget-tighten",+ preserveExports: ["seal", "junk", "unlock", "memory"],+ });+ expect(res.exportDecoysInjected).toBe(250);+ expect(WebAssembly.validate(new Uint8Array(res.buffer))).toBe(true);++ const bytes = res.buffer;+ let offset = 8;+ let decoySeal = 0;+ let decoyJunk = 0;+ let decoyUnlock = 0;+ while (offset < bytes.length) {+ const sectionId = bytes[offset++]!;+ let size = 0;+ let shift = 0;+ while (true) {+ const b = bytes[offset++]!;+ size |= (b & 0x7f) << shift;+ if ((b & 0x80) === 0) break;+ shift += 7;+ }+ const sectionEnd = offset + size;+ if (sectionId === 7) {+ const entries = parseWasmExportSectionPayload(bytes.subarray(offset, sectionEnd));+ for (const e of entries) {+ if (e.kind !== 0) continue;+ if (!e.name.startsWith("enclave_export_")) continue;+ if (e.index === 0) decoySeal++;+ else if (e.index === 1) decoyJunk++;+ else if (e.index === 2) decoyUnlock++;+ }+ break;+ }+ offset = sectionEnd;+ }+ expect(decoySeal + decoyJunk + decoyUnlock).toBe(250);+ // Round-12: arity-1 seal must not receive alias budget when arity-2 exist.+ expect(decoySeal).toBe(0);+ expect(decoyJunk).toBeGreaterThan(40);+ expect(decoyUnlock).toBeGreaterThan(40);+ });+});