From 2845b9bc73893b62b0a5f0b289c3bef29d272100 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 00:16:09 +0530 Subject: [PATCH 01/15] faster Mul01By01 --- std/algebra/emulated/fields_bn254/e6.go | 11 ++--------- std/algebra/emulated/fields_bw6761/e3.go | 11 ++--------- std/algebra/native/fields_bls12377/e6.go | 13 +++---------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/std/algebra/emulated/fields_bn254/e6.go b/std/algebra/emulated/fields_bn254/e6.go index 4330fa49f..1a29a6640 100644 --- a/std/algebra/emulated/fields_bn254/e6.go +++ b/std/algebra/emulated/fields_bn254/e6.go @@ -230,22 +230,15 @@ func (e Ext6) MulBy01(z *E6, c0, c1 *E2) *E6 { func (e Ext6) Mul01By01(c0, c1, d0, d1 *E2) *E6 { a := e.Ext2.Mul(d0, c0) b := e.Ext2.Mul(d1, c1) - t0 := e.Ext2.Mul(c1, d1) - t0 = e.Ext2.Sub(t0, b) - t0 = e.Ext2.MulByNonResidue(t0) - t0 = e.Ext2.Add(t0, a) - t2 := e.Ext2.Mul(c0, d0) - t2 = e.Ext2.Sub(t2, a) - t2 = e.Ext2.Add(t2, b) t1 := e.Ext2.Add(c0, c1) tmp := e.Ext2.Add(d0, d1) t1 = e.Ext2.Mul(t1, tmp) t1 = e.Ext2.Sub(t1, a) t1 = e.Ext2.Sub(t1, b) return &E6{ - B0: *t0, + B0: *a, B1: *t1, - B2: *t2, + B2: *b, } } diff --git a/std/algebra/emulated/fields_bw6761/e3.go b/std/algebra/emulated/fields_bw6761/e3.go index 63fc125a9..9de2dce3c 100644 --- a/std/algebra/emulated/fields_bw6761/e3.go +++ b/std/algebra/emulated/fields_bw6761/e3.go @@ -235,22 +235,15 @@ func (e Ext3) MulBy12(x *E3, b1, b2 *baseEl) *E3 { func (e Ext3) Mul01By01(c0, c1, d0, d1 *baseEl) *E3 { a := e.fp.Mul(d0, c0) b := e.fp.Mul(d1, c1) - t0 := e.fp.Mul(c1, d1) - t0 = e.fp.Sub(b, t0) - t0 = e.fp.MulConst(t0, big.NewInt(4)) - t0 = e.fp.Add(t0, a) - t2 := e.fp.Mul(c0, d0) - t2 = e.fp.Sub(t2, a) - t2 = e.fp.Add(t2, b) t1 := e.fp.Add(c0, c1) tmp := e.fp.Add(d0, d1) t1 = e.fp.Mul(t1, tmp) t1 = e.fp.Sub(t1, a) t1 = e.fp.Sub(t1, b) return &E3{ - A0: *t0, + A0: *a, A1: *t1, - A2: *t2, + A2: *b, } } diff --git a/std/algebra/native/fields_bls12377/e6.go b/std/algebra/native/fields_bls12377/e6.go index 5fba0cae6..7ea287f68 100644 --- a/std/algebra/native/fields_bls12377/e6.go +++ b/std/algebra/native/fields_bls12377/e6.go @@ -280,17 +280,10 @@ func (e *E6) MulBy01(api frontend.API, c0, c1 E2) *E6 { } func Mul01By01(api frontend.API, c0, c1, d0, d1 E2) *E6 { - var a, b, t0, t1, t2, tmp E2 + var a, b, t1, tmp E2 a.Mul(api, d0, c0) b.Mul(api, d1, c1) - t0.Mul(api, c1, d1) - t0.Sub(api, t0, b) - t0.MulByNonResidue(api, t0) - t0.Add(api, t0, a) - t2.Mul(api, c0, d0) - t2.Sub(api, t2, a) - t2.Add(api, t2, b) t1.Add(api, c0, c1) tmp.Add(api, d0, d1) t1.Mul(api, t1, tmp) @@ -298,9 +291,9 @@ func Mul01By01(api frontend.API, c0, c1, d0, d1 E2) *E6 { t1.Sub(api, t1, b) return &E6{ - B0: t0, + B0: a, B1: t1, - B2: t2, + B2: b, } } From 718671d7eaff8dd9d48542b76b3cb7cfafd291f3 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 01:04:49 +0530 Subject: [PATCH 02/15] bn254: test mul 01 by 01 --- std/algebra/emulated/fields_bn254/e6_test.go | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/std/algebra/emulated/fields_bn254/e6_test.go b/std/algebra/emulated/fields_bn254/e6_test.go index 6c46bb7d4..baba1b67e 100644 --- a/std/algebra/emulated/fields_bn254/e6_test.go +++ b/std/algebra/emulated/fields_bn254/e6_test.go @@ -266,6 +266,49 @@ func TestMulFp6By01(t *testing.T) { } +type e6Mul01By01 struct { + A0, A1 E2 + B0, B1 E2 + C E6 `gnark:",public"` +} + +func (circuit *e6Mul01By01) Define(api frontend.API) error { + e := NewExt6(api) + expected := e.Mul01By01(&circuit.A0, &circuit.A1, &circuit.B0, &circuit.B1) + e.AssertIsEqual(expected, &circuit.C) + + return nil +} + +func TestMul01By01(t *testing.T) { + + assert := test.NewAssert(t) + // witness values + var a, c bn254.E6 + var A0, A1, B0, B1 bn254.E2 + _, _ = A0.SetRandom() + _, _ = A1.SetRandom() + _, _ = B0.SetRandom() + _, _ = B1.SetRandom() + a.B0 = A0 + a.B1 = A1 + a.B2.SetZero() + c.Set(&a) + c.MulBy01(&B0, &B1) + + witness := e6Mul01By01{ + A0: FromE2(&A0), + A1: FromE2(&A1), + B0: FromE2(&B0), + B1: FromE2(&B1), + C: FromE6(&c), + } + + err := test.IsSolved(&e6Mul01By01{}, &witness, ecc.BN254.ScalarField()) + assert.NoError(err) + +} + type e6MulBy0 struct { A E6 C0 E2 From 10215c62091b2bd2e67730e59f2c4aef547dadf8 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 01:22:59 +0530 Subject: [PATCH 03/15] bls12377: test mul 01 by 01 --- std/algebra/native/fields_bls12377/e6_test.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/std/algebra/native/fields_bls12377/e6_test.go b/std/algebra/native/fields_bls12377/e6_test.go index 1165fab11..c092de80d 100644 --- a/std/algebra/native/fields_bls12377/e6_test.go +++ b/std/algebra/native/fields_bls12377/e6_test.go @@ -122,6 +122,48 @@ func TestMulFp6(t *testing.T) { assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_761)) } +type e6Mul01By01 struct { + A0, A1 E2 + B0, B1 E2 + C E6 `gnark:",public"` +} + +func (circuit *e6Mul01By01) Define(api frontend.API) error { + expected := E6{} + + expected = *Mul01By01(api, circuit.A0, circuit.A1, circuit.B0, circuit.B1) + expected.AssertIsEqual(api, circuit.C) + + return nil +} + +func TestMul01By01(t *testing.T) { + + var circuit, witness e6Mul01By01 + // witness values + var a, c bls12377.E6 + var A0, A1, B0, B1 bls12377.E2 + _, _ = A0.SetRandom() + _, _ = A1.SetRandom() + _, _ = B0.SetRandom() + _, _ = B1.SetRandom() + a.B0 = A0 + a.B1 = A1 + a.B2.SetZero() + c.Set(&a) + c.MulBy01(&B0, &B1) + + witness.A0.Assign(&A0) + witness.A1.Assign(&A1) + witness.B0.Assign(&B0) + witness.B1.Assign(&B1) + witness.C.Assign(&c) + + assert := test.NewAssert(t) + assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_761)) + +} + type fp6MulByNonResidue struct { A E6 C E6 `gnark:",public"` From 426e330b4999f86e9e932ee7fcd5d31aade19212 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 01:49:52 +0530 Subject: [PATCH 04/15] bw6761: test mul 01 by 01 --- std/algebra/emulated/fields_bw6761/e3_test.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/std/algebra/emulated/fields_bw6761/e3_test.go b/std/algebra/emulated/fields_bw6761/e3_test.go index 707be87b6..af3903961 100644 --- a/std/algebra/emulated/fields_bw6761/e3_test.go +++ b/std/algebra/emulated/fields_bw6761/e3_test.go @@ -152,6 +152,49 @@ func TestMulFp3(t *testing.T) { assert.NoError(err) } +type e3Mul01By01 struct { + A0, A1 baseEl + B0, B1 baseEl + C E3 +} + +func (circuit *e3Mul01By01) Define(api frontend.API) error { + e := NewExt3(api) + expected := e.Mul01By01(&circuit.A0, &circuit.A1, &circuit.B0, &circuit.B1) + e.AssertIsEqual(expected, &circuit.C) + + return nil +} + +func TestMul01By01(t *testing.T) { + + assert := test.NewAssert(t) + // witness values + var a, c bw6761.E3 + var A0, A1, B0, B1 fp.Element + A0.SetRandom() + A1.SetRandom() + B0.SetRandom() + B1.SetRandom() + a.A0 = A0 + a.A1 = A1 + a.A2.SetZero() + c.Set(&a) + c.MulBy01(&B0, &B1) + + witness := e3Mul01By01{ + A0: emulated.ValueOf[emulated.BW6761Fp](A0), + A1: emulated.ValueOf[emulated.BW6761Fp](A1), + B0: emulated.ValueOf[emulated.BW6761Fp](B0), + B1: emulated.ValueOf[emulated.BW6761Fp](B1), + C: FromE3(&c), + } + + err := test.IsSolved(&e3Mul01By01{}, &witness, ecc.BN254.ScalarField()) + assert.NoError(err) + +} + type e3MulByNonResidue struct { A, B E3 } From c7f1e51390c95c920d2b8217c5208a437104c965 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 02:10:17 +0530 Subject: [PATCH 05/15] comments for mul 01 by 01 tests --- std/algebra/emulated/fields_bn254/e6_test.go | 5 +++++ std/algebra/emulated/fields_bw6761/e3_test.go | 4 ++++ std/algebra/native/fields_bls12377/e6_test.go | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/std/algebra/emulated/fields_bn254/e6_test.go b/std/algebra/emulated/fields_bn254/e6_test.go index baba1b67e..9b8dfdac7 100644 --- a/std/algebra/emulated/fields_bn254/e6_test.go +++ b/std/algebra/emulated/fields_bn254/e6_test.go @@ -282,6 +282,7 @@ func (circuit *e6Mul01By01) Define(api frontend.API) error { func TestMul01By01(t *testing.T) { + // we test our new E3.Mul01By01 against E3.MulBy01 assert := test.NewAssert(t) // witness values var a, c bn254.E6 @@ -290,6 +291,10 @@ func TestMul01By01(t *testing.T) { _, _ = A1.SetRandom() _, _ = B0.SetRandom() _, _ = B1.SetRandom() + + // build a 01 sparse E3 with, + // first two elements as A1 and A2, + // and the third as 0 a.B0 = A0 a.B1 = A1 a.B2.SetZero() diff --git a/std/algebra/emulated/fields_bw6761/e3_test.go b/std/algebra/emulated/fields_bw6761/e3_test.go index af3903961..189325843 100644 --- a/std/algebra/emulated/fields_bw6761/e3_test.go +++ b/std/algebra/emulated/fields_bw6761/e3_test.go @@ -168,6 +168,7 @@ func (circuit *e3Mul01By01) Define(api frontend.API) error { func TestMul01By01(t *testing.T) { + // we test our new E3.Mul01By01 against E3.MulBy01 assert := test.NewAssert(t) // witness values var a, c bw6761.E3 @@ -176,6 +177,9 @@ func TestMul01By01(t *testing.T) { A1.SetRandom() B0.SetRandom() B1.SetRandom() + // build a 01 sparse E3 with, + // first two elements as A1 and A2, + // and the third as 0 a.A0 = A0 a.A1 = A1 a.A2.SetZero() diff --git a/std/algebra/native/fields_bls12377/e6_test.go b/std/algebra/native/fields_bls12377/e6_test.go index c092de80d..111b94f75 100644 --- a/std/algebra/native/fields_bls12377/e6_test.go +++ b/std/algebra/native/fields_bls12377/e6_test.go @@ -139,6 +139,7 @@ func (circuit *e6Mul01By01) Define(api frontend.API) error { func TestMul01By01(t *testing.T) { + // we test our new E3.Mul01By01 against E3.MulBy01 var circuit, witness e6Mul01By01 // witness values var a, c bls12377.E6 @@ -147,6 +148,9 @@ func TestMul01By01(t *testing.T) { _, _ = A1.SetRandom() _, _ = B0.SetRandom() _, _ = B1.SetRandom() + // build a 01 sparse E3 with, + // first two elements as A1 and A2, + // and the third as 0 a.B0 = A0 a.B1 = A1 a.B2.SetZero() From c2031a69d088a15d7dc8d743a01fed18415be47d Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 02:13:21 +0530 Subject: [PATCH 06/15] chore lint --- std/algebra/native/fields_bls12377/e6_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/std/algebra/native/fields_bls12377/e6_test.go b/std/algebra/native/fields_bls12377/e6_test.go index 111b94f75..87749fb90 100644 --- a/std/algebra/native/fields_bls12377/e6_test.go +++ b/std/algebra/native/fields_bls12377/e6_test.go @@ -129,9 +129,7 @@ type e6Mul01By01 struct { } func (circuit *e6Mul01By01) Define(api frontend.API) error { - expected := E6{} - - expected = *Mul01By01(api, circuit.A0, circuit.A1, circuit.B0, circuit.B1) + expected := *Mul01By01(api, circuit.A0, circuit.A1, circuit.B0, circuit.B1) expected.AssertIsEqual(api, circuit.C) return nil From 19c7716558e38c5df98706fc025acf848a15c159 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 10:32:22 +0530 Subject: [PATCH 07/15] chore update stats --- internal/stats/latest.stats | Bin 2246 -> 2246 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/internal/stats/latest.stats b/internal/stats/latest.stats index 83c9387fa9278436954906eaa56dfe162ce7eaa5..f048811e44e44aca67f1e83b3c97128cb8227459 100644 GIT binary patch delta 95 zcmX>mcua6Y=HzOY1(PQ+EuY-V;W#;)J$~{8wmFlfSrR6nV&6S+)tt$e%#SAPuq#VB vG5(8nVgLdT5W)DDajF@ZU|^WMlhtuzrsL#atkWh-vo4tYlyU83H^%t@iQgg7 delta 94 zcmX>mcua6Y=456z$I0w0b0({E%%5DvzIHMv Date: Sat, 9 Mar 2024 13:54:22 +0530 Subject: [PATCH 08/15] bn254: faster e6 MulBy01 --- std/algebra/emulated/fields_bn254/e6.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/std/algebra/emulated/fields_bn254/e6.go b/std/algebra/emulated/fields_bn254/e6.go index 4330fa49f..3ffb11dd0 100644 --- a/std/algebra/emulated/fields_bn254/e6.go +++ b/std/algebra/emulated/fields_bn254/e6.go @@ -196,9 +196,10 @@ func (e Ext6) MulBy01(z *E6, c0, c1 *E2) *E6 { t0 = e.Ext2.Sub(t0, b) t0 = e.Ext2.MulByNonResidue(t0) t0 = e.Ext2.Add(t0, a) - tmp = e.Ext2.Add(&z.B0, &z.B2) - t2 := e.Ext2.Mul(c0, tmp) - t2 = e.Ext2.Sub(t2, a) + // for t2, schoolbook is faster than karatsuba + // c2 = a0b2 + a1b1 + a2b0, + // c2 = a2b0 + b ∵ b2 = 0, b = a1b1 + t2 := e.Ext2.Mul(&z.B2, c0) t2 = e.Ext2.Add(t2, b) t1 := e.Ext2.Add(c0, c1) tmp = e.Ext2.Add(&z.B0, &z.B1) From 859ee922379b40a20230a16e7ce73bb2eb92b7e8 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:00:20 +0530 Subject: [PATCH 09/15] bls12381: faster e6 MulBy01 --- std/algebra/emulated/fields_bls12381/e6.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/std/algebra/emulated/fields_bls12381/e6.go b/std/algebra/emulated/fields_bls12381/e6.go index 85e522eeb..406c317c0 100644 --- a/std/algebra/emulated/fields_bls12381/e6.go +++ b/std/algebra/emulated/fields_bls12381/e6.go @@ -216,9 +216,10 @@ func (e Ext6) MulBy01(z *E6, c0, c1 *E2) *E6 { t0 = e.Ext2.Sub(t0, b) t0 = e.Ext2.MulByNonResidue(t0) t0 = e.Ext2.Add(t0, a) - tmp = e.Ext2.Add(&z.B0, &z.B2) - t2 := e.Ext2.Mul(c0, tmp) - t2 = e.Ext2.Sub(t2, a) + // for t2, schoolbook is faster than karatsuba + // c2 = a0b2 + a1b1 + a2b0, + // c2 = a2b0 + b ∵ b2 = 0, b = a1b1 + t2 := e.Ext2.Mul(&z.B2, c0) t2 = e.Ext2.Add(t2, b) t1 := e.Ext2.Add(c0, c1) tmp = e.Ext2.Add(&z.B0, &z.B1) From c2a37fdfddcbfd275e61c622f064eb01841d9bc0 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:02:57 +0530 Subject: [PATCH 10/15] bw6761: faster e3 MulBy01 --- std/algebra/emulated/fields_bw6761/e3.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/std/algebra/emulated/fields_bw6761/e3.go b/std/algebra/emulated/fields_bw6761/e3.go index 63fc125a9..df30d521d 100644 --- a/std/algebra/emulated/fields_bw6761/e3.go +++ b/std/algebra/emulated/fields_bw6761/e3.go @@ -154,9 +154,10 @@ func (e Ext3) MulBy01(z *E3, c0, c1 *baseEl) *E3 { t0 = e.fp.MulConst(t0, big.NewInt(4)) t0 = e.fp.Add(t0, a) - tmp = e.fp.Add(&z.A0, &z.A2) - t2 := e.fp.Mul(c0, tmp) - t2 = e.fp.Sub(t2, a) + // for t2, schoolbook is faster than karatsuba + // c2 = a0b2 + a1b1 + a2b0, + // c2 = a2b0 + b ∵ b2 = 0, b = a1b1 + t2 := e.fp.Mul(&z.A2, c0) t2 = e.fp.Add(t2, b) t1 := e.fp.Add(c0, c1) From 4eff191475b0ff120bbebb1bd0a8e4059f68f622 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:20:19 +0530 Subject: [PATCH 11/15] bls12377: test e6 MulBy01 --- std/algebra/native/fields_bls12377/e6_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/std/algebra/native/fields_bls12377/e6_test.go b/std/algebra/native/fields_bls12377/e6_test.go index 1165fab11..60e849605 100644 --- a/std/algebra/native/fields_bls12377/e6_test.go +++ b/std/algebra/native/fields_bls12377/e6_test.go @@ -122,6 +122,42 @@ func TestMulFp6(t *testing.T) { assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_761)) } +type fp6MulBy01 struct { + A E6 + C0, C1 E2 + C E6 `gnark:",public"` +} + +func (circuit *fp6MulBy01) Define(api frontend.API) error { + expected := circuit.A + expected.MulBy01(api, circuit.C0, circuit.C1) + expected.AssertIsEqual(api, circuit.C) + + return nil +} + +func TestMulFp6By01(t *testing.T) { + + var circuit, witness fp6MulBy01 + // witness values + var a, c bls12377.E6 + var C0, C1 bls12377.E2 + _, _ = a.SetRandom() + _, _ = C0.SetRandom() + _, _ = C1.SetRandom() + c.Set(&a) + c.MulBy01(&C0, &C1) + + witness.A.Assign(&a) + witness.C0.Assign(&C0) + witness.C1.Assign(&C1) + witness.C.Assign(&c) + + assert := test.NewAssert(t) + assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_761)) + +} + type fp6MulByNonResidue struct { A E6 C E6 `gnark:",public"` From 1818bce3b5e0ce5fdd6348695fa172f1e8bf98bb Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:21:10 +0530 Subject: [PATCH 12/15] bls12377: faster e6 MulBy01 --- std/algebra/native/fields_bls12377/e6.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/std/algebra/native/fields_bls12377/e6.go b/std/algebra/native/fields_bls12377/e6.go index 5fba0cae6..61af7dbd9 100644 --- a/std/algebra/native/fields_bls12377/e6.go +++ b/std/algebra/native/fields_bls12377/e6.go @@ -261,9 +261,10 @@ func (e *E6) MulBy01(api frontend.API, c0, c1 E2) *E6 { t0.MulByNonResidue(api, t0) t0.Add(api, t0, a) - tmp.Add(api, e.B0, e.B2) - t2.Mul(api, c0, tmp) - t2.Sub(api, t2, a) + // for t2, schoolbook is faster than karatsuba + // c2 = a0b2 + a1b1 + a2b0, + // c2 = a2b0 + b ∵ b2 = 0, b = a1b1 + t2.Mul(api, e.B2, c0) t2.Add(api, t2, b) t1.Add(api, c0, c1) From 1ba12f62d68d353ae71834beeec96b8cb2bda4a7 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:30:27 +0530 Subject: [PATCH 13/15] bls24315: test e12 MulBy01 --- .../native/fields_bls24315/e12_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/std/algebra/native/fields_bls24315/e12_test.go b/std/algebra/native/fields_bls24315/e12_test.go index 6e41b82d7..8768000ae 100644 --- a/std/algebra/native/fields_bls24315/e12_test.go +++ b/std/algebra/native/fields_bls24315/e12_test.go @@ -122,6 +122,42 @@ func TestMulFp12(t *testing.T) { assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_633)) } +type fp12MulBy01 struct { + A E12 + C0, C1 E4 + C E12 `gnark:",public"` +} + +func (circuit *fp12MulBy01) Define(api frontend.API) error { + expected := circuit.A + expected.MulBy01(api, circuit.C0, circuit.C1) + expected.AssertIsEqual(api, circuit.C) + + return nil +} + +func TestMulFp12By01(t *testing.T) { + + var circuit, witness fp12MulBy01 + // witness values + var a, c bls24315.E12 + var C0, C1 bls24315.E4 + _, _ = a.SetRandom() + _, _ = C0.SetRandom() + _, _ = C1.SetRandom() + c.Set(&a) + c.MulBy01(&C0, &C1) + + witness.A.Assign(&a) + witness.C0.Assign(&C0) + witness.C1.Assign(&C1) + witness.C.Assign(&c) + + assert := test.NewAssert(t) + assert.CheckCircuit(&circuit, test.WithValidAssignment(&witness), test.WithCurves(ecc.BW6_633)) + +} + type fp12MulByNonResidue struct { A E12 C E12 `gnark:",public"` From 39cfb2242dc8b7ff46eacc6d09aff8d3edb3b395 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 14:30:34 +0530 Subject: [PATCH 14/15] bls24315: faster e12 MulBy01 --- std/algebra/native/fields_bls24315/e12.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/std/algebra/native/fields_bls24315/e12.go b/std/algebra/native/fields_bls24315/e12.go index a65ac7611..2c9897c33 100644 --- a/std/algebra/native/fields_bls24315/e12.go +++ b/std/algebra/native/fields_bls24315/e12.go @@ -243,9 +243,10 @@ func (e *E12) MulBy01(api frontend.API, c0, c1 E4) *E12 { t0.MulByNonResidue(api, t0) t0.Add(api, t0, a) - tmp.Add(api, e.C0, e.C2) - t2.Mul(api, c0, tmp) - t2.Sub(api, t2, a) + // for t2, schoolbook is faster than karatsuba + // c2 = a0b2 + a1b1 + a2b0, + // c2 = a2b0 + b ∵ b2 = 0, b = a1b1 + t2.Mul(api, e.C2, c0) t2.Add(api, t2, b) t1.Add(api, c0, c1) From 09a3327d87e95d19e1f1c6eadf9ee4498add5a41 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Sat, 9 Mar 2024 23:41:44 +0530 Subject: [PATCH 15/15] chore update stats --- internal/stats/latest.stats | Bin 2246 -> 2246 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/internal/stats/latest.stats b/internal/stats/latest.stats index 83c9387fa9278436954906eaa56dfe162ce7eaa5..dded511de49d9d926d101e5ac1e03effbfdd87c8 100644 GIT binary patch delta 155 zcmX>mcua6Y=HzVl_{kI4=1iW%w0v?ahasPZ7ULhr_`Qo5z+mzT_PvvLv#LllF#dZ4 z65#*~GyY}qZvqoQ?!-(ZUXM+Te;04h0827VmSkNtxte9cmcua6Y=43Z!Bi`IgjDHv3>0khZ$wjR5Ca+?jKlwPz+Q})5%O?x4Et%ZGq0eiP z#`rh)V+>T)Cbp!>>MRQ;w=*x8%+9PLDa82ikq}Uh11!(@mnHZOm|&PJ#6Dx