-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
There was a problem hiding this 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.
if power % 2 != 0 { | ||
self.conjugate() | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
* Comment residues used for field extensions * Remove unusued functions and constants * Correct forb constant comment
Fixes #91 and #90.
This PR removes some unused functions and corrects some comments regarding its constants.