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

Perf: Parallelize subgroup checks in KZG MPC setup #615

Merged
merged 4 commits into from
Jan 23, 2025
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
26 changes: 22 additions & 4 deletions ecc/bls12-377/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bls12-381/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bls24-315/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bls24-317/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bn254/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bw6-633/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions ecc/bw6-761/kzg/mpcsetup.go

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

26 changes: 22 additions & 4 deletions internal/generator/kzg/template/mpcsetup.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import (
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
curve "github.com/consensys/gnark-crypto/ecc/{{.Name}}"
"github.com/consensys/gnark-crypto/ecc/{{.Name}}/fr"
"github.com/consensys/gnark-crypto/ecc/{{.Name}}/mpcsetup"
"github.com/consensys/gnark-crypto/utils"
"io"
"math/big"
)
Expand Down Expand Up @@ -113,11 +115,27 @@ func (s *MpcSetup) Verify(next *MpcSetup) error {
}

if !next.srs.Vk.G2[1].IsInSubGroup() {
return errors.New("𝔾₂ representation not in subgroup")
return errors.New("[x]₂ representation not in subgroup")
}
for i := 1; i < len(next.srs.Pk.G1); i++ {
if !next.srs.Pk.G1[i].IsInSubGroup() {
return errors.New("𝔾₁ representation not in subgroup")

// TODO @Tabaie replace with batch subgroup check
n := len(next.srs.Pk.G1) - 1
wp := utils.NewWorkerPool()
defer wp.Stop()
fail := make(chan error, wp.NbWorkers())

wp.Submit(n, func(start, end int) {
for i := start; i < end; i++ {
if !next.srs.Pk.G1[i+1].IsInSubGroup() {
fail <- fmt.Errorf("[x^%d]₁ representation not in subgroup", i+1)
break
}
}
}, n/wp.NbWorkers()+1).Wait()
close(fail)
for err := range fail {
if err != nil {
return err
}
}

Expand Down
4 changes: 4 additions & 0 deletions utils/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewWorkerPool() *WorkerPool {
return p
}

func (wp *WorkerPool) NbWorkers() int {
return wp.nbWorkers
}

// Stop (but does not wait) the pool. It frees the worker.
func (wp *WorkerPool) Stop() {
close(wp.chJobs)
Expand Down
Loading