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

fix: error handling in acir simulator #1907

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all 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
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