Skip to content
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