From f230a0d939664a8f4369cabc54e714db8eb4c312 Mon Sep 17 00:00:00 2001 From: Youssef El Housni Date: Mon, 24 Jun 2024 19:36:17 +0100 Subject: [PATCH] refactor: remove E3 Conjugate from BW6 --- ecc/bw6-633/internal/fptower/e3.go | 8 ------ ecc/bw6-633/internal/fptower/e3_test.go | 33 ------------------------- ecc/bw6-756/internal/fptower/e3.go | 7 ------ ecc/bw6-756/internal/fptower/e3_test.go | 33 ------------------------- ecc/bw6-761/internal/fptower/e3.go | 7 ------ ecc/bw6-761/internal/fptower/e3_test.go | 33 ------------------------- 6 files changed, 121 deletions(-) diff --git a/ecc/bw6-633/internal/fptower/e3.go b/ecc/bw6-633/internal/fptower/e3.go index 03f65c004..bb7421c77 100644 --- a/ecc/bw6-633/internal/fptower/e3.go +++ b/ecc/bw6-633/internal/fptower/e3.go @@ -128,14 +128,6 @@ func (z *E3) String() string { return (z.A0.String() + "+(" + z.A1.String() + ")*u+(" + z.A2.String() + ")*u**2") } -// Conjugate conjugates an element in E3 -func (z *E3) Conjugate(x *E3) *E3 { - z.A0.Set(&x.A0) - z.A1.Neg(&x.A1) - z.A2.Set(&x.A2) - return z -} - // MulByElement multiplies an element in E3 by an element in fp func (z *E3) MulByElement(x *E3, y *fp.Element) *E3 { var yCopy fp.Element diff --git a/ecc/bw6-633/internal/fptower/e3_test.go b/ecc/bw6-633/internal/fptower/e3_test.go index 0526292de..9db8a0251 100644 --- a/ecc/bw6-633/internal/fptower/e3_test.go +++ b/ecc/bw6-633/internal/fptower/e3_test.go @@ -111,16 +111,6 @@ func TestE3ReceiverIsOperand(t *testing.T) { genA, )) - properties.Property("[BW6-633] Having the receiver as operand (Conjugate) should output the same result", prop.ForAll( - func(a *E3) bool { - var b E3 - b.Conjugate(a) - a.Conjugate(a) - return a.Equal(&b) - }, - genA, - )) - properties.Property("[BW6-633] Having the receiver as operand (mul by element) should output the same result", prop.ForAll( func(a *E3, b fp.Element) bool { var c E3 @@ -246,20 +236,6 @@ func TestE3Ops(t *testing.T) { genA, )) - properties.Property("[BW6-633] a + pi(a), a-pi(a) should be real", prop.ForAll( - func(a *E3) bool { - var b, c, d E3 - var e, f fp.Element - b.Conjugate(a) - c.Add(a, &b) - d.Sub(a, &b) - e.Double(&a.A0) - f.Double(&a.A1) - return c.A1.IsZero() && d.A0.IsZero() && e.Equal(&c.A0) && f.Equal(&d.A1) - }, - genA, - )) - properties.TestingRun(t, gopter.ConsoleReporter(false)) } @@ -333,12 +309,3 @@ func BenchmarkE3MulNonRes(b *testing.B) { a.MulByNonResidue(&a) } } - -func BenchmarkE3Conjugate(b *testing.B) { - var a E3 - _, _ = a.SetRandom() - b.ResetTimer() - for i := 0; i < b.N; i++ { - a.Conjugate(&a) - } -} diff --git a/ecc/bw6-756/internal/fptower/e3.go b/ecc/bw6-756/internal/fptower/e3.go index 15fc2d4bb..bc645379e 100644 --- a/ecc/bw6-756/internal/fptower/e3.go +++ b/ecc/bw6-756/internal/fptower/e3.go @@ -124,13 +124,6 @@ func (z *E3) String() string { return (z.A0.String() + "+(" + z.A1.String() + ")*u+(" + z.A2.String() + ")*u**2") } -// Conjugate conjugates an element in E3 -func (z *E3) Conjugate(x *E3) *E3 { - *z = *x - z.A1.Neg(&z.A1) - return z -} - // MulByElement multiplies an element in E3 by an element in fp func (z *E3) MulByElement(x *E3, y *fp.Element) *E3 { _y := *y diff --git a/ecc/bw6-756/internal/fptower/e3_test.go b/ecc/bw6-756/internal/fptower/e3_test.go index 2e2eac7fa..09cc04640 100644 --- a/ecc/bw6-756/internal/fptower/e3_test.go +++ b/ecc/bw6-756/internal/fptower/e3_test.go @@ -112,16 +112,6 @@ func TestE3ReceiverIsOperand(t *testing.T) { genA, )) - properties.Property("[BW756] Having the receiver as operand (Conjugate) should output the same result", prop.ForAll( - func(a *E3) bool { - var b E3 - b.Conjugate(a) - a.Conjugate(a) - return a.Equal(&b) - }, - genA, - )) - properties.Property("[BW756] Having the receiver as operand (mul by element) should output the same result", prop.ForAll( func(a *E3, b fp.Element) bool { var c E3 @@ -248,20 +238,6 @@ func TestE3Ops(t *testing.T) { genA, )) - properties.Property("[BW756] a + pi(a), a-pi(a) should be real", prop.ForAll( - func(a *E3) bool { - var b, c, d E3 - var e, f fp.Element - b.Conjugate(a) - c.Add(a, &b) - d.Sub(a, &b) - e.Double(&a.A0) - f.Double(&a.A1) - return c.A1.IsZero() && d.A0.IsZero() && e.Equal(&c.A0) && f.Equal(&d.A1) - }, - genA, - )) - properties.TestingRun(t, gopter.ConsoleReporter(false)) } @@ -335,12 +311,3 @@ func BenchmarkE3MulNonRes(b *testing.B) { a.MulByNonResidue(&a) } } - -func BenchmarkE3Conjugate(b *testing.B) { - var a E3 - _, _ = a.SetRandom() - b.ResetTimer() - for i := 0; i < b.N; i++ { - a.Conjugate(&a) - } -} diff --git a/ecc/bw6-761/internal/fptower/e3.go b/ecc/bw6-761/internal/fptower/e3.go index 29e7fd7ff..b16151212 100644 --- a/ecc/bw6-761/internal/fptower/e3.go +++ b/ecc/bw6-761/internal/fptower/e3.go @@ -124,13 +124,6 @@ func (z *E3) String() string { return (z.A0.String() + "+(" + z.A1.String() + ")*u+(" + z.A2.String() + ")*u**2") } -// Conjugate conjugates an element in E3 -func (z *E3) Conjugate(x *E3) *E3 { - *z = *x - z.A1.Neg(&z.A1) - return z -} - // MulByElement multiplies an element in E3 by an element in fp func (z *E3) MulByElement(x *E3, y *fp.Element) *E3 { _y := *y diff --git a/ecc/bw6-761/internal/fptower/e3_test.go b/ecc/bw6-761/internal/fptower/e3_test.go index 1fd50d2f5..99de77cf1 100644 --- a/ecc/bw6-761/internal/fptower/e3_test.go +++ b/ecc/bw6-761/internal/fptower/e3_test.go @@ -111,16 +111,6 @@ func TestE3ReceiverIsOperand(t *testing.T) { genA, )) - properties.Property("[BW761] Having the receiver as operand (Conjugate) should output the same result", prop.ForAll( - func(a *E3) bool { - var b E3 - b.Conjugate(a) - a.Conjugate(a) - return a.Equal(&b) - }, - genA, - )) - properties.Property("[BW761] Having the receiver as operand (mul by element) should output the same result", prop.ForAll( func(a *E3, b fp.Element) bool { var c E3 @@ -246,20 +236,6 @@ func TestE3Ops(t *testing.T) { genA, )) - properties.Property("[BW761] a + pi(a), a-pi(a) should be real", prop.ForAll( - func(a *E3) bool { - var b, c, d E3 - var e, f fp.Element - b.Conjugate(a) - c.Add(a, &b) - d.Sub(a, &b) - e.Double(&a.A0) - f.Double(&a.A1) - return c.A1.IsZero() && d.A0.IsZero() && e.Equal(&c.A0) && f.Equal(&d.A1) - }, - genA, - )) - properties.TestingRun(t, gopter.ConsoleReporter(false)) } @@ -333,12 +309,3 @@ func BenchmarkE3MulNonRes(b *testing.B) { a.MulByNonResidue(&a) } } - -func BenchmarkE3Conjugate(b *testing.B) { - var a E3 - _, _ = a.SetRandom() - b.ResetTimer() - for i := 0; i < b.N; i++ { - a.Conjugate(&a) - } -}