mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-07 11:26:44 +01:00
Compare commits
1 Commits
feature/bu
...
feature/mi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d4b1abc10 |
@@ -159,9 +159,7 @@ func cmdConvert(provingKeyPath, provingKeyBinPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = ioutil.WriteFile(provingKeyBinPath, pkGBin, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(provingKeyBinPath, pkGBin, 0644)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"io"
|
||||
"math/big"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -35,6 +34,7 @@ type PkString struct {
|
||||
DomainSize int `json:"domainSize"`
|
||||
PolsA []map[string]string `json:"polsA"`
|
||||
PolsB []map[string]string `json:"polsB"`
|
||||
PolsC []map[string]string `json:"polsC"`
|
||||
}
|
||||
|
||||
// WitnessString contains the Witness in string representation
|
||||
@@ -149,6 +149,10 @@ func pkStringToPk(ps PkString) (*types.Pk, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.PolsC, err = polsStringToBigInt(ps.PolsC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
@@ -815,9 +819,9 @@ func ParsePkBin(f *os.File) (*types.Pk, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < pk.NPublic+1; i++ {
|
||||
pk.C = append(pk.C, z)
|
||||
}
|
||||
pk.C = append(pk.C, z) // circom behaviour (3x null==["0", "0", "0"])
|
||||
pk.C = append(pk.C, z)
|
||||
pk.C = append(pk.C, z)
|
||||
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
||||
b, err = readNBytes(r, 64)
|
||||
if err != nil {
|
||||
@@ -970,15 +974,6 @@ func coordFromMont(u, q *big.Int) *big.Int {
|
||||
)
|
||||
}
|
||||
|
||||
func sortedKeys(m map[int]*big.Int) []int {
|
||||
keys := make([]int, 0, len(m))
|
||||
for k, _ := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Ints(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
// PkToGoBin converts the ProvingKey (*types.Pk) into binary format defined by
|
||||
// go-circom-prover-verifier. PkGoBin is a own go-circom-prover-verifier
|
||||
// binary format that allows to go faster when parsing.
|
||||
@@ -1027,8 +1022,7 @@ func PkToGoBin(pk *types.Pk) ([]byte, error) {
|
||||
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsA[i])))
|
||||
r = append(r, b[:]...)
|
||||
o += 4
|
||||
for _, j := range sortedKeys(pk.PolsA[i]) {
|
||||
v := pk.PolsA[i][j]
|
||||
for j, v := range pk.PolsA[i] {
|
||||
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
||||
r = append(r, b[:]...)
|
||||
r = append(r, addPadding32(v.Bytes())...)
|
||||
@@ -1041,8 +1035,7 @@ func PkToGoBin(pk *types.Pk) ([]byte, error) {
|
||||
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsB[i])))
|
||||
r = append(r, b[:]...)
|
||||
o += 4
|
||||
for _, j := range sortedKeys(pk.PolsB[i]) {
|
||||
v := pk.PolsB[i][j]
|
||||
for j, v := range pk.PolsB[i] {
|
||||
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
||||
r = append(r, b[:]...)
|
||||
r = append(r, addPadding32(v.Bytes())...)
|
||||
@@ -1291,9 +1284,9 @@ func ParsePkGoBin(f *os.File) (*types.Pk, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < pk.NPublic+1; i++ {
|
||||
pk.C = append(pk.C, z)
|
||||
}
|
||||
pk.C = append(pk.C, z)
|
||||
pk.C = append(pk.C, z)
|
||||
pk.C = append(pk.C, z)
|
||||
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
||||
b, err = readNBytes(r, 64)
|
||||
if err != nil {
|
||||
|
||||
@@ -242,6 +242,7 @@ func testCircuitParsePkBin(t *testing.T, circuit string) {
|
||||
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) {
|
||||
@@ -282,6 +283,13 @@ func testGoCircomPkFormat(t *testing.T, circuit string) {
|
||||
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) {
|
||||
|
||||
@@ -13,6 +13,36 @@ import (
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
// Proof is the data structure of the Groth16 zkSNARK proof
|
||||
type Proof struct {
|
||||
A *bn256.G1
|
||||
B *bn256.G2
|
||||
C *bn256.G1
|
||||
}
|
||||
|
||||
// Pk holds the data structure of the ProvingKey
|
||||
type Pk struct {
|
||||
A []*bn256.G1
|
||||
B2 []*bn256.G2
|
||||
B1 []*bn256.G1
|
||||
C []*bn256.G1
|
||||
NVars int
|
||||
NPublic int
|
||||
VkAlpha1 *bn256.G1
|
||||
VkDelta1 *bn256.G1
|
||||
VkBeta1 *bn256.G1
|
||||
VkBeta2 *bn256.G2
|
||||
VkDelta2 *bn256.G2
|
||||
HExps []*bn256.G1
|
||||
DomainSize int
|
||||
PolsA []map[int]*big.Int
|
||||
PolsB []map[int]*big.Int
|
||||
PolsC []map[int]*big.Int
|
||||
}
|
||||
|
||||
// Witness contains the witness
|
||||
type Witness []*big.Int
|
||||
|
||||
// Group Size
|
||||
const (
|
||||
GSIZE = 6
|
||||
|
||||
@@ -83,6 +83,7 @@ type Pk struct {
|
||||
DomainSize int
|
||||
PolsA []map[int]*big.Int
|
||||
PolsB []map[int]*big.Int
|
||||
PolsC []map[int]*big.Int
|
||||
}
|
||||
|
||||
// Witness contains the witness
|
||||
|
||||
Reference in New Issue
Block a user