From da0317fd013308db6ce847bc9c3d506a2a3ae0ff Mon Sep 17 00:00:00 2001 From: Gautam Botrel Date: Thu, 5 Oct 2023 12:45:59 -0500 Subject: [PATCH] clean: remove useless snippet in mulWindowed (#453) * clean: remove useless snippet in mulWindowed * clean: more deadcode --- ecc/bls12-377/g1.go | 11 ----------- ecc/bls12-377/g2.go | 4 ---- ecc/bls12-378/g1.go | 11 ----------- ecc/bls12-378/g2.go | 4 ---- ecc/bls12-381/g1.go | 11 ----------- ecc/bls12-381/g2.go | 4 ---- ecc/bls24-315/g1.go | 11 ----------- ecc/bls24-315/g2.go | 4 ---- ecc/bls24-317/g1.go | 11 ----------- ecc/bls24-317/g2.go | 4 ---- ecc/bn254/g1.go | 11 ----------- ecc/bn254/g2.go | 4 ---- ecc/bw6-633/g1.go | 11 ----------- ecc/bw6-633/g2.go | 4 ---- ecc/bw6-756/g1.go | 11 ----------- ecc/bw6-756/g2.go | 4 ---- ecc/bw6-761/g1.go | 11 ----------- ecc/bw6-761/g2.go | 4 ---- ecc/secp256k1/g1.go | 11 ----------- internal/generator/ecc/template/point.go.tmpl | 14 -------------- 20 files changed, 160 deletions(-) diff --git a/ecc/bls12-377/g1.go b/ecc/bls12-377/g1.go index fe15a31d9b..e1bc1809f4 100644 --- a/ecc/bls12-377/g1.go +++ b/ecc/bls12-377/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -442,11 +435,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bls12-377/g2.go b/ecc/bls12-377/g2.go index a7594cfc6d..c256d8210e 100644 --- a/ecc/bls12-377/g2.go +++ b/ecc/bls12-377/g2.go @@ -417,11 +417,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bls12-378/g1.go b/ecc/bls12-378/g1.go index ba42cd1584..eb59168b86 100644 --- a/ecc/bls12-378/g1.go +++ b/ecc/bls12-378/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -442,11 +435,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bls12-378/g2.go b/ecc/bls12-378/g2.go index 960c787300..7da45cbc86 100644 --- a/ecc/bls12-378/g2.go +++ b/ecc/bls12-378/g2.go @@ -417,11 +417,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bls12-381/g1.go b/ecc/bls12-381/g1.go index c5be10ed8a..c24a82cda6 100644 --- a/ecc/bls12-381/g1.go +++ b/ecc/bls12-381/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -442,11 +435,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bls12-381/g2.go b/ecc/bls12-381/g2.go index c6d0fafa89..cd32bfb46b 100644 --- a/ecc/bls12-381/g2.go +++ b/ecc/bls12-381/g2.go @@ -418,11 +418,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bls24-315/g1.go b/ecc/bls24-315/g1.go index 5da6c2e134..8b91064502 100644 --- a/ecc/bls24-315/g1.go +++ b/ecc/bls24-315/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -444,11 +437,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bls24-315/g2.go b/ecc/bls24-315/g2.go index 5ad43d49eb..7c9510046b 100644 --- a/ecc/bls24-315/g2.go +++ b/ecc/bls24-315/g2.go @@ -419,11 +419,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bls24-317/g1.go b/ecc/bls24-317/g1.go index 689f962005..f5a4d287d4 100644 --- a/ecc/bls24-317/g1.go +++ b/ecc/bls24-317/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -444,11 +437,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bls24-317/g2.go b/ecc/bls24-317/g2.go index 29bad5b099..0d59a79a75 100644 --- a/ecc/bls24-317/g2.go +++ b/ecc/bls24-317/g2.go @@ -419,11 +419,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bn254/g1.go b/ecc/bn254/g1.go index 4c0a294980..e64b53ffa7 100644 --- a/ecc/bn254/g1.go +++ b/ecc/bn254/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -432,11 +425,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bn254/g2.go b/ecc/bn254/g2.go index d0da8e60ea..b4f279fc37 100644 --- a/ecc/bn254/g2.go +++ b/ecc/bn254/g2.go @@ -424,11 +424,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bw6-633/g1.go b/ecc/bw6-633/g1.go index 05a610276c..282352cc91 100644 --- a/ecc/bw6-633/g1.go +++ b/ecc/bw6-633/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -447,11 +440,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bw6-633/g2.go b/ecc/bw6-633/g2.go index ed44d59d4f..17af770dbe 100644 --- a/ecc/bw6-633/g2.go +++ b/ecc/bw6-633/g2.go @@ -419,11 +419,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bw6-756/g1.go b/ecc/bw6-756/g1.go index 045b384c65..49437c7d8f 100644 --- a/ecc/bw6-756/g1.go +++ b/ecc/bw6-756/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -451,11 +444,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bw6-756/g2.go b/ecc/bw6-756/g2.go index fdeb5e14c4..012542286c 100644 --- a/ecc/bw6-756/g2.go +++ b/ecc/bw6-756/g2.go @@ -423,11 +423,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/bw6-761/g1.go b/ecc/bw6-761/g1.go index 04d23cc9d4..70a51e6989 100644 --- a/ecc/bw6-761/g1.go +++ b/ecc/bw6-761/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -451,11 +444,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/ecc/bw6-761/g2.go b/ecc/bw6-761/g2.go index 5aa68749ae..590621d9f8 100644 --- a/ecc/bw6-761/g2.go +++ b/ecc/bw6-761/g2.go @@ -423,11 +423,7 @@ func (p *G2Jac) mulWindowed(a *G2Jac, s *big.Int) *G2Jac { var ops [3]G2Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g2Infinity) diff --git a/ecc/secp256k1/g1.go b/ecc/secp256k1/g1.go index 8631a67672..ed3291938f 100644 --- a/ecc/secp256k1/g1.go +++ b/ecc/secp256k1/g1.go @@ -23,15 +23,8 @@ import ( "github.com/consensys/gnark-crypto/internal/parallel" "math/big" "runtime" - "sync" ) -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} - // G1Affine point in affine coordinates type G1Affine struct { X, Y fp.Element @@ -432,11 +425,7 @@ func (p *G1Jac) mulWindowed(a *G1Jac, s *big.Int) *G1Jac { var ops [3]G1Jac ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&g1Infinity) diff --git a/internal/generator/ecc/template/point.go.tmpl b/internal/generator/ecc/template/point.go.tmpl index 8736632ec6..dfabf475fd 100644 --- a/internal/generator/ecc/template/point.go.tmpl +++ b/internal/generator/ecc/template/point.go.tmpl @@ -8,9 +8,6 @@ import ( "math/big" "runtime" - {{- if eq .PointName "g1"}} - "sync" - {{- end }} {{- if .GLV}} "github.com/consensys/gnark-crypto/ecc" @@ -24,13 +21,6 @@ import ( {{- end}} ) -{{- if eq .PointName "g1"}} -var bigIntPool = sync.Pool{ - New: func() interface{} { - return new(big.Int) - }, -} -{{- end}} // {{ $TAffine }} point in affine coordinates type {{ $TAffine }} struct { @@ -651,11 +641,7 @@ func (p *{{ $TJacobian }}) mulWindowed(a *{{ $TJacobian }}, s *big.Int) *{{ $TJa var ops [3]{{ $TJacobian }} ops[0].Set(a) - e := s if s.Sign() == -1 { - e = bigIntPool.Get().(*big.Int) - defer bigIntPool.Put(e) - e.Neg(s) ops[0].Neg(&ops[0]) } res.Set(&{{ toLower .PointName}}Infinity)