ethereum / ethereum/py_ecc

Switch curve_name from string to NamedTuple

Open
#57 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
231
Forks
88
PR merge metrics
No merged PRs in 30d

Description

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

```py
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.