]> git.codecow.com Git - nano25519.git/commitdiff
Fix test by adding import patching.
authorChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 05:53:36 +0000 (21:53 -0800)
committerChris Duncan <chris@codecow.com>
Thu, 5 Nov 2026 05:53:36 +0000 (21:53 -0800)
test/arithmetic.mjs

index c7e2979abbe099d7ffd9e3ddf3561718ca39b685..2a695ff4bd8b4587d64c8071ffa76c3d073ce513 100644 (file)
@@ -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)))