diff --git a/prover.go b/prover.go index dee889f..21fe479 100644 --- a/prover.go +++ b/prover.go @@ -2,6 +2,7 @@ package gocircomprover import ( "crypto/rand" + "fmt" "math/big" bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" @@ -101,3 +102,32 @@ func Prove(pk *ProvingKey, w Witness) (*Proof, []*big.Int, error) { return &proof, pubSignals, nil } + +func calculateH(pk *ProvingKey, w Witness) []*big.Int { + m := pk.DomainSize + polAT := arrayOfZeroes(m) + polBT := arrayOfZeroes(m) + polCT := arrayOfZeroes(m) + + for i := 0; i < pk.NVars; i++ { + for j, _ := range pk.PolsA[i] { + polAT[j] = FAdd(polAT[j], FMul(w[i], pk.PolsA[i][j])) + fmt.Println(polAT[j]) + } + for j, _ := range pk.PolsB[i] { + polBT[j] = FAdd(polBT[j], FMul(w[i], pk.PolsB[i][j])) + } + for j, _ := range pk.PolsC[i] { + polCT[j] = FAdd(polCT[j], FMul(w[i], pk.PolsC[i][j])) + } + } + polAS := ifft(polAT) + polBS := ifft(polBT) + + polABS := PolynomialMul(polAS, polBS) + polCS := ifft(polCT) + polABCS := PolynomialSub(polABS, polCS) + + hS := polABCS[m:] + return hS +} diff --git a/prover_test.go b/prover_test.go new file mode 100644 index 0000000..dfa6416 --- /dev/null +++ b/prover_test.go @@ -0,0 +1,35 @@ +package gocircomprover + +import ( + "fmt" + "io/ioutil" + "math/big" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestProve(t *testing.T) { + provingKeyJson, err := ioutil.ReadFile("testdata/provingkey.json") + require.Nil(t, err) + pk, err := ParseProvingKey(provingKeyJson) + require.Nil(t, err) + + fmt.Println("polsA", pk.PolsA) + fmt.Println("polsB", pk.PolsB) + fmt.Println("polsC", pk.PolsC) + + witnessJson, err := ioutil.ReadFile("testdata/witness.json") + require.Nil(t, err) + w, err := ParseWitness(witnessJson) + require.Nil(t, err) + + fmt.Println("w", w) + assert.Equal(t, Witness{big.NewInt(1), big.NewInt(33), big.NewInt(3), big.NewInt(11)}, w) + + proof, pubSignals, err := Prove(pk, w) + assert.Nil(t, err) + fmt.Println("proof", proof) + fmt.Println("pubSignals", pubSignals) +}