Skip to content

Commit

Permalink
feat: allow specifying using the remote circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTehrani committed Sep 21, 2023
1 parent 5dae5e1 commit eeb704a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/lib/src/core/membership_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion packages/lib/src/core/membership_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -30,6 +31,8 @@ export class MembershipVerifier extends Profiler implements IVerifier {
}

this.circuit = options.circuit;
this.useRemoteCircuit =
options.useRemoteCircuit ?? typeof window !== "undefined";
}

async initWasm() {
Expand All @@ -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");
Expand Down
5 changes: 2 additions & 3 deletions packages/lib/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit eeb704a

Please sign in to comment.