diff --git a/tooling/noir_js/src/program.ts b/tooling/noir_js/src/program.ts index 7d11166c0a7..877fd400688 100644 --- a/tooling/noir_js/src/program.ts +++ b/tooling/noir_js/src/program.ts @@ -20,6 +20,10 @@ export class Noir { } } + async destroy(): Promise { + 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; diff --git a/tooling/noir_js_backend_barretenberg/src/index.ts b/tooling/noir_js_backend_barretenberg/src/index.ts index a2f8240f6f7..e51e35585c0 100644 --- a/tooling/noir_js_backend_barretenberg/src/index.ts +++ b/tooling/noir_js_backend_barretenberg/src/index.ts @@ -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. @@ -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); } @@ -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); diff --git a/tooling/noir_js_backend_barretenberg/src/types.ts b/tooling/noir_js_backend_barretenberg/src/types.ts new file mode 100644 index 00000000000..b88a942d986 --- /dev/null +++ b/tooling/noir_js_backend_barretenberg/src/types.ts @@ -0,0 +1,3 @@ +export type BackendOptions = { + threads: number; +}; diff --git a/tooling/noir_js_types/src/types.ts b/tooling/noir_js_types/src/types.ts index 6285972d1e9..f534ec9a920 100644 --- a/tooling/noir_js_types/src/types.ts +++ b/tooling/noir_js_types/src/types.ts @@ -10,8 +10,8 @@ export interface Backend { generateIntermediateProof(decompressedWitness: Uint8Array): Promise; verifyFinalProof(proofData: ProofData): Promise; - verifyIntermediateProof(proofData: ProofData): Promise; + destroy(): Promise; } export type ProofData = {