mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-06 19:06:43 +01:00
Add cli to convert Pk to go-circom binary file
This commit is contained in:
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -23,6 +23,6 @@ jobs:
|
|||||||
- name: Compile circuits and execute Go tests
|
- name: Compile circuits and execute Go tests
|
||||||
run: |
|
run: |
|
||||||
cd testdata && sh ./compile-circuits.sh && cd ..
|
cd testdata && sh ./compile-circuits.sh && cd ..
|
||||||
go run cli/cli.go -prove -provingkey=testdata/circuit1k/proving_key.json -witness=testdata/circuit1k/witness.json -proof=testdata/circuit1k/proof.json -public=testdata/circuit1k/public.json
|
go run cli/cli.go -prove -pk=testdata/circuit1k/proving_key.json -witness=testdata/circuit1k/witness.json -proof=testdata/circuit1k/proof.json -public=testdata/circuit1k/public.json
|
||||||
go run cli/cli.go -prove -provingkey=testdata/circuit5k/proving_key.json -witness=testdata/circuit5k/witness.json -proof=testdata/circuit5k/proof.json -public=testdata/circuit5k/public.json
|
go run cli/cli.go -prove -pk=testdata/circuit5k/proving_key.json -witness=testdata/circuit5k/witness.json -proof=testdata/circuit5k/proof.json -public=testdata/circuit5k/public.json
|
||||||
go test ./...
|
go test ./...
|
||||||
|
|||||||
34
cli/cli.go
34
cli/cli.go
@@ -21,12 +21,14 @@ func main() {
|
|||||||
|
|
||||||
prove := flag.Bool("prove", false, "prover mode")
|
prove := flag.Bool("prove", false, "prover mode")
|
||||||
verify := flag.Bool("verify", false, "verifier mode")
|
verify := flag.Bool("verify", false, "verifier mode")
|
||||||
|
convert := flag.Bool("convert", false, "convert mode, to convert between proving_key.json to proving_key.go.bin")
|
||||||
|
|
||||||
provingKeyPath := flag.String("provingkey", "proving_key.json", "provingKey path")
|
provingKeyPath := flag.String("pk", "proving_key.json", "provingKey path")
|
||||||
witnessPath := flag.String("witness", "witness.json", "witness path")
|
witnessPath := flag.String("witness", "witness.json", "witness path")
|
||||||
proofPath := flag.String("proof", "proof.json", "proof path")
|
proofPath := flag.String("proof", "proof.json", "proof path")
|
||||||
verificationKeyPath := flag.String("verificationkey", "verification_key.json", "verificationKey path")
|
verificationKeyPath := flag.String("vk", "verification_key.json", "verificationKey path")
|
||||||
publicPath := flag.String("public", "public.json", "public signals path")
|
publicPath := flag.String("public", "public.json", "public signals path")
|
||||||
|
provingKeyBinPath := flag.String("pkbin", "proving_key.go.bin", "provingKey Bin path")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -42,6 +44,12 @@ func main() {
|
|||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
} else if *convert {
|
||||||
|
err := cmdConvert(*provingKeyPath, *provingKeyBinPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
@@ -133,3 +141,25 @@ func cmdVerify(proofPath, verificationKeyPath, publicPath string) error {
|
|||||||
fmt.Println("verification:", v)
|
fmt.Println("verification:", v)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdConvert(provingKeyPath, provingKeyBinPath string) error {
|
||||||
|
fmt.Println("Convertion tool")
|
||||||
|
|
||||||
|
provingKeyJson, err := ioutil.ReadFile(provingKeyPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pk, err := parsers.ParsePk(provingKeyJson)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Converting proving key json (%s)\nto go proving key binary (%s)\n", provingKeyPath, provingKeyBinPath)
|
||||||
|
pkGBin, err := parsers.PkToGoBin(pk)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(provingKeyBinPath, pkGBin, 0644)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -253,11 +253,11 @@ func testGoCircomPkFormat(t *testing.T, circuit string) {
|
|||||||
|
|
||||||
pkGBin, err := PkToGoBin(pk)
|
pkGBin, err := PkToGoBin(pk)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
err = ioutil.WriteFile("../testdata/"+circuit+"/proving_key_go.bin", pkGBin, 0644)
|
err = ioutil.WriteFile("../testdata/"+circuit+"/proving_key.go.bin", pkGBin, 0644)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// parse ProvingKeyGo
|
// parse ProvingKeyGo
|
||||||
pkGoBinFile, err := os.Open("../testdata/" + circuit + "/proving_key_go.bin")
|
pkGoBinFile, err := os.Open("../testdata/" + circuit + "/proving_key.go.bin")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer pkGoBinFile.Close()
|
defer pkGoBinFile.Close()
|
||||||
pkG, err := ParsePkGoBin(pkGoBinFile)
|
pkG, err := ParsePkGoBin(pkGoBinFile)
|
||||||
@@ -291,7 +291,7 @@ func benchmarkParsePk(b *testing.B, circuit string) {
|
|||||||
require.Nil(b, err)
|
require.Nil(b, err)
|
||||||
defer pkBinFile.Close()
|
defer pkBinFile.Close()
|
||||||
|
|
||||||
pkGoBinFile, err := os.Open("../testdata/" + circuit + "/proving_key_go.bin")
|
pkGoBinFile, err := os.Open("../testdata/" + circuit + "/proving_key.go.bin")
|
||||||
require.Nil(b, err)
|
require.Nil(b, err)
|
||||||
defer pkGoBinFile.Close()
|
defer pkGoBinFile.Close()
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestCircuitsGenerateProof(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCircuitGenerateProof(t *testing.T, circuit string) {
|
func testCircuitGenerateProof(t *testing.T, circuit string) {
|
||||||
// using json provingKey file
|
// Using json provingKey file:
|
||||||
// provingKeyJson, err := ioutil.ReadFile("../testdata/" + circuit + "/proving_key.json")
|
// provingKeyJson, err := ioutil.ReadFile("../testdata/" + circuit + "/proving_key.json")
|
||||||
// require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
// pk, err := parsers.ParsePk(provingKeyJson)
|
// pk, err := parsers.ParsePk(provingKeyJson)
|
||||||
@@ -32,11 +32,18 @@ func testCircuitGenerateProof(t *testing.T, circuit string) {
|
|||||||
// w, err := parsers.ParseWitness(witnessJson)
|
// w, err := parsers.ParseWitness(witnessJson)
|
||||||
// require.Nil(t, err)
|
// require.Nil(t, err)
|
||||||
|
|
||||||
// using bin provingKey file
|
// Using bin provingKey file:
|
||||||
pkBinFile, err := os.Open("../testdata/" + circuit + "/proving_key.bin")
|
// pkBinFile, err := os.Open("../testdata/" + circuit + "/proving_key.bin")
|
||||||
|
// require.Nil(t, err)
|
||||||
|
// defer pkBinFile.Close()
|
||||||
|
// pk, err := parsers.ParsePkBin(pkBinFile)
|
||||||
|
// require.Nil(t, err)
|
||||||
|
|
||||||
|
// Using go bin provingKey file:
|
||||||
|
pkGoBinFile, err := os.Open("../testdata/" + circuit + "/proving_key.go.bin")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer pkBinFile.Close()
|
defer pkGoBinFile.Close()
|
||||||
pk, err := parsers.ParsePkBin(pkBinFile)
|
pk, err := parsers.ParsePkGoBin(pkGoBinFile)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
witnessBinFile, err := os.Open("../testdata/" + circuit + "/witness.bin")
|
witnessBinFile, err := os.Open("../testdata/" + circuit + "/witness.bin")
|
||||||
|
|||||||
1
testdata/clean-gereated-files.sh
vendored
1
testdata/clean-gereated-files.sh
vendored
@@ -7,3 +7,4 @@ rm */*.cpp
|
|||||||
rm */*.sym
|
rm */*.sym
|
||||||
rm */*.r1cs
|
rm */*.r1cs
|
||||||
rm */*.sol
|
rm */*.sol
|
||||||
|
rm */*.bin
|
||||||
|
|||||||
12
testdata/compile-circuits.sh
vendored
12
testdata/compile-circuits.sh
vendored
@@ -45,19 +45,23 @@ compile_and_ts_and_witness
|
|||||||
|
|
||||||
cd ../
|
cd ../
|
||||||
|
|
||||||
echo "convert witness & pk of circuit1k to bin"
|
echo "convert witness & pk of circuit1k to bin & go bin"
|
||||||
node node_modules/wasmsnark/tools/buildwitness.js -i circuit1k/witness.json -o circuit1k/witness.bin
|
node node_modules/wasmsnark/tools/buildwitness.js -i circuit1k/witness.json -o circuit1k/witness.bin
|
||||||
node node_modules/wasmsnark/tools/buildpkey.js -i circuit1k/proving_key.json -o circuit1k/proving_key.bin
|
node node_modules/wasmsnark/tools/buildpkey.js -i circuit1k/proving_key.json -o circuit1k/proving_key.bin
|
||||||
|
go run ../cli/cli.go -convert -pk circuit1k/proving_key.json -pkbin circuit1k/proving_key.go.bin
|
||||||
|
|
||||||
echo "convert witness & pk of circuit5k to bin"
|
echo "convert witness & pk of circuit5k to bin & go bin"
|
||||||
node node_modules/wasmsnark/tools/buildwitness.js -i circuit5k/witness.json -o circuit5k/witness.bin
|
node node_modules/wasmsnark/tools/buildwitness.js -i circuit5k/witness.json -o circuit5k/witness.bin
|
||||||
node node_modules/wasmsnark/tools/buildpkey.js -i circuit5k/proving_key.json -o circuit5k/proving_key.bin
|
node node_modules/wasmsnark/tools/buildpkey.js -i circuit5k/proving_key.json -o circuit5k/proving_key.bin
|
||||||
|
go run ../cli/cli.go -convert -pk circuit5k/proving_key.json -pkbin circuit5k/proving_key.go.bin
|
||||||
|
|
||||||
# echo "convert witness & pk of circuit10k to bin"
|
# echo "convert witness & pk of circuit10k to bin & go bin"
|
||||||
# node node_modules/wasmsnark/tools/buildwitness.js -i circuit10k/witness.json -o circuit10k/witness.bin
|
# node node_modules/wasmsnark/tools/buildwitness.js -i circuit10k/witness.json -o circuit10k/witness.bin
|
||||||
# node node_modules/wasmsnark/tools/buildpkey.js -i circuit10k/proving_key.json -o circuit10k/proving_key.bin
|
# node node_modules/wasmsnark/tools/buildpkey.js -i circuit10k/proving_key.json -o circuit10k/proving_key.bin
|
||||||
|
# go run ../cli/cli.go -convert -pk circuit10k/proving_key.json -pkbin circuit10k/proving_key.go.bin
|
||||||
#
|
#
|
||||||
# echo "convert witness & pk of circuit20k to bin"
|
# echo "convert witness & pk of circuit20k to bin & go bin"
|
||||||
# node node_modules/wasmsnark/tools/buildwitness.js -i circuit20k/witness.json -o circuit20k/witness.bin
|
# node node_modules/wasmsnark/tools/buildwitness.js -i circuit20k/witness.json -o circuit20k/witness.bin
|
||||||
# node node_modules/wasmsnark/tools/buildpkey.js -i circuit20k/proving_key.json -o circuit20k/proving_key.bin
|
# node node_modules/wasmsnark/tools/buildpkey.js -i circuit20k/proving_key.json -o circuit20k/proving_key.bin
|
||||||
|
# go run ../cli/cli.go -convert -pk circuit20k/proving_key.json -pkbin circuit20k/proving_key.go.bin
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user