aztec-nr - noir_aztec::messages::discovery

Type alias ComputeNoteHashAndNullifier

pub type ComputeNoteHashAndNullifier<Env> = unconstrained fn[Env](BoundedVec<Field, 11>, Field, Field, AztecAddress, Field, Field) -> Option<NoteHashAndNullifier>;

A function which takes a note's packed content, address of the emitting contract, note nonce, storage slot and note type ID and attempts to compute its note hash (not hashed by note nonce nor siloed by address) and inner nullifier (not siloed by address).

This function must be user-provided as its implementation requires knowledge of how note type IDs are allocated in a contract. The #[aztec] macro automatically creates such a contract library method called _compute_note_hash_and_nullifier, which looks something like this:

|packed_note, contract_address, note_nonce, storage_slot, note_type_id| {
    if note_type_id == MyNoteType::get_id() {
        assert(packed_note.len() == MY_NOTE_TYPE_SERIALIZATION_LENGTH);

        let note = MyNoteType::unpack(aztec::utils::array::subarray(packed_note.storage(), 0));

        let note_hash = note.compute_note_hash(storage_slot);
        let note_hash_for_nullification = aztec::note::utils::compute_note_hash_for_nullification(
            RetrievedNote{ note, contract_address, metadata: SettledNoteMetadata::new(note_nonce).into() },
            storage_slot
        );

        let inner_nullifier = note.compute_nullifier_unconstrained(note_hash_for_nullification);

        Option::some(
            aztec::messages::discovery::NoteHashAndNullifier {
                note_hash, inner_nullifier
            }
        )
    } else if note_type_id == MyOtherNoteType::get_id() {
          ... // Similar to above but calling MyOtherNoteType::unpack_content
    } else {
        Option::none() // Unknown note type ID
    };
}