Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute note type id in Noir instead of Rust #7165

Closed
Tracked by #5070 ...
benesjan opened this issue Jun 24, 2024 · 1 comment
Closed
Tracked by #5070 ...

Compute note type id in Noir instead of Rust #7165

benesjan opened this issue Jun 24, 2024 · 1 comment
Labels
S-blocked Status: Blocked

Comments

@benesjan
Copy link
Contributor

benesjan commented Jun 24, 2024

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)
}
@benesjan
Copy link
Contributor Author

benesjan commented Oct 4, 2024

Already addressed

@benesjan benesjan closed this as completed Oct 4, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in A3 Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked
Projects
Archived in project
Development

No branches or pull requests

1 participant