Skip to content

Commit

Permalink
feat: adding destroy and options object (#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello authored and TomAFrench committed Oct 12, 2023
1 parent 3828e22 commit 31684bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions tooling/noir_js/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class Noir {
}
}

async destroy(): Promise<void> {
await this.backend?.destroy();
}

private getBackend(): Backend {
if (this.backend === undefined) throw new Error('Operation requires a backend but none was provided');
return this.backend;
Expand Down
10 changes: 6 additions & 4 deletions tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { decompressSync as gunzip } from 'fflate';
import { acirToUint8Array } from './serialize.js';
import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
import { BackendOptions } from './types.js';

// This is the number of bytes in a UltraPlonk proof
// minus the public inputs.
Expand All @@ -15,11 +16,12 @@ export class BarretenbergBackend implements Backend {
private api: any;
private acirComposer: any;
private acirUncompressedBytecode: Uint8Array;
private numberOfThreads = 1;

constructor(acirCircuit: CompiledCircuit, numberOfThreads = 1) {
constructor(
acirCircuit: CompiledCircuit,
private options: BackendOptions = { threads: 1 },
) {
const acirBytecodeBase64 = acirCircuit.bytecode;
this.numberOfThreads = numberOfThreads;
this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64);
}

Expand All @@ -28,7 +30,7 @@ export class BarretenbergBackend implements Backend {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js');
const api = await Barretenberg.new(this.numberOfThreads);
const api = await Barretenberg.new(this.options.threads);

const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode);
const crs = await Crs.new(subgroupSize + 1);
Expand Down
3 changes: 3 additions & 0 deletions tooling/noir_js_backend_barretenberg/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type BackendOptions = {
threads: number;
};
2 changes: 1 addition & 1 deletion tooling/noir_js_types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface Backend {
generateIntermediateProof(decompressedWitness: Uint8Array): Promise<ProofData>;

verifyFinalProof(proofData: ProofData): Promise<boolean>;

verifyIntermediateProof(proofData: ProofData): Promise<boolean>;
destroy(): Promise<void>;
}

export type ProofData = {
Expand Down

0 comments on commit 31684bc

Please sign in to comment.