feat(std): add LessThan() and IsEqual() #234
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi guys,
I've found some time to give this a go :).
I have implemented
LessThan()
andIsEqual()
as a newmath
package understd
. Currently, this implementation gives it great isolation and builds on top of the currentfrontend.api
without touching it.I was hoping to simplify
LessThan()
to computea < b
, however, I found that I still needed the full functionality ofCompare()
. If b is greater than a, it needs to be recorded too and persisted to the end of the loop. Without this, ifa
has a less significant bit set whereb
's is not, then it will appear as thougha > b
incorrectly.As such, I wanted to ask whether you guys wanted to relax the feature from
LessThan()
toCompare()
given both require the same amount of work, butCompare()
gives more functionality to the user. I can also see the benefit of simplifying the interface and keeping it asLessThan()
, so also happy to keep it just as is and include the reduction done in the final lines of the current implementation:Another thing I was hoping to do was to add it directly into
frontend.api
. However, I had some issues getting the tests to run. Here is the link to my attempted commit on my fork: LINKAn example of the error is:
However, this implementation also means that the code has to be duplicated thrice across
r1cs
,plonk
andengine
. I could not work out a way to prevent code duplication here if I added it straight intofrontend.api
.What do you guys think? I like the idea of having
api.LessThan()
andapi.IsEqual()
; however it may be cleaner to have these in a newstd/math
package.Open to suggestions and feedback!