mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-06 19:06:43 +01:00
Add Proof to string in circom/snarkjs format
This commit is contained in:
3
ifft.go
3
ifft.go
@@ -1,7 +1,6 @@
|
|||||||
package gocircomprover
|
package gocircomprover
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
@@ -65,7 +64,7 @@ func fft(roots rootsT, pall []*big.Int, bits, offset, step int) []*big.Int {
|
|||||||
// var out []*big.Int
|
// var out []*big.Int
|
||||||
out := make([]*big.Int, n)
|
out := make([]*big.Int, n)
|
||||||
for i := 0; i < ndiv2; i++ {
|
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] = fAdd(p1[i], fMul(roots.roots[bits][i], p2[i]))
|
||||||
out[i+ndiv2] = fSub(p1[i], fMul(roots.roots[bits][i], p2[i]))
|
out[i+ndiv2] = fSub(p1[i], fMul(roots.roots[bits][i], p2[i]))
|
||||||
}
|
}
|
||||||
|
|||||||
36
parsers.go
36
parsers.go
@@ -35,6 +35,14 @@ type ProvingKeyString struct {
|
|||||||
// WitnessString contains the Witness in string representation
|
// WitnessString contains the Witness in string representation
|
||||||
type WitnessString []string
|
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
|
// ParseWitness parses the json []byte data into the Witness struct
|
||||||
func ParseWitness(wJson []byte) (Witness, error) {
|
func ParseWitness(wJson []byte) (Witness, error) {
|
||||||
var ws WitnessString
|
var ws WitnessString
|
||||||
@@ -149,10 +157,8 @@ func polsStringToBigInt(s []map[string]string) ([]map[int]*big.Int, error) {
|
|||||||
// oi = append(oi, si)
|
// oi = append(oi, si)
|
||||||
jInt, err := strconv.Atoi(j)
|
jInt, err := strconv.Atoi(j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(j)
|
|
||||||
return o, err
|
return o, err
|
||||||
}
|
}
|
||||||
fmt.Println(jInt, si)
|
|
||||||
oi[jInt] = si
|
oi[jInt] = si
|
||||||
}
|
}
|
||||||
o = append(o, oi)
|
o = append(o, oi)
|
||||||
@@ -343,3 +349,29 @@ func stringToG2(h [][]string) (*bn256.G2, error) {
|
|||||||
_, err = p.Unmarshal(b)
|
_, err = p.Unmarshal(b)
|
||||||
return p, err
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user