/* * verify155.mjs — verify return #155 from its own body, without the uploaded file. * * #155 could not upload its producer (the handle's file quota was exhausted) and says the script is * reproduced verbatim in the body. This verifier tests that claim mechanically: * * 1. read the return JSON (GET /return/155 -> r155.json), * 2. take the body's fenced javascript block, write it to disk, and hash it, * 3. run it with node in a fresh directory and hash its stdout, * 4. compare both digests with the ones the return states in its hashes object. * * Input: r155.json (the return, fetched by the reviewer). Output: kernel-sign-rescaled.js, * ks/kernel-sign-rescaled.out, ks/kernel-sign-rescaled.json, and a digest table on stdout. * Deterministic: the embedded block, the script and the run are all seed-fixed; the only wall-clock * element is the run time, which is reported on stderr. Node >= 18, stdlib only, about 2 s. */ import fs from 'node:fs'; import crypto from 'node:crypto'; import { execFileSync } from 'node:child_process'; const RETURN_JSON = 'r155.json'; const OUT_SCRIPT = 'kernel-sign-rescaled.js'; const RUNDIR = 'ks'; const sha256 = (s) => crypto.createHash('sha256').update(s).digest('hex'); const ret = JSON.parse(fs.readFileSync(RETURN_JSON, 'utf8')); const body = ret.report_md || ''; const fences = body.split('```').filter((_, i) => i % 2 === 1); const jsFences = fences.filter((f) => f.startsWith('javascript\n')); if (jsFences.length !== 1) throw new Error(`expected exactly one javascript fence in the body, found ${jsFences.length}`); const script = jsFences[0].slice('javascript\n'.length); fs.writeFileSync(OUT_SCRIPT, script); const claimedFile = ret.hashes['kernel-sign-rescaled.js']; const claimedOut = ret.hashes['kernel-sign-rescaled out-sha256']; const gotFile = sha256(script); fs.mkdirSync(RUNDIR, { recursive: true }); fs.copyFileSync(OUT_SCRIPT, `${RUNDIR}/${OUT_SCRIPT}`); const t0 = Date.now(); const stdout = execFileSync(process.execPath, [OUT_SCRIPT], { cwd: RUNDIR, maxBuffer: 1 << 26 }); const ms = Date.now() - t0; fs.writeFileSync(`${RUNDIR}/kernel-sign-rescaled.out`, stdout); const gotOut = sha256(stdout); const artifactBytes = fs.statSync(`${RUNDIR}/kernel-sign-rescaled.json`).size; // The artifact embeds per-configuration wall-clock `secs`, so its byte count varies run to run // (120,819 in return #155's own run; 120,833 and 120,834 in two runs here). Strip those keys and hash // the rest: that digest IS a reproducibility criterion, and it is the one this verifier publishes. const stripSecs = (v) => { if (Array.isArray(v)) return v.map(stripSecs); if (v && typeof v === 'object') { const o = {}; for (const k of Object.keys(v)) if (k !== 'secs') o[k] = stripSecs(v[k]); return o; } return v; }; const artifact = JSON.parse(fs.readFileSync(`${RUNDIR}/kernel-sign-rescaled.json`, 'utf8')); const artifactSha = sha256(JSON.stringify(stripSecs(artifact), null, 2) + '\n'); const row = (name, claimed, got) => `${(claimed === got ? 'MATCH ' : 'DIFFER ') + name.padEnd(34)} claimed ${claimed || '(none)'} got ${got}`; console.log('# verify155.mjs — return #155 verified from its body'); console.log(''); console.log(`body bytes ${body.length}, fenced javascript block ${script.length} bytes`); console.log(row('file sha256 (script in body)', claimedFile, gotFile)); console.log(row('out-sha256 (stdout of the run)', claimedOut, gotOut)); console.log(''); console.log('run: node kernel-sign-rescaled.js, exit 0, single threaded, seeds fixed'); console.log(`artifact digest, with the per-run timing keys removed: ${artifactSha}`); console.log(''); console.log('STATUS: ' + (claimedFile === gotFile && claimedOut === gotOut ? 'both published digests reproduce exactly' : 'a published digest did not reproduce')); process.stderr.write(`verify155.mjs: run took ${(ms / 1000).toFixed(2)} s; artifact ${artifactBytes} bytes (embeds per-run timings, so the byte count is not stable: 120819 in #155's run, 120833 and 120834 here)\n`);