Browse Source

Update proof sync.WaitGroup scooped variables & Add time prints in cli proof generation

ed255-patch-1
arnaucube 4 years ago
parent
commit
5b77df54b7
2 changed files with 27 additions and 20 deletions
  1. +7
    -0
      cli/cli.go
  2. +20
    -20
      prover/prover.go

+ 7
- 0
cli/cli.go

@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"time"
"github.com/iden3/go-circom-prover-verifier/parsers"
"github.com/iden3/go-circom-prover-verifier/prover"
@ -46,6 +47,8 @@ func main() {
func cmdProve(provingKeyPath, witnessPath, proofPath, publicPath string) error {
fmt.Println("zkSNARK Groth16 prover")
fmt.Println("Reading proving key file:", provingKeyPath)
provingKeyJson, err := ioutil.ReadFile(provingKeyPath)
if err != nil {
return err
@ -55,6 +58,7 @@ func cmdProve(provingKeyPath, witnessPath, proofPath, publicPath string) error {
return err
}
fmt.Println("Reading witness file:", witnessPath)
witnessJson, err := ioutil.ReadFile(witnessPath)
if err != nil {
return err
@ -64,10 +68,13 @@ func cmdProve(provingKeyPath, witnessPath, proofPath, publicPath string) error {
return err
}
fmt.Println("Generating the proof")
beforeT := time.Now()
proof, pubSignals, err := prover.GenerateProof(pk, w)
if err != nil {
return err
}
fmt.Println("proof generation time elapsed:", time.Since(beforeT))
proofStr, err := parsers.ProofToJson(proof)
if err != nil {

+ 20
- 20
prover/prover.go

@ -73,39 +73,39 @@ func GenerateProof(pk *types.Pk, w types.Witness) (*types.Proof, []*big.Int, err
proof.C = new(bn256.G1).ScalarBaseMult(big.NewInt(0))
proofBG1 := new(bn256.G1).ScalarBaseMult(big.NewInt(0))
var waitGroup sync.WaitGroup
waitGroup.Add(4)
go func(wg *sync.WaitGroup) {
var wg sync.WaitGroup
wg.Add(4)
go func() {
for i := 0; i < pk.NVars; i++ {
proof.A = new(bn256.G1).Add(proof.A, new(bn256.G1).ScalarMult(pk.A[i], w[i]))
}
wg.Done()
}(&waitGroup)
go func(wg *sync.WaitGroup) {
}()
go func() {
for i := 0; i < pk.NVars; i++ {
proof.B = new(bn256.G2).Add(proof.B, new(bn256.G2).ScalarMult(pk.B2[i], w[i]))
}
wg.Done()
}(&waitGroup)
go func(wg *sync.WaitGroup) {
}()
go func() {
for i := 0; i < pk.NVars; i++ {
proofBG1 = new(bn256.G1).Add(proofBG1, new(bn256.G1).ScalarMult(pk.B1[i], w[i]))
}
wg.Done()
}(&waitGroup)
go func(wg *sync.WaitGroup) {
}()
go func() {
for i := pk.NPublic + 1; i < pk.NVars; i++ {
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(pk.C[i], w[i]))
}
wg.Done()
}(&waitGroup)
waitGroup.Wait()
}()
wg.Wait()
h := calculateH(pk, w)
var waitGroup2 sync.WaitGroup
waitGroup2.Add(2)
go func(wg *sync.WaitGroup) {
var wg2 sync.WaitGroup
wg2.Add(2)
go func() {
proof.A = new(bn256.G1).Add(proof.A, pk.VkAlpha1)
proof.A = new(bn256.G1).Add(proof.A, new(bn256.G1).ScalarMult(pk.VkDelta1, r))
@ -114,15 +114,15 @@ func GenerateProof(pk *types.Pk, w types.Witness) (*types.Proof, []*big.Int, err
proofBG1 = new(bn256.G1).Add(proofBG1, pk.VkBeta1)
proofBG1 = new(bn256.G1).Add(proofBG1, new(bn256.G1).ScalarMult(pk.VkDelta1, s))
wg.Done()
}(&waitGroup2)
go func(wg *sync.WaitGroup) {
wg2.Done()
}()
go func() {
for i := 0; i < len(h); i++ {
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(pk.HExps[i], h[i]))
}
wg.Done()
}(&waitGroup2)
waitGroup2.Wait()
wg2.Done()
}()
wg2.Wait()
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(proof.A, s))
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(proofBG1, r))

Loading…
Cancel
Save