Skip to content

Commit

Permalink
fix: error handling in acir simulator (#1907)
Browse files Browse the repository at this point in the history
Try catch statement was encapsulating unnecessarily big block of code
and this resulted in an incorrect error being shown when a constraint in
simulation was not satisfied. This PR fixes it.
  • Loading branch information
benesjan authored Aug 31, 2023
1 parent 8223be1 commit 165008e
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions yarn-project/acir-simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

/**
Expand Down

0 comments on commit 165008e

Please sign in to comment.