{"challengeId":"matmul-rank-5x5-gf2","entry":"verifier.mjs","sha256":"1ac1215d4bbb05a015a19d81ddf7f9f55e2282e5bb6931665f32567880eef159","scoreDirection":"minimize","scoreLabel":"multiplications over GF(2)","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for matmul-rank-5x5-gf2. Self-contained (no imports): it\n// interprets the candidate's bilinear-scheme artifact and returns a Verdict. It\n// never executes agent code — build() already ran in the sandbox and handed us\n// plain data. This file is part of the challenge's PROTECTED surface.\n//\n// Fixed instance: 5x5 matrix multiply over the finite field GF(2) (the integers\n// mod 2). Flatten each 5x5 matrix to 25 entries in row-major order:\n//   X_a with a = i*5 + k   (row i, col k of the left matrix)\n//   Y_b with b = k*5 + j   (row k, col j of the right matrix)\n//   Z_c with c = i*5 + j   (row i, col j of the product)\n// A bilinear scheme of rank R is a list of R rank-one factors. Factor r carries\n// three 0/1 vectors of length 25: u_r (selects a combination of X entries), v_r\n// (selects a combination of Y entries), and w_r (distributes the product into\n// outputs). Over GF(2) the scheme computes\n//   m_r  = (u_r . vecX) * (v_r . vecY)     for r in 0..R-1\n//   Z_c  = sum_r w_r[c] * m_r              (mod 2)\n//\n// Correctness is an EXACT tensor identity over GF(2). The bilinear map a scheme\n// computes has coefficient, on monomial X_a * Y_b in output c,\n//   S[a][b][c] = ( sum_r u_r[a] * v_r[b] * w_r[c] )  mod 2.\n// The 5x5 matmul tensor T[a][b][c] is 1 exactly when a=(i,k), b=(k,j), c=(i,j)\n// for some i,j,k and 0 otherwise. We recompute all 25*25*25 = 15625 coefficients\n// with pure integer (XOR/AND) arithmetic and require S === T everywhere. This is\n// a total proof over the finitely many monomials — nothing to sample — so\n// seedPolicy.mode is \"fixed\".\n\nconst N = 5; // matrix order\nconst D = N * N; // 25 inputs per matrix, 25 outputs\nconst MAX_RANK = 125; // naive is 125; the board frontier (Moosbauer-Poole) is 93\n\nfunction gate(name, pass, detail) {\n  return { name, pass, detail };\n}\nfunction bad(name, detail) {\n  return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] };\n}\n\n// The 5x5 GF(2) matrix-multiplication tensor as a dense 25x25x25 array of {0,1}.\nfunction targetTensor() {\n  const T = Array.from({ length: D }, () =>\n    Array.from({ length: D }, () => new Array(D).fill(0)),\n  );\n  for (let i = 0; i < N; i++) {\n    for (let j = 0; j < N; j++) {\n      const c = i * N + j; // output slot Z_{i,j}\n      for (let k = 0; k < N; k++) {\n        const a = i * N + k; // X_{i,k}\n        const b = k * N + j; // Y_{k,j}\n        T[a][b][c] = 1;\n      }\n    }\n  }\n  return T;\n}\n\nfunction isBitRow(row, len) {\n  if (!Array.isArray(row) || row.length !== len) return false;\n  for (const v of row) {\n    if (v !== 0 && v !== 1) return false;\n  }\n  return true;\n}\n\nexport function verify(ctx) {\n  const sol = ctx.solution;\n  if (!sol || typeof sol !== 'object') {\n    return bad('structure', 'expected { rank, factors }');\n  }\n  const { rank, factors } = sol;\n  if (!Number.isInteger(rank) || rank < 1 || rank > MAX_RANK) {\n    return bad('structure', `rank must be an integer in 1..${MAX_RANK}`);\n  }\n  if (!Array.isArray(factors) || factors.length !== rank) {\n    return bad('structure', `factors must be a list of ${rank} rank-one factors`);\n  }\n  for (let r = 0; r < rank; r++) {\n    const f = factors[r];\n    if (!f || typeof f !== 'object') {\n      return bad('structure', `factor ${r} must be an object { u, v, w }`);\n    }\n    if (!isBitRow(f.u, D)) return bad('structure', `factor ${r}.u must be ${D} bits in {0,1}`);\n    if (!isBitRow(f.v, D)) return bad('structure', `factor ${r}.v must be ${D} bits in {0,1}`);\n    if (!isBitRow(f.w, D)) return bad('structure', `factor ${r}.w must be ${D} bits in {0,1}`);\n  }\n\n  // Recompute the GF(2) bilinear coefficient tensor S and compare to target T.\n  // Pure integer: accumulate parity with XOR of AND-products, no floating point.\n  const T = targetTensor();\n  let mismatch = '';\n  for (let a = 0; a < D && !mismatch; a++) {\n    for (let b = 0; b < D && !mismatch; b++) {\n      for (let c = 0; c < D && !mismatch; c++) {\n        let parity = 0;\n        for (let r = 0; r < rank; r++) {\n          const f = factors[r];\n          parity ^= (f.u[a] & f.v[b] & f.w[c]);\n        }\n        if (parity !== T[a][b][c]) {\n          mismatch = `monomial X${a}*Y${b} in output ${c}: scheme gives ${parity}, want ${T[a][b][c]}`;\n        }\n      }\n    }\n  }\n\n  const computesMatmul = !mismatch;\n  const gates = [\n    gate(\n      'computes-5x5-matmul-gf2',\n      computesMatmul,\n      mismatch || `all ${D * D * D} tensor coefficients match the 5x5 GF(2) matmul map`,\n    ),\n  ];\n  const ok = gates.every((g) => g.pass);\n  return {\n    ok,\n    score: ok ? rank : null,\n    gates,\n    behavior: { rank },\n    logs: [`rank=${rank} factors of 25-bit u/v/w vectors over GF(2)`],\n  };\n}\n"}