Skip to content

Custom implementation of NoteInterface::get_note_type_id needs to return the same id as generated by macros #12012

@benesjan

Description

@benesjan

When a note with a custom implementation of NoteInterface::get_note_type_id does not return the value as is set by macros then the code becomes broken in multiple places:

  1. compute_note_hash_and_optionally_a_nullifier function uses an incorrect id and the code panics as a result,
  2. note type id in the TS artifact is incorrect which can cause various issues in tests etc.

This is caused by the fact that in the macros we use the counter value and not the one from the custom impl.:

pub comptime fn note_custom_interface(s: StructDefinition) -> Quoted {
    let (packable_impl, note_packed_len) = derive_packable_if_not_implemented_and_get_len(s);
    **let note_type_id = get_next_note_type_id()**;

    let (indexed_fixed_fields, indexed_nullable_fields) = index_note_fields(s, &[]);
    register_note(
        s,
        note_packed_len,
        **note_type_id**,
        indexed_fixed_fields,
        indexed_nullable_fields,
    );

...
}

I don't think we can get a hold of the note type id here because the function is comptime and hence we cannot call the runtime NoteInterface::get_note_type_id function here.

I don't really see a value of letting the user define custom get_note_type_id function so I would say trying to rethink the interface would make sense.

The #[note_custom_interface] macro is not really used much which is the reason why we have not stumbled upon this yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-aztec.nrComponent: Aztec smart contract frameworkT-bugType: Bug. Something is broken.team-fairiesNico's team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions