diff --git a/tooling/noir_js/src/witness_generation.ts b/tooling/noir_js/src/witness_generation.ts index a329c79c919..1f233422061 100644 --- a/tooling/noir_js/src/witness_generation.ts +++ b/tooling/noir_js/src/witness_generation.ts @@ -1,8 +1,24 @@ import { abiEncode, InputMap } from '@noir-lang/noirc_abi'; import { base64Decode } from './base64_decode.js'; -import { executeCircuit, WitnessMap, ForeignCallHandler, ForeignCallInput } from '@noir-lang/acvm_js'; +import { + WitnessMap, + ForeignCallHandler, + ForeignCallInput, + createBlackBoxSolver, + WasmBlackBoxFunctionSolver, + executeCircuitWithBlackBoxSolver, +} from '@noir-lang/acvm_js'; import { CompiledCircuit } from '@noir-lang/types'; +let solver: Promise; + +const getSolver = (): Promise => { + if (!solver) { + solver = createBlackBoxSolver(); + } + return solver; +}; + const defaultForeignCallHandler: ForeignCallHandler = async (name: string, args: ForeignCallInput[]) => { if (name == 'print') { // By default we do not print anything for `print` foreign calls due to a need for formatting, @@ -26,7 +42,12 @@ export async function generateWitness( // Execute the circuit to generate the rest of the witnesses and serialize // them into a Uint8Array. try { - const solvedWitness = await executeCircuit(base64Decode(compiledProgram.bytecode), witnessMap, foreignCallHandler); + const solvedWitness = await executeCircuitWithBlackBoxSolver( + await getSolver(), + base64Decode(compiledProgram.bytecode), + witnessMap, + foreignCallHandler, + ); return solvedWitness; } catch (err) { throw new Error(`Circuit execution failed: ${err}`);