Skip to content

Commit

Permalink
feat/cache-srs tmp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ytham committed Jan 16, 2024
1 parent 78677fd commit 262b66d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
43 changes: 22 additions & 21 deletions halo2-wasm/js/js/kzg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ import * as fs from "fs";
import { fetchAndConvertToUint8Array } from "../shared/utils";

export const getKzgParams = async (k: number): Promise<Uint8Array> => {
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;
};
2 changes: 2 additions & 0 deletions halo2-wasm/js/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export function fetchAndConvertToUint8Array(url: string): Promise<Uint8Array> {
}
// 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);
Expand Down
3 changes: 2 additions & 1 deletion halo2-wasm/js/web/kzg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { fetchAndConvertToUint8Array } from "../shared/utils";

export const getKzgParams = async (k: number): Promise<Uint8Array> => {
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`);
};

0 comments on commit 262b66d

Please sign in to comment.