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

Throw an error when inverse by 0 in BatchCompressTorus() #222

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -757,13 +757,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 @@ -772,6 +773,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