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

The implementation of towered fields is difficult to relate to documented constructions #264

Open
daira opened this issue Apr 17, 2021 · 6 comments
Labels
D-medium Difficulty: medium P-high Priority: high T-documentation Type: doc improvements

Comments

@daira
Copy link
Contributor

daira commented Apr 17, 2021

(This issue spans algebra and curves, but seems more pertinent here.)

Consider the implementation of towers of field extensions, for example here for BLS12-381. The usual way to describe such towers is by the irreducible polynomial used for each extension. For instance, the bls12_381 crate implements Fp2 as Fp[u]/(u2 + 1), and then Fp6 as Fp2[v]/(v3 - (u + 1)), and then Fp12 as Fp6[w]/(w2 - v).

(Strictly speaking there's an abuse of notation here because, e.g. when we write Fp6[w]/(w2 - v) we're conflating the field Fp6 with its representation, but apparently everyone abuses notation that way.)

The choice of irreducible polynomials is fairly arbitrary, but for interoperability it's best for the originator of a curve to pick them and for everyone to use the same ones for that curve. A specific representation for each extension field used by a pairing is needed, at least in order to unambiguously specify the curve and generator for G2, and for test vectors. (You can technically convert between representations, but it's a pain and no-one should need to do that extra work.)

The problem is that the implementation of a tower in arkworks doesn't directly specify these irreducible polynomials (and also doesn't document what they are for existing implementations). Each extension specifies a NONRESIDUE, and Fp2 extensions also specify a QUADRATIC_NONRESIDUE, but I can't tell how these relate to the irreducible polynomial, even after poring over the implementations in algebra/ff/src/fields/models.

@weikengchen
Copy link
Member

I agree that the irreducible polynomial is basically hidden throughout both repos. And it seems that the current implementations in https://github.com/arkworks-rs/algebra/tree/master/ff/src/fields/models focus on only specific irreducible polynomials.

Should we add more explanations in models? Do you think there will be use cases that use more special irreducible polynomials?

@weikengchen
Copy link
Member

(Note: generally there exist some prime numbers that could cause some of these polynomials to be not irreducible, but it seems to be rare)

@daira
Copy link
Contributor Author

daira commented Apr 17, 2021

If I had to guess by extrapolation from BLS12-381, I'd guess that a k-extension uses the irreducible polynomial uk - NONRESIDUE. Is that right?

More explanation would definitely be good!

It's not so rare; e.g. Pluto's field cannot use u2 + 1 for Fp2, and so it is currently specified to use u2 + 5 (I'll change that if needed). In fact u2 + 1 will never be irreducible for a pairing or half-pairing cycle with high 2-adicity, because we must have p = 1 (mod 8).

@daira
Copy link
Contributor Author

daira commented May 14, 2021

This is blocking my implementation of Pluto and Triton in arkworks-rs/curves#54. The documentation needed is of how the constants such as NONRESIDUE and QUADRATIC_NONRESIDUE correspond to the usual description of a tower.

@Pratyush
Copy link
Member

Pratyush commented May 14, 2021

QUADRATIC_NONRESIDUE is used only as an implementation detail in the square-root algorithm, while NONRESIDUE is used to construct the extension. Eg, see here for quadratic extensions and here for cubic extensions.

The documentation on QuadExtField should be helpful also.

@weikengchen
Copy link
Member

So it seems that it is possible to implement u^2+5, just one needs to choose the NONRESIDUE in Fq2Parameters to be -5.

On a related note, I recently also implemented the BN446 inside the arkworks environment here: https://github.com/oblivious-file-sharing/netherite-algebra/tree/main/src/curve_bn446
It has associated Sage scripts, which may be helpful.

@Pratyush Pratyush added D-medium Difficulty: medium P-high Priority: high T-documentation Type: doc improvements labels Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-medium Difficulty: medium P-high Priority: high T-documentation Type: doc improvements
Projects
Development

No branches or pull requests

3 participants