Skip to content

Commit

Permalink
replicating changes in noir-lang/noir#4227
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Feb 13, 2024
1 parent 3562f6d commit 30f7f64
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const debug = createDebug('bb.js:wasm');

export type BackendOptions = {
threads?: number;
memory?: { initial?: number; maximum?: number };
memory?: { maximum: number };
};

/**
Expand All @@ -32,7 +32,7 @@ export class Barretenberg extends BarretenbergApi {
const worker = createMainWorker();
const wasm = getRemoteBarretenbergWasm<BarretenbergWasmMainWorker>(worker);
const { module, threads } = await fetchModuleAndThreads(desiredThreads);
await wasm.init(module, threads, proxy(debug), memory?.initial, memory?.maximum);
await wasm.init(module, threads, proxy(debug), memory?.maximum);
return new Barretenberg(worker, wasm);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase {
module: WebAssembly.Module,
threads = Math.min(getNumCpu(), BarretenbergWasmMain.MAX_THREADS),
logger: (msg: string) => void = debug,
initial = 26,
maximum = 2 ** 16,
initial = 26,
) {
this.logger = logger;

Expand Down
5 changes: 3 additions & 2 deletions noir/tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
import { BackendOptions } from './types.js';
import { deflattenPublicInputs, flattenPublicInputsAsArray } from './public_inputs.js';
import { type Barretenberg } from '@aztec/bb.js';
import { cpus } from 'os';

export { publicInputsToWitnessMap } from './public_inputs.js';

Expand All @@ -24,7 +25,7 @@ export class BarretenbergBackend implements Backend {

constructor(
acirCircuit: CompiledCircuit,
private options: BackendOptions = { threads: 1 },
private options: BackendOptions = { threads: navigator ? navigator.hardwareConcurrency : cpus().length },
) {
const acirBytecodeBase64 = acirCircuit.bytecode;
this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64);
Expand All @@ -34,7 +35,7 @@ export class BarretenbergBackend implements Backend {
async instantiate(): Promise<void> {
if (!this.api) {
const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js');
const api = await Barretenberg.new({ threads: this.options.threads });
const api = await Barretenberg.new(this.options);

const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode);
const crs = await Crs.new(subgroupSize + 1);
Expand Down
2 changes: 2 additions & 0 deletions noir/tooling/noir_js_backend_barretenberg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
export type BackendOptions = {
/** @description Number of threads */
threads: number;
/** @description Maximum memory to be allocated to the WASM (optional) */
memory?: { maximum: number };
};

0 comments on commit 30f7f64

Please sign in to comment.