Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding destroy and options object #3105

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tooling/noir_js/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
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 @@ -14,11 +15,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 @@ -27,7 +29,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