From bef271af6a12fbda2add5338a80ee805066b79c6 Mon Sep 17 00:00:00 2001 From: qybaihe <137127051+qybaihe@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:42:27 +0800 Subject: [PATCH] fix(lint-lanes): ignore all-zero init arrays as compare tables Round-2 blue whole-key pack buffers like [0,0,0,0] tripped per-lane-byte-compare-array next to key identifiers. Skip all-zero literals so chained gates harden under default refuse without allow. --- src/engine/lane-independence-lint.ts | 19 ++++++++++++------- tests/lane-independence-lint.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/engine/lane-independence-lint.ts b/src/engine/lane-independence-lint.ts index 11fd035..6a60e20 100644 --- a/src/engine/lane-independence-lint.ts +++ b/src/engine/lane-independence-lint.ts @@ -82,13 +82,18 @@ export function lintLaneIndependence(source: string): LaneIndependenceReport { if (BYTE_COMPARE_ARRAY.test(text) && /(?:key|guess|input|lane)/i.test(text)) { const m = text.match(BYTE_COMPARE_ARRAY); - findings.push( - finding( - "per-lane-byte-compare-array", - "Literal multi-byte compare table near key/guess identifiers — may allow independent per-lane probes.", - m?.[0] ?? "", - ), - ); + // Round-2 blue: all-zero init arrays (e.g. pack buffers) are not compare tables. + const lit = m?.[0] ?? ""; + const allZero = /^\[\s*0\s*(?:,\s*0\s*){3,}\]$/.test(lit); + if (!allZero) { + findings.push( + finding( + "per-lane-byte-compare-array", + "Literal multi-byte compare table near key/guess identifiers — may allow independent per-lane probes.", + lit, + ), + ); + } } if (LANE_AND_REDUCE.test(text) || EVERY_INDEXED_LANE.test(text)) { diff --git a/tests/lane-independence-lint.test.ts b/tests/lane-independence-lint.test.ts index a1f6b56..1d9b6d2 100644 --- a/tests/lane-independence-lint.test.ts +++ b/tests/lane-independence-lint.test.ts @@ -59,6 +59,30 @@ describe("lane-independence footgun lint (#40.1 / red-blue round-1)", () => { expect(report.findings[0]!.severity).toBe("error"); }); + it("ignores all-zero init arrays used for whole-key packing (round-2 blue)", () => { + const src = ` + function packWord(key, start) { + let w = 0; + for (let i = 0; i < 4; i++) w = (w << 8) | key.charCodeAt(start + i); + return w | 0; + } + function activate(key) { + let a = packWord(key, 0), b = packWord(key, 4), c = packWord(key, 8), d = packWord(key, 12); + // legacy-looking zero buffer that is NOT a compare table: + const scratch = [0, 0, 0, 0]; + void scratch; + for (let r = 0; r < 24; r++) { + a = (a + b) | 0; b = (b ^ a) | 0; c = (c + d) | 0; d = (d ^ c) | 0; + a ^= c; b ^= d; + } + return (a ^ b ^ c ^ d) === 0x12345678; + } + `; + const report = lintLaneIndependence(src); + expect(report.findings.some((f) => f.id === "per-lane-byte-compare-array")).toBe(false); + expect(report.looksLaneIndependent).toBe(false); + }); + it("errors on CrackMe v6-style per-byte WASM lane oracles", () => { const tpl = readFileSync( resolve(process.cwd(), "challenge/v6/src/vault.template.cjs"),