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

Switch curve_name from string to NamedTuple #57

Open
carver opened this issue Mar 6, 2019 · 1 comment
Open

Switch curve_name from string to NamedTuple #57

carver opened this issue Mar 6, 2019 · 1 comment

Comments

@carver
Copy link
Collaborator

carver commented Mar 6, 2019

py_ecc/fields/__init__.py has a lot of duplications and is at high risk of typos (like importing the coeffs or field modulus from the wrong curve).

Let's think about alternatives to this setup. Maybe something like:

class Curve(NamedTuple):
  field_modulus: int
  fq12_modulus_coeffs: Tuple[int, ...]
  fq2_modulus_coeffs: Tuple[int, int]

bls12_381 = Curve(
  field_modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583,
  fq2_modulus_coeffs = (1, 0),
  fq12_modulus_coeffs = (2, 0, 0, 0, 0, 0, -2, 0, 0, 0, 0, 0),  # Implied + [1]
)

^ This still doesn't feel quite right, but it's a starting point.

The end goal is to be able to create bn128_FQ2 with a reference to a single thing (like this new NamedTuple)

Of course, this approach comes at the downside of having to import the curve to create an FQ. Maybe a little more annoying at the REPL. But for the caller in a file, it means fewer magic strings and less likelihood for a typo with a confusing error. For the library, hopefully better readability.

Originally posted by @carver in https://github.com/_render_node/MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0OTIyNTg5NQ==/comments/review_comment

@Bhargavasomu
Copy link
Contributor

Bhargavasomu commented Mar 6, 2019

This would happen in the second phase of the refactoring upgrading process where, even the curves would be generalized and all their properties would be encapsulated as a NamedTuple.

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

No branches or pull requests

2 participants