mirror of
https://github.com/arnaucube/go-circom-prover-verifier.git
synced 2026-02-06 19:06:43 +01:00
Update go mod & usage
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"math/big"
|
||||
|
||||
"github.com/iden3/go-circom-prover-verifier/types"
|
||||
"github.com/iden3/go-iden3-crypto/ff"
|
||||
)
|
||||
|
||||
@@ -24,30 +25,30 @@ func arrayOfZeroesE(n int) []*ff.Element {
|
||||
|
||||
func fAdd(a, b *big.Int) *big.Int {
|
||||
ab := new(big.Int).Add(a, b)
|
||||
return new(big.Int).Mod(ab, R)
|
||||
return new(big.Int).Mod(ab, types.R)
|
||||
}
|
||||
|
||||
func fSub(a, b *big.Int) *big.Int {
|
||||
ab := new(big.Int).Sub(a, b)
|
||||
return new(big.Int).Mod(ab, R)
|
||||
return new(big.Int).Mod(ab, types.R)
|
||||
}
|
||||
|
||||
func fMul(a, b *big.Int) *big.Int {
|
||||
ab := new(big.Int).Mul(a, b)
|
||||
return new(big.Int).Mod(ab, R)
|
||||
return new(big.Int).Mod(ab, types.R)
|
||||
}
|
||||
|
||||
func fDiv(a, b *big.Int) *big.Int {
|
||||
ab := new(big.Int).Mul(a, new(big.Int).ModInverse(b, R))
|
||||
return new(big.Int).Mod(ab, R)
|
||||
ab := new(big.Int).Mul(a, new(big.Int).ModInverse(b, types.R))
|
||||
return new(big.Int).Mod(ab, types.R)
|
||||
}
|
||||
|
||||
func fNeg(a *big.Int) *big.Int {
|
||||
return new(big.Int).Mod(new(big.Int).Neg(a), R)
|
||||
return new(big.Int).Mod(new(big.Int).Neg(a), types.R)
|
||||
}
|
||||
|
||||
func fInv(a *big.Int) *big.Int {
|
||||
return new(big.Int).ModInverse(a, R)
|
||||
return new(big.Int).ModInverse(a, types.R)
|
||||
}
|
||||
|
||||
func fExp(base *big.Int, e *big.Int) *big.Int {
|
||||
@@ -146,15 +147,3 @@ func polynomialDivE(a, b []*ff.Element) ([]*ff.Element, []*ff.Element) {
|
||||
}
|
||||
return r, rem
|
||||
}
|
||||
|
||||
// once https://github.com/iden3/go-iden3-crypto/pull/22 is merged, use the fucntion from there
|
||||
func ElementArrayToBigIntArray(e []*ff.Element) []*big.Int {
|
||||
var o []*big.Int
|
||||
for i := range e {
|
||||
ei := e[i]
|
||||
bi := big.NewInt(0)
|
||||
ei.ToBigIntRegular(bi)
|
||||
o = append(o, bi)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func randBI() *big.Int {
|
||||
maxbits := 253
|
||||
maxbits := 256
|
||||
b := make([]byte, (maxbits/8)-1)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
"github.com/iden3/go-circom-prover-verifier/types"
|
||||
"github.com/iden3/go-iden3-crypto/ff"
|
||||
)
|
||||
|
||||
@@ -15,7 +16,7 @@ type rootsT struct {
|
||||
func newRootsT() rootsT {
|
||||
var roots rootsT
|
||||
|
||||
rem := new(big.Int).Sub(R, big.NewInt(1))
|
||||
rem := new(big.Int).Sub(types.R, big.NewInt(1))
|
||||
s := 0
|
||||
for rem.Bit(0) == 0 { // rem.Bit==0 when even
|
||||
s++
|
||||
|
||||
@@ -41,18 +41,15 @@ type Pk struct {
|
||||
// Witness contains the witness
|
||||
type Witness []*big.Int
|
||||
|
||||
// R is the mod of the finite field
|
||||
var R, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
|
||||
|
||||
func randBigInt() (*big.Int, error) {
|
||||
maxbits := R.BitLen()
|
||||
maxbits := types.R.BitLen()
|
||||
b := make([]byte, (maxbits/8)-1)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := new(big.Int).SetBytes(b)
|
||||
rq := new(big.Int).Mod(r, R)
|
||||
rq := new(big.Int).Mod(r, types.R)
|
||||
|
||||
return rq, nil
|
||||
}
|
||||
@@ -101,7 +98,7 @@ func GenerateProof(pk *types.Pk, w types.Witness) (*types.Proof, []*big.Int, err
|
||||
}
|
||||
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(proof.A, s))
|
||||
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(proofBG1, r))
|
||||
rsneg := new(big.Int).Mod(new(big.Int).Neg(new(big.Int).Mul(r, s)), R) // fAdd & fMul
|
||||
rsneg := new(big.Int).Mod(new(big.Int).Neg(new(big.Int).Mul(r, s)), types.R) // fAdd & fMul
|
||||
proof.C = new(bn256.G1).Add(proof.C, new(bn256.G1).ScalarMult(pk.VkDelta1, rsneg))
|
||||
|
||||
pubSignals := w[1 : pk.NPublic+1]
|
||||
@@ -148,5 +145,5 @@ func calculateH(pk *types.Pk, w types.Witness) []*big.Int {
|
||||
hSeFull := ifft(polABT)
|
||||
|
||||
hSe := hSeFull[m:]
|
||||
return ElementArrayToBigIntArray(hSe)
|
||||
return utils.ElementArrayToBigIntArray(hSe)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user