diff --git a/yarn-project/acir-simulator/src/client/simulator.ts b/yarn-project/acir-simulator/src/client/simulator.ts index d5e6567e2a9..d9ec7b44799 100644 --- a/yarn-project/acir-simulator/src/client/simulator.ts +++ b/yarn-project/acir-simulator/src/client/simulator.ts @@ -168,37 +168,38 @@ export class AcirSimulator { storageSlot: Fr, notePreimage: Fr[], ) { + let abi: FunctionAbiWithDebugMetadata; try { - const abi = await this.db.getFunctionABI(contractAddress, computeNoteHashAndNullifierSelector); - - const preimageLen = (abi.parameters[3].type as ArrayType).length; - const extendedPreimage = notePreimage.concat(Array(preimageLen - notePreimage.length).fill(Fr.ZERO)); - - const execRequest: FunctionCall = { - to: AztecAddress.ZERO, - functionData: FunctionData.empty(), - args: encodeArguments(abi, [contractAddress, nonce, storageSlot, extendedPreimage]), - }; - - const [innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier] = (await this.runUnconstrained( - execRequest, - AztecAddress.ZERO, - abi, - AztecAddress.ZERO, - EthAddress.ZERO, - )) as bigint[]; - - return { - innerNoteHash: new Fr(innerNoteHash), - siloedNoteHash: new Fr(siloedNoteHash), - uniqueSiloedNoteHash: new Fr(uniqueSiloedNoteHash), - innerNullifier: new Fr(innerNullifier), - }; + abi = await this.db.getFunctionABI(contractAddress, computeNoteHashAndNullifierSelector); } catch (e) { throw new Error( `Mandatory implementation of "${computeNoteHashAndNullifierSignature}" missing in noir contract ${contractAddress.toString()}.`, ); } + + const preimageLen = (abi.parameters[3].type as ArrayType).length; + const extendedPreimage = notePreimage.concat(Array(preimageLen - notePreimage.length).fill(Fr.ZERO)); + + const execRequest: FunctionCall = { + to: AztecAddress.ZERO, + functionData: FunctionData.empty(), + args: encodeArguments(abi, [contractAddress, nonce, storageSlot, extendedPreimage]), + }; + + const [innerNoteHash, siloedNoteHash, uniqueSiloedNoteHash, innerNullifier] = (await this.runUnconstrained( + execRequest, + AztecAddress.ZERO, + abi, + AztecAddress.ZERO, + EthAddress.ZERO, + )) as bigint[]; + + return { + innerNoteHash: new Fr(innerNoteHash), + siloedNoteHash: new Fr(siloedNoteHash), + uniqueSiloedNoteHash: new Fr(uniqueSiloedNoteHash), + innerNullifier: new Fr(innerNullifier), + }; } /**