feat: allow specifying using the remote circuit

This commit is contained in:
Daniel Tehrani
2023-09-21 14:53:35 +09:00
parent 5dae5e1aa4
commit eeb704a7d1
4 changed files with 9 additions and 5 deletions

View File

@@ -90,7 +90,8 @@ export class MembershipProver extends Profiler implements IProver {
this.timeEnd("Generate witness");
this.time("Load circuit");
const circuitBin = await loadCircuit(this.circuit);
const useRemoteCircuit = typeof window !== "undefined";
const circuitBin = await loadCircuit(this.circuit, useRemoteCircuit);
this.timeEnd("Load circuit");
// Get the public input in bytes

View File

@@ -13,6 +13,7 @@ import { PublicInput, verifyEffEcdsaPubInput } from "../helpers/public_input";
*/
export class MembershipVerifier extends Profiler implements IVerifier {
circuit: string;
useRemoteCircuit: boolean;
constructor(options: VerifyConfig) {
super({ enabled: options?.enableProfiler });
@@ -30,6 +31,8 @@ export class MembershipVerifier extends Profiler implements IVerifier {
}
this.circuit = options.circuit;
this.useRemoteCircuit =
options.useRemoteCircuit ?? typeof window !== "undefined";
}
async initWasm() {
@@ -41,7 +44,7 @@ export class MembershipVerifier extends Profiler implements IVerifier {
publicInputSer: Uint8Array
): Promise<boolean> {
this.time("Load circuit");
const circuitBin = await loadCircuit(this.circuit);
const circuitBin = await loadCircuit(this.circuit, this.useRemoteCircuit);
this.timeEnd("Load circuit");
this.time("Verify public input");

View File

@@ -18,9 +18,8 @@ export const snarkJsWitnessGen = async (input: any, wasmFile: string) => {
/**
* Load a circuit from a file or URL
*/
export const loadCircuit = async (pathOrUrl: string): Promise<Uint8Array> => {
const isWeb = typeof window !== "undefined";
if (isWeb) {
export const loadCircuit = async (pathOrUrl: string, useRemoteCircuit: boolean): Promise<Uint8Array> => {
if (useRemoteCircuit) {
return await fetchCircuit(pathOrUrl);
} else {
return await readCircuitFromFs(pathOrUrl);

View File

@@ -29,6 +29,7 @@ export interface ProverConfig {
export interface VerifyConfig {
circuit: string; // Path to circuit file compiled by Nova-Scotia
enableProfiler?: boolean;
useRemoteCircuit?: boolean;
}
export interface IProver {