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

Document Noir PR 3045 #3191

Closed
github-actions bot opened this issue Oct 9, 2023 · 5 comments
Closed

Document Noir PR 3045 #3191

github-actions bot opened this issue Oct 9, 2023 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2023

Document PR #3045 on the Noir repository.

@guipublic
Copy link
Contributor

PR #3045 allows users to filter functions for specific field.
This is conditional compilation because functions that do not match the filter are not compiled.
To use such filter, you need to add a field attribute. For instance:

#[field(bn254)]
fn foo() -> u32 {
    1
}

#[field(23)]
fn foo() -> u32 {
    2
}

#[field(bls12_381)]
fn foo() -> u32 {
    3
}

The field attributes that we currently support are: bn254, bls12_381, and any number (in decimal or hexa form)
When the field attribute is set, noir will compile the function only if it match the native field of noir. This native field is given by feature defined on acir_field cargo.toml. Default is bn254.
In the example given, we can define a function 3 times, but only the first one will be used, because it matches the default noir field. If you re-compile noir with bs12-381, then it will use the last one. The middle one will only match if the noir field is 23. If you use the bn254 modulus value instead, then noir will complain that there are duplicate function definitions. If you use a curve name which is not defined, e.g #[field(my_great_curve)], then the field attribute will not match and the function is discarded (i.e we do not produce an error).

@critesjosh
Copy link
Contributor

thanks @guipublic! Is this useful because it allows Noir devs to write code that is more proving system agnostic? Is this being used anywhere in the Noir codebase?

@guipublic
Copy link
Contributor

thanks @guipublic! Is this useful because it allows Noir devs to write code that is more proving system agnostic? Is this being used anywhere in the Noir codebase?

Yes, the proving system specifies the curve and hence the field noir has to use. So when we write code which depends on the field, it won't work for another proving system.
This is not used in the Noir codebase, but we already have code which depends on the field and we should use the field attribute for it. I will have a look at adding it in our std-lid.

@signorecello
Copy link
Contributor

This is great! I think we don't have a dedicated page about other backends... So I'll move this to the docs monorepo and ask if someone wants to write a specific doc page about this :)

@signorecello signorecello transferred this issue from noir-lang/docs Oct 17, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 17, 2023
@signorecello signorecello added the documentation Improvements or additions to documentation label Oct 17, 2023
@Savio-Sou Savio-Sou added this to the 0.17 milestone Oct 19, 2023
@guipublic
Copy link
Contributor

I am closing this because the docs have already been updated by PR #3209

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Archived in project
Development

No branches or pull requests

4 participants