From: Chris Duncan Date: Thu, 5 Nov 2026 05:53:36 +0000 (-0800) Subject: Fix test by adding import patching. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=7b1eb8f84ba71b69e2262eee76ca6c986260801f;p=nano25519.git Fix test by adding import patching. --- diff --git a/test/arithmetic.mjs b/test/arithmetic.mjs index c7e2979..2a695ff 100644 --- a/test/arithmetic.mjs +++ b/test/arithmetic.mjs @@ -164,9 +164,9 @@ export function verify_pubkey_ (): i32 { return verify_pubkey(U8A) ? 1 : 0 } export function verify_signature_ (): i32 { return verify_signature(U8W) ? 1 : 0 } ` -/** Seeded controls: each `from` must occur once inside its `fn`. */ +/** Seeded controls: each `from` must occur once inside its `fn`; an optional `import` line is added to the file. */ const NO_IDENTITY = [{ file: 'src/assembly/ed25519/ge/double_scalarmult.ts', fn: 'ge_double_scalarmult_vartime_to_p3', from: '\n\tp3_0(r)', to: '' }] -const STALE_T = [{ file: 'src/assembly/ed25519/ge/double_scalarmult.ts', fn: 'ge_double_scalarmult_vartime_to_p3', from: 'p1p1_to_p3(r, t)', to: 'p1p1_to_p3(r, t)\n\t\t\tfe_mul(r.T, r.X, r.Y)' }] +const STALE_T = [{ file: 'src/assembly/ed25519/ge/double_scalarmult.ts', fn: 'ge_double_scalarmult_vartime_to_p3', from: 'p1p1_to_p3(r, t)', to: 'p1p1_to_p3(r, t)\n\t\t\tfe_mul(r.T, r.X, r.Y)', import: "import { fe_mul } from '../fe'" }] const NO_PRECONDITIONS = [ { file: 'src/assembly/crypto_verify.ts', fn: 'verify_pubkey', from: 'if (ge_is_canonical(pub) != 0) {', to: 'if (false) {' }, { file: 'src/assembly/crypto_verify.ts', fn: 'verify_signature', from: 'if (ge_is_canonical(sig) != 0) {', to: 'if (false) {' }, @@ -192,7 +192,13 @@ async function probe (name, edits = []) { if (start < 0 || end < 0 || body.split(edit.from).length !== 2) { throw new Error(`control no longer applies: "${edit.from.trim()}" must occur once in ${edit.fn}()`) } - await writeFile(path, source.slice(0, start) + body.replace(edit.from, edit.to) + source.slice(end)) + let patched = source.slice(0, start) + body.replace(edit.from, edit.to) + source.slice(end) + if (edit.import) { + const at = patched.indexOf('\nimport ') + if (at < 0) throw new Error(`control no longer applies: ${edit.file} has no import to precede`) + patched = patched.slice(0, at + 1) + edit.import + '\n' + patched.slice(at + 1) + } + await writeFile(path, patched) } await exec(process.execPath, [asc, 'src/assembly/harness.ts', '--outFile', 'build/harness.wasm'], { cwd: dir.pathname }) return new WebAssembly.Module(await readFile(new URL('build/harness.wasm', dir)))