From 262b66df4aeed72c6aea95b8732de6c4e007e61e Mon Sep 17 00:00:00 2001 From: Yu Jiang Tham Date: Mon, 15 Jan 2024 16:59:42 -0800 Subject: [PATCH] feat/cache-srs tmp changes --- halo2-wasm/js/js/kzg.ts | 43 ++++++++++++++++++----------------- halo2-wasm/js/shared/utils.ts | 2 ++ halo2-wasm/js/web/kzg.ts | 3 ++- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/halo2-wasm/js/js/kzg.ts b/halo2-wasm/js/js/kzg.ts index 5f03e49..8b02e54 100644 --- a/halo2-wasm/js/js/kzg.ts +++ b/halo2-wasm/js/js/kzg.ts @@ -4,30 +4,31 @@ import * as fs from "fs"; import { fetchAndConvertToUint8Array } from "../shared/utils"; export const getKzgParams = async (k: number): Promise => { - const home = os.homedir(); - const axiomSrsPath = path.join( - home, - ".axiom", - "srs", - "challenge_0085", - `kzg_bn254_${k}.srs` - ); - const exists = fs.existsSync(axiomSrsPath); - if (exists) { - const buffer = fs.readFileSync(axiomSrsPath); - return new Uint8Array(buffer); - } - const folderPath = path.dirname(axiomSrsPath); - if (!fs.existsSync(folderPath)) { - fs.mkdirSync(folderPath, { recursive: true }); - } - if (k < 6 || k > 19) { - throw new Error(`k=${k} is not supported`); - } + console.log("KZG: js"); + // const home = os.homedir(); + // const axiomSrsPath = path.join( + // home, + // ".axiom", + // "srs", + // "challenge_0085", + // `kzg_bn254_${k}.srs` + // ); + // const exists = fs.existsSync(axiomSrsPath); + // if (exists) { + // const buffer = fs.readFileSync(axiomSrsPath); + // return new Uint8Array(buffer); + // } + // const folderPath = path.dirname(axiomSrsPath); + // if (!fs.existsSync(folderPath)) { + // fs.mkdirSync(folderPath, { recursive: true }); + // } + // if (k < 6 || k > 19) { + // throw new Error(`k=${k} is not supported`); + // } const srs = await fetchAndConvertToUint8Array( `https://axiom-crypto.s3.amazonaws.com/challenge_0085/kzg_bn254_${k}.srs` ); - fs.writeFileSync(axiomSrsPath, srs); + // fs.writeFileSync(axiomSrsPath, srs); return srs; }; \ No newline at end of file diff --git a/halo2-wasm/js/shared/utils.ts b/halo2-wasm/js/shared/utils.ts index 45eadf0..82407db 100644 --- a/halo2-wasm/js/shared/utils.ts +++ b/halo2-wasm/js/shared/utils.ts @@ -19,9 +19,11 @@ export function fetchAndConvertToUint8Array(url: string): Promise { } // Check if running in browser or web worker environment else if (typeof window !== "undefined" || typeof self !== "undefined") { + console.log("fetching SRS..."); fetch(url) .then((response) => response.arrayBuffer()) .then((buffer) => { + console.log("got SRS successfully"); resolve(new Uint8Array(buffer)); }) .catch(reject); diff --git a/halo2-wasm/js/web/kzg.ts b/halo2-wasm/js/web/kzg.ts index 137c8d9..9465ec0 100644 --- a/halo2-wasm/js/web/kzg.ts +++ b/halo2-wasm/js/web/kzg.ts @@ -1,8 +1,9 @@ import { fetchAndConvertToUint8Array } from "../shared/utils"; export const getKzgParams = async (k: number): Promise => { + console.log("KZG: web"); if (k < 6 || k > 19) { throw new Error(`k=${k} is not supported`); } - return fetchAndConvertToUint8Array(`https://axiom-crypto.s3.amazonaws.com/challenge_0085/kzg_bn254_${k}.srs`); + return await fetchAndConvertToUint8Array(`https://axiom-crypto.s3.amazonaws.com/challenge_0085/kzg_bn254_${k}.srs`); }; \ No newline at end of file