mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-06 19:06:43 +01:00
Proof generation works, add h pol calculation
This commit is contained in:
30
prover.go
30
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
|
||||
}
|
||||
|
||||
35
prover_test.go
Normal file
35
prover_test.go
Normal file
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user