Skip to content

Commit

Permalink
Throw an error when inverse by 0 in BatchCompressTorus() (#222)
Browse files Browse the repository at this point in the history
* fix: throw an error when inverse by 0 in BatchCompressTorus

* fix(bls24-317): throw an error when inverse by 0 in BatchCompressTorus

* docs: prettify doc

Co-authored-by: Gautam Botrel <gautam.botrel@gmail.com>
  • Loading branch information
yelhousni and gbotrel authored Jul 27, 2022
1 parent c94b731 commit 910b0ec
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 15 deletions.
11 changes: 8 additions & 3 deletions ecc/bls12-377/internal/fptower/e12.go

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

11 changes: 8 additions & 3 deletions ecc/bls12-378/internal/fptower/e12.go

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

11 changes: 8 additions & 3 deletions ecc/bls12-381/internal/fptower/e12.go

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

4 changes: 4 additions & 0 deletions ecc/bls24-315/internal/fptower/e24.go

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

4 changes: 4 additions & 0 deletions ecc/bls24-317/internal/fptower/e24.go

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

11 changes: 8 additions & 3 deletions ecc/bn254/internal/fptower/e12.go

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

4 changes: 4 additions & 0 deletions ecc/bw6-633/internal/fptower/e6.go

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

4 changes: 4 additions & 0 deletions ecc/bw6-756/internal/fptower/e6.go

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

4 changes: 4 additions & 0 deletions ecc/bw6-761/internal/fptower/e6.go

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

11 changes: 8 additions & 3 deletions internal/generator/tower/template/fq12over6over2/fq12.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,14 @@ func (z *E12) CompressTorus() (E6, error) {
return res, nil
}

// BatchCompressTorus GT/E12 elements to half their size
// using a batch inversion
// BatchCompressTorus GT/E12 elements to half their size using a batch inversion.
//
// if len(x) == 0 or if any of the x[i].C1 coordinate is 0, this function returns an error.
func BatchCompressTorus(x []E12) ([]E6, error) {

n := len(x)
if n == 0 {
return []E6{}, errors.New("invalid input size")
return nil, errors.New("invalid input size")
}

var one E6
Expand All @@ -808,6 +809,10 @@ func BatchCompressTorus(x []E12) ([]E6, error) {

for i := 0; i < n; i++ {
res[i].Set(&x[i].C1)
// throw an error if any of the x[i].C1 is 0
if res[i].IsZero() {
return nil, errors.New("invalid input; C1 is 0")
}
}

t := BatchInvertE6(res) // costs 1 inverse
Expand Down

0 comments on commit 910b0ec

Please sign in to comment.