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

Fix nits in bn256. #99

Merged
merged 3 commits into from
Nov 23, 2023
Merged

Fix nits in bn256. #99

merged 3 commits into from
Nov 23, 2023

Conversation

davidnevadoc
Copy link
Contributor

Fixes #91 and #90.

This PR removes some unused functions and corrects some comments regarding its constants.

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! THanks for addressing these nits!
Left some comments to briefly discuss/address/elaborate.

Comment on lines +275 to +277
if power % 2 != 0 {
self.conjugate()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you shift by one to the right and && by a mask? Might be harder to read but we're sure that will always be as optimized as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to do this properly since power is usize.
We can use its methods for example:

if power.trailing_zeros() != 0 {
    self.conjugate()
        }

but I don't think it is worth it.

@@ -271,12 +272,14 @@ impl Fq2 {
}

pub fn frobenius_map(&mut self, power: usize) {
self.c1 *= &FROBENIUS_COEFF_FQ2_C1[power % 2];
if power % 2 != 0 {
self.conjugate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conjugate can't be a const fn as it is done "in place". I wonder if we can gain any speedup by not making it get an &mut and declaring the fn const.

kk since it relies in Sub which isn't const this will not work. So this is fine as is.
Just leaving the comment with my reasoning so you can double-check

@@ -513,7 +508,7 @@ pub const FROBENIUS_COEFF_FQ6_C1: [Fq2; 6] = [
];

pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [
// Fq2(u + 1)**(((2q^0) - 2) / 3)
// Fq2(u + 9)**(((2q^0) - 2) / 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate where's this 9 coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous value is the cubic non_residue for Bls12-381. The values for the field extensions of Bn are :

   Fp2  = Fp[X]  / <X^2 + 1>             alpha^2 = -1
   Fp6  = Fp2[X] / <X^3 - (alpha + 9>    beta^3  = alpha + 9
   Fp12 = Fp6[X] / <X^2 - beta>          gamma^2 = beta

@davidnevadoc davidnevadoc added this pull request to the merge queue Nov 23, 2023
Merged via the queue into main with commit d59aaa0 Nov 23, 2023
7 checks passed
jonathanpwang pushed a commit to axiom-crypto/halo2curves that referenced this pull request Nov 29, 2023
* Comment residues used for field extensions

* Remove unusued functions and constants

* Correct forb constant comment
@davidnevadoc davidnevadoc deleted the nev@bn-frob-const branch December 1, 2023 18:29
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

Successfully merging this pull request may close these issues.

Simplify frobenius_map in bn256
2 participants