mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-07 03:16:46 +01:00
Compare commits
6 Commits
feature/mi
...
c1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4349ce584f | ||
|
|
9555517797 | ||
|
|
ec6920aa11 | ||
|
|
6e31deb5b8 | ||
|
|
94dc934f62 | ||
|
|
9f2587151f |
1
cli/.gitignore
vendored
Normal file
1
cli/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
cli
|
||||||
@@ -159,7 +159,9 @@ func cmdConvert(provingKeyPath, provingKeyBinPath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(provingKeyBinPath, pkGBin, 0644)
|
if err = ioutil.WriteFile(provingKeyBinPath, pkGBin, 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -4,6 +4,6 @@ go 1.14
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ethereum/go-ethereum v1.9.13
|
github.com/ethereum/go-ethereum v1.9.13
|
||||||
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4
|
github.com/iden3/go-iden3-crypto v0.0.5
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
)
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -68,6 +68,8 @@ github.com/iden3/go-iden3-crypto v0.0.4 h1:rGQEFBvX6d4fDxqkQTizVq5UefB+xdZAg8j5F
|
|||||||
github.com/iden3/go-iden3-crypto v0.0.4/go.mod h1:LLcgB7DLWAUs+8eBSKne+ZHy5z7xtAmlYlEz0M9M8gE=
|
github.com/iden3/go-iden3-crypto v0.0.4/go.mod h1:LLcgB7DLWAUs+8eBSKne+ZHy5z7xtAmlYlEz0M9M8gE=
|
||||||
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4 h1:C+WGAJM9G5MxU62cAVrcwivFLk1muyENjGD5DGADk5o=
|
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4 h1:C+WGAJM9G5MxU62cAVrcwivFLk1muyENjGD5DGADk5o=
|
||||||
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
|
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
|
||||||
|
github.com/iden3/go-iden3-crypto v0.0.5 h1:inCSm5a+ry+nbpVTL/9+m6UcIwSv6nhUm0tnIxEbcps=
|
||||||
|
github.com/iden3/go-iden3-crypto v0.0.5/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
|
||||||
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
|
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
|
||||||
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -34,7 +35,6 @@ type PkString struct {
|
|||||||
DomainSize int `json:"domainSize"`
|
DomainSize int `json:"domainSize"`
|
||||||
PolsA []map[string]string `json:"polsA"`
|
PolsA []map[string]string `json:"polsA"`
|
||||||
PolsB []map[string]string `json:"polsB"`
|
PolsB []map[string]string `json:"polsB"`
|
||||||
PolsC []map[string]string `json:"polsC"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WitnessString contains the Witness in string representation
|
// WitnessString contains the Witness in string representation
|
||||||
@@ -149,10 +149,6 @@ func pkStringToPk(ps PkString) (*types.Pk, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.PolsC, err = polsStringToBigInt(ps.PolsC)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
@@ -819,9 +815,9 @@ func ParsePkBin(f *os.File) (*types.Pk, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pk.C = append(pk.C, z) // circom behaviour (3x null==["0", "0", "0"])
|
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)
|
}
|
||||||
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
||||||
b, err = readNBytes(r, 64)
|
b, err = readNBytes(r, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -974,6 +970,15 @@ 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
|
// PkToGoBin converts the ProvingKey (*types.Pk) into binary format defined by
|
||||||
// go-circom-prover-verifier. PkGoBin is a own go-circom-prover-verifier
|
// go-circom-prover-verifier. PkGoBin is a own go-circom-prover-verifier
|
||||||
// binary format that allows to go faster when parsing.
|
// binary format that allows to go faster when parsing.
|
||||||
@@ -1022,7 +1027,8 @@ func PkToGoBin(pk *types.Pk) ([]byte, error) {
|
|||||||
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsA[i])))
|
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsA[i])))
|
||||||
r = append(r, b[:]...)
|
r = append(r, b[:]...)
|
||||||
o += 4
|
o += 4
|
||||||
for j, v := range pk.PolsA[i] {
|
for _, j := range sortedKeys(pk.PolsA[i]) {
|
||||||
|
v := pk.PolsA[i][j]
|
||||||
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
||||||
r = append(r, b[:]...)
|
r = append(r, b[:]...)
|
||||||
r = append(r, addPadding32(v.Bytes())...)
|
r = append(r, addPadding32(v.Bytes())...)
|
||||||
@@ -1035,7 +1041,8 @@ func PkToGoBin(pk *types.Pk) ([]byte, error) {
|
|||||||
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsB[i])))
|
binary.LittleEndian.PutUint32(b[:], uint32(len(pk.PolsB[i])))
|
||||||
r = append(r, b[:]...)
|
r = append(r, b[:]...)
|
||||||
o += 4
|
o += 4
|
||||||
for j, v := range pk.PolsB[i] {
|
for _, j := range sortedKeys(pk.PolsB[i]) {
|
||||||
|
v := pk.PolsB[i][j]
|
||||||
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
binary.LittleEndian.PutUint32(b[:], uint32(j))
|
||||||
r = append(r, b[:]...)
|
r = append(r, b[:]...)
|
||||||
r = append(r, addPadding32(v.Bytes())...)
|
r = append(r, addPadding32(v.Bytes())...)
|
||||||
@@ -1284,9 +1291,9 @@ func ParsePkGoBin(f *os.File) (*types.Pk, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pk.C = append(pk.C, z)
|
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)
|
}
|
||||||
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
for i := pk.NPublic + 1; i < pk.NVars; i++ {
|
||||||
b, err = readNBytes(r, 64)
|
b, err = readNBytes(r, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -238,6 +238,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParsePkBin(t *testing.T) {
|
func TestParsePkBin(t *testing.T) {
|
||||||
@@ -274,6 +278,10 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGoCircomPkFormat(t *testing.T) {
|
func TestGoCircomPkFormat(t *testing.T) {
|
||||||
|
|||||||
@@ -13,36 +13,6 @@ import (
|
|||||||
//"fmt"
|
//"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
|
// Group Size
|
||||||
const (
|
const (
|
||||||
GSIZE = 6
|
GSIZE = 6
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ type Pk struct {
|
|||||||
DomainSize int
|
DomainSize int
|
||||||
PolsA []map[int]*big.Int
|
PolsA []map[int]*big.Int
|
||||||
PolsB []map[int]*big.Int
|
PolsB []map[int]*big.Int
|
||||||
PolsC []map[int]*big.Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Witness contains the witness
|
// Witness contains the witness
|
||||||
|
|||||||
Reference in New Issue
Block a user