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

feat(std): add LessThan() and IsEqual() #234

Closed
wants to merge 1 commit into from

Conversation

vck3000
Copy link

@vck3000 vck3000 commented Jan 14, 2022

Hi guys,

I've found some time to give this a go :).

I have implemented LessThan() and IsEqual() as a new math package under std. Currently, this implementation gives it great isolation and builds on top of the current frontend.api without touching it.

I was hoping to simplify LessThan() to compute a < b, however, I found that I still needed the full functionality of Compare(). If b is greater than a, it needs to be recorded too and persisted to the end of the loop. Without this, if a has a less significant bit set where b's is not, then it will appear as though a > b incorrectly.

As such, I wanted to ask whether you guys wanted to relax the feature from LessThan() to Compare() given both require the same amount of work, but Compare() gives more functionality to the user. I can also see the benefit of simplifying the interface and keeping it as LessThan(), so also happy to keep it just as is and include the reduction done in the final lines of the current implementation:

	// Now, convert output of Convert() into LessThan()
	return m.IsEqual(output, -1)

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: LINK

An example of the error is:

=== RUN   TestCompare/fuzz/bw6_761/plonk
    assert.go:356:
                Error Trace:    assert.go:356
                                                        assert.go:70
                Error:          Received unexpected error:
                                compilation is not deterministic
                Test:           TestCompare/fuzz/bw6_761/plonk

However, this implementation also means that the code has to be duplicated thrice across r1cs, plonk and engine. I could not work out a way to prevent code duplication here if I added it straight into frontend.api.

What do you guys think? I like the idea of having api.LessThan() and api.IsEqual(); however it may be cleaner to have these in a new std/math package.

Open to suggestions and feedback!

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@vck3000
Copy link
Author

vck3000 commented Jan 14, 2022

Hmm, the CLA caught me by surprise. I will have to consult with my research department to see whether I can sign it. Please give me some time to do this. In the meantime, I'd still love to hear your thoughts :).

@vck3000
Copy link
Author

vck3000 commented Jan 14, 2022

Oh, never mind. I just saw #233.

@ThomasPiellard
Copy link
Collaborator

Hi @vck3000 , yes I just pushed a similar PR 1hour ago^^ I have added this directly to the api (so the api interface is modified also).

@vck3000
Copy link
Author

vck3000 commented Jan 14, 2022

Sounds good :). Will close this then.

@vck3000 vck3000 closed this Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants