In compute_raw_note_log function we check whether a note hash of a note for which we are computing log for was already inserted:
let note_exists = context.note_hashes.storage.any(|n: NoteHash| n.counter == note_hash_counter);
assert(note_exists, "Can only emit a note log for an existing note.");
This costs gates and it should not be necessary because we have the information of whether a note has been inserted "somewhere else" in the codebase. One way how we could communicate that the note hash has indeed been inserted is to use the type system and wrap a note that has been inserted in smt. like InsertedNote struct.
Note: The only relevant place where we insert the note hash is in the create_note function in lifecycle.nr so wrapping the note there should be enough.
In
compute_raw_note_logfunction we check whether a note hash of a note for which we are computing log for was already inserted:This costs gates and it should not be necessary because we have the information of whether a note has been inserted "somewhere else" in the codebase. One way how we could communicate that the note hash has indeed been inserted is to use the type system and wrap a note that has been inserted in smt. like
InsertedNotestruct.Note: The only relevant place where we insert the note hash is in the
create_notefunction inlifecycle.nrso wrapping the note there should be enough.