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

Perf: KZG with fixed-argument pairing in affine coordinates #466

Merged
merged 29 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a620985
refactor: remove G1 from KZG verifiying key
yelhousni Oct 25, 2023
132e06b
perf(bw6): precomuting lines in pairing
yelhousni Oct 26, 2023
809ca82
refactor(bw6): simplify PrecomputeLines
yelhousni Oct 26, 2023
9c64699
perf(bw6): precomuting lines in pairing in affine
yelhousni Oct 26, 2023
ecccc50
perf(bw6): use precomputed affine lines in kzg
yelhousni Oct 26, 2023
065b135
perf(bw6-756): precomuting lines in pairing in affine + kzg
yelhousni Oct 31, 2023
8c017da
perf(bn254): precomuting lines in pairing in affine
yelhousni Nov 2, 2023
9259e02
perf(bn254): use precomputed affine lines in kzg
yelhousni Nov 2, 2023
e8d9e09
perf(bls12-377): precomuting lines in pairing in affine
yelhousni Nov 3, 2023
b596dbe
perf(bls12-377): use precomputed affine lines in kzg
yelhousni Nov 3, 2023
a22be87
perf(bls24-315): precomuting lines in pairing in affine
yelhousni Nov 3, 2023
749cbdf
perf(bls24-315): use precomputed affine lines in kzg
yelhousni Nov 3, 2023
f883b34
perf(bls12-381): precomuting lines in pairing in affine
yelhousni Nov 3, 2023
7e180a6
perf(bls12-378): precomuting lines in pairing in affine
yelhousni Nov 3, 2023
39726b0
perf(bls24-317): precomuting lines in pairing in affine
yelhousni Nov 3, 2023
46ba6a5
perf(bls12-381): use precomputed affine lines in kzg
yelhousni Nov 3, 2023
66f0ffc
perf(bls12-378): use precomputed affine lines in kzg
yelhousni Nov 3, 2023
73755d8
perf(bls24-317): use precomputed affine lines in kzg
yelhousni Nov 3, 2023
4a2b903
refactor: generify and consolidate new kzg and fixed-arg pairing
yelhousni Nov 3, 2023
ced3c7b
fix: kzg template for bn254
yelhousni Nov 3, 2023
a646db6
refactor(bw6-633): use revisited Ate pairing instead of Tate
yelhousni Nov 6, 2023
07b87ae
perf(bw6-633): precomuting lines in pairing in affine
yelhousni Nov 6, 2023
689cd26
fix(kzg): bw6-633 vk marshal
yelhousni Nov 6, 2023
5e633e8
refactor: consolidate fixed-argument pairing across curves
yelhousni Nov 6, 2023
bf5af37
docs: skipping inf points in PairFixedQ is implicit
yelhousni Nov 7, 2023
47d3c08
docs: fix misspelled comment
yelhousni Nov 7, 2023
ea69954
perf: specialize mul by affine lines
yelhousni Nov 8, 2023
683b7b0
perf: batchInvert 1/P.Y in fixed-arg pairing
yelhousni Nov 15, 2023
3abc810
refactor: apply code review suggestions
yelhousni Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ecc/bls12-377/bls12-377.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var g1Infinity G1Jac
var g2Infinity G2Jac

// optimal Ate loop counter
var loopCounter [64]int8
var LoopCounter [64]int8

// Parameters useful for the GLV scalar multiplication. The third roots define the
// endomorphisms ϕ₁ and ϕ₂ for <G1Affine> and <G2Affine>. lambda is such that <r, ϕ-λ> lies above
Expand Down Expand Up @@ -134,7 +134,7 @@ func init() {
endo.v.A0.SetString("216465761340224619389371505802605247630151569547285782856803747159100223055385581585702401816380679166954762214499")

// binary decomposition of x₀ little endian
loopCounter = [64]int8{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1}
LoopCounter = [64]int8{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1}

// x₀
xGen.SetString("9586122913090633729", 10)
Expand Down
5 changes: 5 additions & 0 deletions ecc/bls12-377/g1.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ecc/bls12-377/g2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions ecc/bls12-377/internal/fptower/e12_pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,31 @@ func (z *E12) MulBy034(c0, c3, c4 *E2) *E12 {
b.Set(&z.C1)
b.MulBy01(c3, c4)

c0.Add(c0, c3)
var d0 E2
d0.Add(c0, c3)
d.Add(&z.C0, &z.C1)
d.MulBy01(c0, c4)
d.MulBy01(&d0, c4)

z.C1.Add(&a, &b).Neg(&z.C1).Add(&z.C1, &d)
z.C0.MulByNonResidue(&b).Add(&z.C0, &a)

return z
}

// MulBy34 multiplication by sparse element (1,0,0,c3,c4,0)
func (z *E12) MulBy34(c3, c4 *E2) *E12 {
yelhousni marked this conversation as resolved.
Show resolved Hide resolved

var a, b, d E6

a.Set(&z.C0)

b.Set(&z.C1)
b.MulBy01(c3, c4)

var d0 E2
d0.SetOne().Add(&d0, c3)
d.Add(&z.C0, &z.C1)
d.MulBy01(&d0, c4)

z.C1.Add(&a, &b).Neg(&z.C1).Add(&z.C1, &d)
z.C0.MulByNonResidue(&b).Add(&z.C0, &a)
Expand Down Expand Up @@ -90,6 +112,26 @@ func Mul034By034(d0, d3, d4, c0, c3, c4 *E2) [5]E2 {
return [5]E2{z00, x3, x34, x03, x04}
}

// Mul34By34 multiplication of sparse element (1,0,0,c3,c4,0) by sparse element (1,0,0,d3,d4,0)
func Mul34By34(d3, d4, c3, c4 *E2) [5]E2 {
yelhousni marked this conversation as resolved.
Show resolved Hide resolved
var z00, tmp, x0, x3, x4, x04, x03, x34 E2
x3.Mul(c3, d3)
x4.Mul(c4, d4)
x04.Add(c4, d4)
x03.Add(c3, d3)
tmp.Add(c3, c4)
x34.Add(d3, d4).
Mul(&x34, &tmp).
Sub(&x34, &x3).
Sub(&x34, &x4)

x0.SetOne()
z00.MulByNonResidue(&x4).
Add(&z00, &x0)

return [5]E2{z00, x3, x34, x03, x04}
}

// MulBy01234 multiplies z by an E12 sparse element of the form (x0, x1, x2, x3, x4, 0)
func (z *E12) MulBy01234(x *[5]E2) *E12 {
var c1, a, b, c, z0, z1 E6
Expand Down
29 changes: 15 additions & 14 deletions ecc/bls12-377/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ecc/bls12-377/kzg/kzg_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading