Skip to content

Commit

Permalink
Merge 5e31907 into 806b864
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Aug 5, 2024
2 parents 806b864 + 5e31907 commit 12f2d45
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
11 changes: 1 addition & 10 deletions noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,7 @@ pub fn compute_note_hash_for_consumption<Note, let N: u32, let M: u32>(note: Not
// tree) created in a previous TX. So we need the siloed_note_hash which has already been hashed with
// nonce and then contract address. This hash will match the existing leaf in the note hash
// tree, so the kernel can just perform a membership check directly on this hash/leaf.
let unique_note_hash = compute_unique_note_hash(header.nonce, note_hash);
compute_siloed_note_hash(header.contract_address, unique_note_hash)
// IMPORTANT NOTE ON REDUNDANT SILOING BY CONTRACT ADDRESS: The note hash computed above is
// "siloed" by contract address. When a note hash is computed solely for the purpose of
// nullification, it is not strictly necessary to silo the note hash before computing
// its nullifier. In other words, it is NOT NECESSARY for protocol security that a nullifier
// be computed from a siloed note hash. After all, persistable note hashes and nullifiers are
// siloed by the kernel circuit. That being said, the siloed note hash computed above CAN be
// used for nullifier computation, and this achieves the (arguably unnecessary) property that
// nullifiers are computed from a note hash's fully-computed note hash tree leaf.
compute_unique_note_hash(header.nonce, note_hash)
}
}

Expand Down
14 changes: 5 additions & 9 deletions yarn-project/simulator/src/client/simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AztecNode, CompleteAddress, Note } from '@aztec/circuit-types';
import { GeneratorIndex, KeyValidationRequest, computeAppNullifierSecretKey, deriveKeys } from '@aztec/circuits.js';
import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
import { computeUniqueNoteHash } from '@aztec/circuits.js/hash';
import { type FunctionArtifact, getFunctionArtifact } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
Expand Down Expand Up @@ -63,9 +63,8 @@ describe('Simulator', () => {
const note = createNote();
const noteHash = computeNoteHash(storageSlot, note.items);
const uniqueNoteHash = computeUniqueNoteHash(nonce, noteHash);
const siloedNoteHash = siloNoteHash(contractAddress, uniqueNoteHash);
const innerNullifier = poseidon2HashWithSeparator(
[siloedNoteHash, appNullifierSecretKey],
[uniqueNoteHash, appNullifierSecretKey],
GeneratorIndex.NOTE_NULLIFIER,
);

Expand All @@ -78,12 +77,9 @@ describe('Simulator', () => {
note,
);

expect(result).toEqual({
noteHash,
uniqueNoteHash,
siloedNoteHash,
innerNullifier,
});
expect(result.noteHash).toEqual(noteHash);
expect(result.uniqueNoteHash).toEqual(uniqueNoteHash);
expect(result.innerNullifier).toEqual(innerNullifier);
});

it('throw if the contract does not implement "compute_note_hash_and_optionally_a_nullifier"', async () => {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export class AcirSimulator {
}

/**
* Computes the inner nullifier of a note.
* Computes note hashes and an inner nullifier.
* @param contractAddress - The address of the contract.
* @param nonce - The nonce of the note hash.
* @param storageSlot - The storage slot.
* @param noteTypeId - The note type identifier.
* @param computeNullifier - A flag indicating whether to compute the nullifier or just return 0.
* @param note - The note.
* @returns The nullifier.
* @returns Note hashes and inner nullifier (nullifier before contract address siloing).
*/
public async computeNoteHashAndOptionallyANullifier(
contractAddress: AztecAddress,
Expand Down

0 comments on commit 12f2d45

Please sign in to comment.