Skip to content

Compute note type id in Noir instead of Rust #7165

Closed

Description

@benesjan

Blocked by meta programming.

In this PR I've introduced a tiny-keccak dependency to macros and I compute the note type id directly in the rust macro code. This is unnecessary because instead we can just compute the value in Noir. This will not result in an unnecessary gate count increase because Noir evaluates constants during compile time.

I actually already tried implementing this but the changes turned out to be very complicated because in the current macro code we try to fetch the note type id directly from HIR when we are injecting note exports (inject_note_exports function). The issue is that at that point in compilation timeline the constants were not evaluated yet and the function throws for that reason.

I decided to give up on trying to make it work due to us completely rewriting the macros in a not-so-distant future due to meta programming. Once meta programming is in place, we should try tackling this (or ideally do it the correct way during the rewrite).

Here is the Noir functionality I've implemented but eventually reverted:

 use crate::utils::field::field_from_bytes;

global SELECTOR_SIZE = 4;

pub fn compute_note_selector<N>(signature: str<N>) -> Field {
    let bytes = signature.as_bytes();
    let hash = dep::std::hash::keccak256(bytes, bytes.len() as u32);

    let mut selector_be_bytes = [0; SELECTOR_SIZE];
    for i in 0..SELECTOR_SIZE {
        selector_be_bytes[i] = hash[i];
    }

    field_from_bytes(selector_be_bytes, true)
}

Activity

  1. benesjan commented on Oct 4, 2024

    @benesjan
    ContributorAuthor

    Already addressed

  2. moved this from Todo to Done in A3on Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions