Browse Source

Proof generation works, add h pol calculation

ed255-patch-1
arnaucube 4 years ago
parent
commit
001af791cc
2 changed files with 65 additions and 0 deletions
  1. +30
    -0
      prover.go
  2. +35
    -0
      prover_test.go

+ 30
- 0
prover.go

@ -2,6 +2,7 @@ package gocircomprover
import ( import (
"crypto/rand" "crypto/rand"
"fmt"
"math/big" "math/big"
bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" 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 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
}

+ 35
- 0
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)
}

Loading…
Cancel
Save