-
Notifications
You must be signed in to change notification settings - Fork 136
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
Issue with LessThan Function: No Support for Field Elements Greater Than 253 Bits #1061
Comments
I'm sure we can help you implement something custom with existing snarkyjs methods. |
Hi, I implemented a Code:
|
You can treat 255 bit numbers equivalently, instead of splitting them into 1 + 253 bits you split them into 2 + 253 bits. |
Hey, thanks for the solution. I am running into the problem where one of the input to the |
@shryasss I was suggesting that you split it into 2 + 253 in this case. If you know that inputs are smallish negative or positive numbers, say they have an absolute value < MAX, then there is an even easier solution: check whether |
Yes, I have implemented a
But as you mentioned in the last response, the inputs might not be smallish, as a negative number will be very close to the Field Order, so it won't be smallish. Also, if I do -- x + Max < y + Max, won't it be equivalent to -- x < y, I am not able to understand the difference here. Thanks for the prompt responses, appreciate it a lot! |
Yeah that's the point, it's equivalent but both sides are small, by adding MAX you turn the "negative" (close to field order) into a small positive number, so it no longer has too many bits Also, does your 2 + 253 bit solution above not work? |
I think the problem here will be that if only one of the input is close to the Field Order, then if I add the modulus to both the numbers, then the other number becomes close to the Field Order. Any thoughts on this?
Yes, it works |
I didn't suggest to add the modulus, but some number MAX that's large enough to make all your inputs positive but small enough so that x + MAX is less than 253 for all your inputs. Of course, it depends on the application whether such a number exists. As I wrote above, this is applicable if all your inputs are either small negative or small positive numbers (as is the case for many applications) |
Ohh right, got it. It makes a lot of sense to do that. Thanks, will try to implement this in my wrapper and share the code here. Thank you so much for the help!! |
solved by #1523 |
Hello,
I am currently developing a Zero-Knowledge (ZK) application and have encountered a limitation with the
lessThan
function in the Field class. Specifically, the function seems to only support field elements of size less than or equal to 253 bits.In my particular use case, I need to work with field elements that are larger than 253 bits. This limitation is causing a significant roadblock in the development of my application.
I am referring to the implementation found at this location: https://github.com/o1-labs/snarkyjs/blob/main/src/lib/field.ts#L699
I would greatly appreciate any guidance or potential solutions to overcome this limitation. Is there a workaround or an alternative function that I could use to compare larger field elements? Or is there a plan to extend the
lessThan
function to support larger field elements in the future?Thank you in advance for your assistance and I look forward to your response.
The text was updated successfully, but these errors were encountered: