Fix curves interfaces inconsistencies #35
Merged
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.
On the current master branch, the interfaces of the various curves are not consistent.
This is problematic as we cannot write code that would work for all curves and be generic.
This issue has to deal with how coordinates are managed in all curves implementations.
There are 5 curves implementations:
All these implementations follow different approaches to represent and access the points coordinates:
X, Y, Z
(see: https://github.com/scipr-lab/libff/blob/master/libff/algebra/curves/alt_bn128/alt_bn128_g1.hpp#L35)coord
which is an array of 3 elements (see: https://github.com/scipr-lab/libff/blob/master/libff/algebra/curves/bn128/bn128_g1.hpp#L36)X, Y, Z
(see: https://github.com/scipr-lab/libff/blob/master/libff/algebra/curves/edwards/edwards_g1.hpp#L32)X_, Y_, Z_
, with gettersX(), Y(), Z()
(see: https://github.com/scipr-lab/libff/blob/master/libff/algebra/curves/mnt/mnt4/mnt4_g1.hpp#L49-L51 and https://github.com/scipr-lab/libff/blob/master/libff/algebra/curves/mnt/mnt4/mnt4_g1.hpp#L27-L28)(Note that the comment above only links to the groups G1, but the same applies for the G2 groups).
As such, we see that there are 3 different methods used to handle the point coordinates.
This is problematic since we cannot easily switch "one curve for another" and write generic code.
An example of affected project is: https://github.com/clearmatics/zeth, especially the functions here: https://github.com/clearmatics/zeth/pull/181/files
This PR fixes the above issue by refactoring the groups interfaces consistently. The convention followed is the one of the
alt_bn128
andedwards
curves where the point coordinates are public attributes calledX, Y, Z
.Important note1: This is a breaking change.
Important note2: I haven't ran benchmarks for this change. I suspect that the bn128 arithmetic may be a tiny bit affected by the changes as we need to pay the cost of filling the coordinate arrays before calling the functions from the namespace
bn::ecop
. This should be negligible compared to the actual "curve arithmetic" though.