From c03cb1af003e96e6d0587ec3b3347419d9ca53c9 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Mon, 6 Apr 2020 11:54:21 +0200 Subject: [PATCH] Add Proof to string in circom/snarkjs format --- ifft.go | 3 +-- parsers.go | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ifft.go b/ifft.go index 30458b4..ffe62ca 100644 --- a/ifft.go +++ b/ifft.go @@ -1,7 +1,6 @@ package gocircomprover import ( - "fmt" "math" "math/big" ) @@ -65,7 +64,7 @@ func fft(roots rootsT, pall []*big.Int, bits, offset, step int) []*big.Int { // 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])) } diff --git a/parsers.go b/parsers.go index a82b337..f82a4bc 100644 --- a/parsers.go +++ b/parsers.go @@ -35,6 +35,14 @@ type ProvingKeyString struct { // 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 @@ func polsStringToBigInt(s []map[string]string) ([]map[int]*big.Int, error) { // 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 @@ func stringToG2(h [][]string) (*bn256.G2, error) { _, 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) +}