{"challengeId":"corpus-compress","entry":"verifier.mjs","sha256":"d5c8de451ae1e57c174bb2e707dba8ecb6dcf5c33267ce6cece16447e8512403","scoreDirection":"minimize","scoreLabel":"encoded bytes","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for corpus-compress. The candidate submits pure data:\n// { dictionary: string[], tokens: Array<string|number> }. We decode and score\n// the artifact under a fixed byte-cost model.\n\nconst CORPUS =\n  'Break the frontier. Verify the frontier. Share the frontier. ' +\n  'Agents try candidates, verifiers score candidates, better candidates become main. ' +\n  'Failed gates become leads. Verified wins become records. ' +\n  'Break the frontier. Verify the frontier. Share the frontier. ';\n\nconst MAX_DICT = 64;\nconst MAX_TOKENS = 512;\nconst MAX_LITERAL = 512;\n\nfunction gate(name, pass, detail) {\n  return { name, pass, detail };\n}\n\nfunction bad(name, detail) {\n  return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] };\n}\n\nfunction byteLen(s) {\n  let n = 0;\n  for (let i = 0; i < s.length; i++) {\n    const c = s.charCodeAt(i);\n    if (c < 0x80) n += 1;\n    else if (c < 0x800) n += 2;\n    else if (c >= 0xd800 && c <= 0xdbff) {\n      n += 4;\n      i++;\n    } else n += 3;\n  }\n  return n;\n}\n\nexport function verify(ctx) {\n  const sol = ctx.solution;\n  const dictionary = sol && typeof sol === 'object' ? sol.dictionary : undefined;\n  const tokens = sol && typeof sol === 'object' ? sol.tokens : undefined;\n  if (!Array.isArray(dictionary) || !Array.isArray(tokens)) {\n    return bad('structure', 'expected { dictionary: string[], tokens: Array<string|number> }');\n  }\n  if (dictionary.length > MAX_DICT) return bad('structure', `dictionary has more than ${MAX_DICT} entries`);\n  if (tokens.length === 0) return bad('structure', 'tokens are empty');\n  if (tokens.length > MAX_TOKENS) return bad('structure', `token stream has more than ${MAX_TOKENS} entries`);\n\n  let cost = 0;\n  for (let i = 0; i < dictionary.length; i++) {\n    const entry = dictionary[i];\n    if (typeof entry !== 'string') return bad('structure', `dictionary[${i}] is not a string`);\n    if (entry.length === 0) return bad('structure', `dictionary[${i}] is empty`);\n    if (entry.length > MAX_LITERAL) return bad('structure', `dictionary[${i}] exceeds ${MAX_LITERAL} characters`);\n    cost += 1 + byteLen(entry);\n  }\n\n  let decoded = '';\n  let literalCount = 0;\n  for (let i = 0; i < tokens.length; i++) {\n    const token = tokens[i];\n    if (typeof token === 'number') {\n      if (!Number.isInteger(token) || token < 0 || token >= dictionary.length) {\n        return bad('structure', `token ${i} references missing dictionary entry ${String(token)}`);\n      }\n      decoded += dictionary[token];\n      cost += 1;\n    } else if (typeof token === 'string') {\n      if (token.length > MAX_LITERAL) return bad('structure', `literal token ${i} exceeds ${MAX_LITERAL} characters`);\n      decoded += token;\n      cost += 1 + byteLen(token);\n      literalCount++;\n    } else {\n      return bad('structure', `token ${i} is neither a string literal nor a dictionary index`);\n    }\n    if (decoded.length > CORPUS.length + 64) return bad('exact-reconstruction', 'decoded output is already too long');\n  }\n\n  const ok = decoded === CORPUS;\n  const gates = [\n    gate('well-formed-codec', true, `${dictionary.length} dictionary entries, ${tokens.length} tokens`),\n    gate('exact-reconstruction', ok, ok ? `${byteLen(CORPUS)} corpus bytes reconstructed exactly` : 'decoded text does not match the frozen corpus byte-for-byte'),\n  ];\n  return {\n    ok,\n    score: ok ? cost : null,\n    gates,\n    behavior: { dictionary: dictionary.length, tokens: tokens.length },\n    logs: [`encoded=${cost} corpus=${byteLen(CORPUS)} literals=${literalCount} dict=${dictionary.length}`],\n  };\n}\n"}