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) {' },
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)))