-
Notifications
You must be signed in to change notification settings - Fork 151
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
New architecture for template generator #5
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…les; generate only BW6-761 for now
… a piece of the tower generator
…fp. TODO: generate all code for one curve before moving on to the next
…pairing, recover bls381 pairing as a sanity check
…bls381 only for now
…o as to split Frobenius code from pairing.go like in bls381. This allows convenient diff checking for the new way to generate Frobenius constants
…enius constants automatically from the new template
…generate primefields for all curves in sequence; coooool
…y, recover all 4 curve towers
…ng for all 4 curves; TODO pairing for bw6-761 is incomplete, still need to port gpoint to the new architecture
…edding degree 6, ie. BW6-761
…e only the import statements in imports.go
…of template generators
By the way, this PR also contains some new code for BW6-761 pairing: Frobenius and final exponentiation. TODO for BW6-761
|
…6-761. Tests auto-generated by tweaking gnark commit 7dcd496
…ation; final exp currently fails
…ompare final exp against sage code from eprint 2020/351
…or BW6-761 FinalExponentiation!
Closed
…elete the sage script I used to find them
ThomasPiellard
approved these changes
Jun 15, 2020
…ator---it's mostly curve-specific code anyway; restore go generate ./internal/... in config.yml; regenerate code
We now have a working pairing for BW6-761. Ready to merge. Several optimizations remain TODO. For example:
Clean-up TODO:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why?
It is now much easier to automatically compute constants required for code generation from within gurvy instead of manually copy-pasting from sage. (Also, I did some house cleaning. There's still lots more cleaning needed though.)
The flagship example is the methods
MulByNonResiduexPowery
found infrobenius.go
for each curve. Another example is the inverse of 2 modulop
used in curves with a field tower of the form used by BLS12-381, BW6-761. There are several other constants whose computation could also be automated in this way.In the future, it will be easier to add new constants or new curves to gurvy. Perhaps one could even use this new architecture to reduce reliance on sage to make tests, though I suspect the complete elimination of sage from the process is not yet worth the effort.
Overview
Prior to this PR, all code (goff, tower, curve groups, pairing) for each curve was generated from a single executable invoked from the root directory via
go generate ./internal/...
. This single executable prevented the use of code generated earlier in the process to generate subsequent code. For example, it was not possible to use code from goff or the field tower to generate code for the pairing. Thus, it was impossible, for example, to automate the computation of constants used in Frobenius computations. Instead, these constants must be computed manually in sage and copy-pasted into gurvy's Go codebase.By contrast, the new architecture splits code generation into four worker executables: one for each of goff, tower, curve groups, pairing. These four workers are managed by another master executable, so the original user-facing terminal command is the same: all code is generated with a single command:
Each worker is invoked under-the-hood via
go run
, which automatically compiles the executable from source before executing. Some of that source is generated by previous workers, so newly generated code is instantly compiled into the next worker's executable.The new architecture
/internal/generators/main.go
. It contains all the info required to generate all the curves.curve
package.primefields
,tower
,gpoint
, andpairing
. Each imports fromcurve
---that's how they get their arguments.generator.go
. The master executable invokesmain/main.go
viago run
.main.go
is typically just a wrapper that importscurve
(as a way to get curve info) and invokesgenerator.go
.primefields
worker has this simple structure. All the work is done bygoff
, so no more code is needed here.primefields
provide their own templates instead of invokinggoff
. For these workers, template code appears in atemplates/
directory.generated-code.go
.import
statement, so it is included ingenerator.go
. See for example: https://github.com/ConsenSys/gurvy/blob/17fb8608bf278e67ad264849ef11ed3a3d260f0b/internal/generators/tower/generator.go#L103main.go
. Example: https://github.com/ConsenSys/gurvy/blob/17fb8608bf278e67ad264849ef11ed3a3d260f0b/internal/generators/main.go#L130generate.go
simple, this extra generation code is typically split into other source files at the worker's root. (Example: computation of Frobenius constants inpairing/constants.go
.)