-
Notifications
You must be signed in to change notification settings - Fork 103
GLV implementation for BLS12_377, BLS12_381 and BN254 #158
Conversation
bls12_377/src/curves/unit_tests/BLS12377G2_XMD-SHA-256_SSWU_RO_.json
Outdated
Show resolved
Hide resolved
@@ -119,21 +120,112 @@ const TE_GENERATOR_Y: Fq = | |||
|
|||
/// x coordinate for SW curve generator | |||
const SW_GENERATOR_X: Fq = | |||
MontFp!("30900340493481298850216505686589334086208278925799850409469406976849338430199"); | |||
MontFp!("4732093294267640299242820317528400560681136891967543338160850811774078125840"); |
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.
Why did these generators change?
const COEFF_A: Self::BaseField = | ||
MontFp!("10773120815616481058602537765553212789256758185246796157495669123169359657269"); | ||
MontFp!("52435875175126190479447740508185965837690552500527637822603658699934817984513"); |
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.
How did the curve coefficients change? That seems fishy.
Regardless, we can use the original short values here, namely:
MontFp!("52435875175126190479447740508185965837690552500527637822603658699934817984513"); | |
MontFp!("−3763200000"); |
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.
There were changes on the coefficients in order to optimize slightly one computation.
We should use these new coefficients (matching https://eprint.iacr.org/2021/1152.pdf).
Note that the two curves are isomorphic (same order, etc.), as this SageMath script shows:
p = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
Fp = GF(p)
HD = hilbert_class_polynomial(-8)
# new coefficients from the commit, can be written using negative numbers
A1 = 52435875175126190479447740508185965837690552500527637822603658699934817984513
B1 = 52435875175126190479447740508185965837690552500527637822603658621262613184513
# previous coefficients from the commit
A2 = 10773120815616481058602537765553212789256758185246796157495669123169359657269
B2 = 29569587568322301171008055308580903175558631321415017492731745847794083609535
E1 = EllipticCurve(Fp, [A1,B1])
E2 = EllipticCurve(Fp, [A2,B2])
assert HD(E1.j_invariant()) == 0
assert HD(E2.j_invariant()) == 0
impl SWCurveConfig for BandersnatchConfig { | ||
/// COEFF_A = 10773120815616481058602537765553212789256758185246796157495669123169359657269 | ||
/// COEFF_A = 52435875175126190479447740508185965837690552500527637822603658699934817984513 |
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.
/// COEFF_A = 52435875175126190479447740508185965837690552500527637822603658699934817984513 | |
/// COEFF_A = -3763200000 |
const COEFF_B: Self::BaseField = | ||
MontFp!("29569587568322301171008055308580903175558631321415017492731745847794083609535"); | ||
MontFp!("52435875175126190479447740508185965837690552500527637822603658621262613184513"); |
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.
MontFp!("52435875175126190479447740508185965837690552500527637822603658621262613184513"); | |
MontFp!("-78675968000000"); |
|
||
/// COEFF_B = 29569587568322301171008055308580903175558631321415017492731745847794083609535 | ||
/// COEFF_B = 52435875175126190479447740508185965837690552500527637822603658621262613184513 |
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.
/// COEFF_B = 52435875175126190479447740508185965837690552500527637822603658621262613184513 | |
/// COEFF_B = -78675968000000 |
let y = p.y; | ||
|
||
// 1/(x + 44800) | ||
let tmp1 = FpConfig::inverse(&(x + var44800)).unwrap(); |
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.
Hm, inverting in the endomorphism seems to defeat the purpose, no? The endomorphism is supposed to be fast.
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.
I see, the endomorphism is fast in the Edwards form.
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.
Since the endomorphism is slow here, we should just use the normal scalar multiplication.
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.
In fact, could we adapt #102 for this task? That constructs GLV multiplication for the TE form directly, and should get the expected speed up
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.
(We could do that in a follow up PR)
this was likely a result of an old merge conflict
@Pratyush I'm thinking to just pull out the Bandersnatch changes into a separate PR, as I don't know why a new parameter set is used. Maybe later @simonmasson can add more details on this change, but I think we should move forward with the rest for now, WDYT? |
@asanso maybe you can shed some light on the new parameters as we discussed today? |
@mmagician Handling Bandersnatch in a different PR seems reasonable! |
The failing tests for curves with GLV enabled should be fixed when #171 is merged. |
Description
Updates #147 by @simonmasson to use the slightly improved trait interface from arkworks-rs/algebra#644.
Update:
Benchmarks show that there is a significant improvement for BLS12-377, BLS12-381 (40%, 37% respectively), moderate improvement for BN254 (10%) and a small improvement for Bandersnatch at 2%. The rest perform worse with GLV enabled by default. For the last group I've left the implementation of the GLV trait in, but haven't enabled it by default.
PR title reflects the defaults only.
closes: #147
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the Github PR explorer