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 2 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
6 changes: 5 additions & 1 deletion tooling/noir_js/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import initAbi, { abiDecode, InputMap, InputValue } from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';
import { witnessMapToUint8Array } from './serialize.js';

export class Noir {
export class Noir implements Noir {
signorecello marked this conversation as resolved.
Show resolved Hide resolved
constructor(
private circuit: CompiledCircuit,
private backend?: Backend,
Expand All @@ -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
11 changes: 6 additions & 5 deletions tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { acirToUint8Array } from './serialize.js';
import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
import { Backend, BackendOptions, CompiledCircuit, ProofData } from '@noir-lang/types';

// This is the number of bytes in a UltraPlonk proof
// minus the public inputs.
Expand All @@ -14,11 +14,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 +28,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
6 changes: 5 additions & 1 deletion tooling/noir_js_types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ export interface Backend {
generateIntermediateProof(decompressedWitness: Uint8Array): Promise<ProofData>;

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

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

export type BackendOptions = {
threads: number;
};

signorecello marked this conversation as resolved.
Show resolved Hide resolved
export type ProofData = {
publicInputs: Uint8Array[];
proof: Uint8Array;
Expand Down
Loading