4 Commits

Author SHA1 Message Date
Eduard S
6d4b1abc10 Test all fields of parsed binary pk 2020-05-22 12:37:08 +02:00
Eduard S
e652f34753 Merge pull request #19 from iden3/fix/pk-parse-benchmarks
Fix pk parser benchmarks
2020-05-21 16:19:07 +02:00
arnaucube
42961f6b94 Fix pk parser benchmarks
Parsers were working correctly, but the benchmarks had errors.

The benchmarks in the commit d1b3979eb6
are incorrect, correct ones are:

```
BenchmarkParsePk/ParsePkJson_circuit1k-4         	       2	 529437960 ns/op
BenchmarkParsePk/ParsePkBin_circuit1k-4          	       2	 607792597 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit1k-4        	       2	 540594611 ns/op
BenchmarkParsePk/ParsePkJson_circuit5k-4         	       1	2769819086 ns/op
BenchmarkParsePk/ParsePkBin_circuit5k-4          	       1	3094913319 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit5k-4        	       1	2404651389 ns/op
BenchmarkParsePk/ParsePkJson_circuit10k-4        	       1	5374917709 ns/op
BenchmarkParsePk/ParsePkBin_circuit10k-4         	       1	5756633515 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit10k-4       	       1	4782081310 ns/op
BenchmarkParsePk/ParsePkJson_circuit20k-4        	       1	10374987398 ns/op
BenchmarkParsePk/ParsePkBin_circuit20k-4         	       1	11528361584 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit20k-4       	       1	9541829245 ns/op
BenchmarkParsePk/ParsePkJson_circuit50k-4         	       1	25979727146 ns/op
BenchmarkParsePk/ParsePkBin_circuit50k-4          	       1	28434810627 ns/op
BenchmarkParsePk/ParsePkGoBin_circuit50k-4        	       1	23860248412 ns/op
```

The size of ProvingKey file for a circuit of 20k and 50k constraints:
```
circuit 20k constraints:
10097876 bytes of proving_key.go.bin
10097876 bytes of proving_key.bin
29760049 bytes of proving_key.json

circuit 50k constraints:
24195028 bytes of proving_key.go.bin
24194964 bytes of proving_key.bin
71484081 bytes of proving_key.json
```
2020-05-21 13:19:45 +02:00
Eduard S
386758370e Merge pull request #18 from iden3/feature/pk-own-format
Add own go-circom ProvingKey Bin format
2020-05-21 11:25:53 +02:00
2 changed files with 25 additions and 3 deletions

1
cli/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
cli

View File

@@ -238,6 +238,11 @@ func testCircuitParsePkBin(t *testing.T, circuit string) {
assert.Equal(t, pkJ.B2, pk.B2) assert.Equal(t, pkJ.B2, pk.B2)
assert.Equal(t, pkJ.C, pk.C) assert.Equal(t, pkJ.C, pk.C)
assert.Equal(t, pkJ.HExps[:pkJ.DomainSize], pk.HExps[:pk.DomainSize]) // circom behaviour assert.Equal(t, pkJ.HExps[:pkJ.DomainSize], pk.HExps[:pk.DomainSize]) // circom behaviour
assert.Equal(t, pkJ.NVars, pk.NVars)
assert.Equal(t, pkJ.NPublic, pk.NPublic)
assert.Equal(t, pkJ.DomainSize, pk.DomainSize)
assert.Equal(t, pkJ.PolsC, pk.PolsC)
} }
func TestParsePkBin(t *testing.T) { func TestParsePkBin(t *testing.T) {
@@ -274,6 +279,17 @@ func testGoCircomPkFormat(t *testing.T, circuit string) {
assert.Equal(t, pk.HExps, pkG.HExps) assert.Equal(t, pk.HExps, pkG.HExps)
assert.Equal(t, pk.PolsA, pkG.PolsA) assert.Equal(t, pk.PolsA, pkG.PolsA)
assert.Equal(t, pk.PolsB, pkG.PolsB) assert.Equal(t, pk.PolsB, pkG.PolsB)
assert.Equal(t, pk.NVars, pkG.NVars)
assert.Equal(t, pk.NPublic, pkG.NPublic)
assert.Equal(t, pk.DomainSize, pkG.DomainSize)
assert.Equal(t, pk.PolsC, pkG.PolsC)
// pkPrettyJSON, err := json.MarshalIndent(pk, "", " ")
// require.Nil(t, err)
// pkGoPrettyJSON, err := json.MarshalIndent(pkG, "", " ")
// require.Nil(t, err)
// assert.Equal(t, pkPrettyJSON, pkGoPrettyJSON)
} }
func TestGoCircomPkFormat(t *testing.T) { func TestGoCircomPkFormat(t *testing.T) {
@@ -297,17 +313,22 @@ func benchmarkParsePk(b *testing.B, circuit string) {
b.Run("ParsePkJson "+circuit, func(b *testing.B) { b.Run("ParsePkJson "+circuit, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
ParsePkBin(pkBinFile) _, err = ParsePk(pkJson)
require.Nil(b, err)
} }
}) })
b.Run("ParsePkBin "+circuit, func(b *testing.B) { b.Run("ParsePkBin "+circuit, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
ParsePk(pkJson) pkBinFile.Seek(0, 0)
_, err = ParsePkBin(pkBinFile)
require.Nil(b, err)
} }
}) })
b.Run("ParsePkGoBin "+circuit, func(b *testing.B) { b.Run("ParsePkGoBin "+circuit, func(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
ParsePkGoBin(pkBinFile) pkGoBinFile.Seek(0, 0)
_, err = ParsePkGoBin(pkGoBinFile)
require.Nil(b, err)
} }
}) })
} }