arnaucube
arnaucube/go-circom-prover-verifierPublic Self-hosted repository
Add Proof to string in circom/snarkjs format
arnaucube root@arnaucube.com
Mon, 06 Apr 2020 11:54:21 +0200
commit

c03cb1af003e96e6d0587ec3b3347419d9ca53c9

parent

198eeee493ff8dfca64984a1453fa3dd70480493

2 files changed, 35 insertions(+), 4 deletions(-)

jump to
M ifft.go → ifft.go

@@ -1,7 +1,6 @@

package gocircomprover import ( - "fmt" "math" "math/big" )

@@ -65,7 +64,7 @@

// var out []*big.Int out := make([]*big.Int, n) for i := 0; i < ndiv2; i++ { - fmt.Println(i, len(roots.roots)) + // fmt.Println(i, len(roots.roots)) out[i] = fAdd(p1[i], fMul(roots.roots[bits][i], p2[i])) out[i+ndiv2] = fSub(p1[i], fMul(roots.roots[bits][i], p2[i])) }
M parsers.go → parsers.go

@@ -35,6 +35,14 @@

// WitnessString contains the Witness in string representation type WitnessString []string +// ProofString is the equivalent to the Proof struct in string representation +type ProofString struct { + A [3]string `json:"pi_a"` + B [3][2]string `json:"pi_b"` + C [3]string `json:"pi_c"` + Protocol string `json:"protocol"` +} + // ParseWitness parses the json []byte data into the Witness struct func ParseWitness(wJson []byte) (Witness, error) { var ws WitnessString

@@ -149,10 +157,8 @@ }

// oi = append(oi, si) jInt, err := strconv.Atoi(j) if err != nil { - fmt.Println(j) return o, err } - fmt.Println(jInt, si) oi[jInt] = si } o = append(o, oi)

@@ -343,3 +349,29 @@ p := new(bn256.G2)

_, err = p.Unmarshal(b) return p, err } + +func proofToString(p *Proof) ([]byte, error) { + var ps ProofString + + a := p.A.Marshal() + ps.A[0] = new(big.Int).SetBytes(a[:32]).String() + ps.A[1] = new(big.Int).SetBytes(a[32:64]).String() + ps.A[2] = "1" + + b := p.B.Marshal() + ps.B[0][1] = new(big.Int).SetBytes(b[:32]).String() + ps.B[0][0] = new(big.Int).SetBytes(b[32:64]).String() + ps.B[1][1] = new(big.Int).SetBytes(b[64:96]).String() + ps.B[1][0] = new(big.Int).SetBytes(b[96:128]).String() + ps.B[2][0] = "1" + ps.B[2][1] = "0" + + c := p.C.Marshal() + ps.C[0] = new(big.Int).SetBytes(c[:32]).String() + ps.C[1] = new(big.Int).SetBytes(c[32:64]).String() + ps.C[2] = "1" + + ps.Protocol = "groth" + + return json.Marshal(ps) +}