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

Add gte and lte functions to BN254 library #7580

Open
partylikeits1983 opened this issue Mar 4, 2025 · 2 comments
Open

Add gte and lte functions to BN254 library #7580

partylikeits1983 opened this issue Mar 4, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@partylikeits1983
Copy link

partylikeits1983 commented Mar 4, 2025

Problem

The bn254 field library does not have eq, gte, nor lte functions. It is possible to compare equality of fields with == however, I believe the following syntax is useful:

let a: Field = 1;
let b: Field = 1;
let is_equal = a.eq(b);

Also the syntax:

let a: Field = 0;
let b: Field = 1;
let is_lte = a.lte(b);
let a: Field = 1;
let b: Field = 0;
let is_gte = a.gte(b);

would be super useful to have.

Why?

Since these functions are not implemented it requires the circuit developer to add extra complexity to their circuit, which is bad devEx.

Proposed change

This functionality was proposed in this PR: #7572, however the PR was closed due to lack of consensus among the core team regarding the best path forward to implement this functionality.

It would be even better to be able to use the operators <= and >= with fields natively.

Would be great if the Noir team could reach a consensus regarding how to add this basic functionality.

@TomAFrench @critesjosh @zac-williamson

Happy Case

Leave constructive feedback and a path forward regarding how to implement basic functionality to improve developer experience and engage constructively with developers looking to use Noir in a production environment.

Workaround

None

Would you like to submit a PR for this Issue?

Open to creating a draft PR.

@vezenovm
Copy link
Contributor

vezenovm commented Mar 5, 2025

It would be even better to be able to use the operators <= and >= with fields natively.

DevEx is not the only concern when comparing fields. Safety is also one of Noir's main tenets. We have not exposed < and > natively on fields thus far like we do integer types due to these safety concerns. Finite fields do not have an inherent ordering, which can lead to vulnerabilities especially for developers unfamiliar with finite field arithmetic.

We expose lt for advanced users who desire to perform arithmetic logic on fields. However, we would like to move away from a free function (due to it not being very user friendly as you mentioned). Adding more of these methods when they will possibly be deprecated in the future will just lead to more breaking changes down the line.

We definitely want to improve DevEx for field comparisons, but it has taken a backseat to other priorities.

@partylikeits1983
Copy link
Author

@vezenovm I agree that using free functions isn’t the best approach for handling field comparisons. Instead, by converting field elements to their canonical integer representations, we can directly compare the integers. I’m open to working on this improvement and can open a draft PR to implement the changes.

@Savio-Sou Savio-Sou removed the status in Noir Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants