Skip to content

Commit

Permalink
fix: initialize wasm instance in test_halo2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sifnoc committed Dec 3, 2024
1 parent b403703 commit 8c0de02
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test-e2e/web/test_halo2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import * as mopro_wasm from './mopro-pkg/mopro_wasm.js';

// Initialize the WASM module and thread pool once
const initializeWasm = async () => {
try {
await mopro_wasm.default();
await mopro_wasm.initThreadPool(navigator.hardwareConcurrency);
} catch (error) {
console.error("Failed to initialize WASM module or thread pool:", error);
throw error;
}
};

const initPromise = initializeWasm();

async function fetchBinaryFile(url) {
const response = await fetch(url);
if (!response.ok) throw new Error(`Failed to load ${url}`);
Expand All @@ -15,9 +28,6 @@ async function measureTime(callback) {

async function run_plonk_test(input) {
try {
await mopro_wasm.default();
await mopro_wasm.initThreadPool(navigator.hardwareConcurrency);

const SRS_KEY = await fetchBinaryFile('./mopro-pkg/parameters/plonk_fibonacci_srs.bin');
const PROVING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/plonk_fibonacci_pk.bin');
const VERIFYING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/plonk_fibonacci_vk.bin');
Expand All @@ -43,9 +53,6 @@ async function run_plonk_test(input) {

async function run_hyperplonk_test(input) {
try {
await mopro_wasm.default();
await mopro_wasm.initThreadPool(navigator.hardwareConcurrency);

const SRS_KEY = await fetchBinaryFile('./mopro-pkg/parameters/hyperplonk_fibonacci_srs.bin');
const PROVING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/hyperplonk_fibonacci_pk.bin');
const VERIFYING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/hyperplonk_fibonacci_vk.bin');
Expand All @@ -72,9 +79,6 @@ async function run_hyperplonk_test(input) {

async function run_gemini_test(input) {
try {
await mopro_wasm.default();
await mopro_wasm.initThreadPool(navigator.hardwareConcurrency);

const SRS_KEY = await fetchBinaryFile('./mopro-pkg/parameters/gemini_fibonacci_srs.bin');
const PROVING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/gemini_fibonacci_pk.bin');
const VERIFYING_KEY = await fetchBinaryFile('./mopro-pkg/parameters/gemini_fibonacci_vk.bin');
Expand Down Expand Up @@ -103,6 +107,9 @@ async function run_gemini_test(input) {
self.addEventListener('message', async (event) => {
const { testName, input } = event.data;
try {
// Initialize wasm instance once
await initPromise;

if (testName === 'Plonk') {
const result = await run_plonk_test(input);
self.postMessage({ testName, data: result });
Expand Down

0 comments on commit 8c0de02

Please sign in to comment.