Browse Source

Update go mod & usage

ed255-patch-1
arnaucube 4 years ago
parent
commit
6256fcc9db
8 changed files with 29 additions and 43 deletions
  1. +4
    -8
      go.mod
  2. +6
    -5
      go.sum
  3. +8
    -19
      prover/arithmetic.go
  4. +1
    -1
      prover/arithmetic_test.go
  5. +2
    -1
      prover/ifft.go
  6. +4
    -7
      prover/prover.go
  7. +3
    -0
      types/types.go
  8. +1
    -2
      verifier/verifier.go

+ 4
- 8
go.mod

@ -1,13 +1,9 @@
module go-circom-prover-verifier
module github.com/iden3/go-circom-prover-verifier
go 1.14
replace github.com/iden3/go-circom-prover-verifier => ./
require (
github.com/ethereum/go-ethereum v1.9.12
github.com/iden3/go-circom-prover-verifier v0.0.0-00010101000000-000000000000
github.com/iden3/go-iden3-crypto v0.0.4
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4
github.com/ethereum/go-ethereum v1.9.13
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4
github.com/stretchr/testify v1.4.0
)

+ 6
- 5
go.sum

@ -42,8 +42,9 @@ github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbT
github.com/edsrzf/mmap-go v0.0.0-20160512033002-935e0e8a636c/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyCIo22xvs=
github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY=
github.com/ethereum/go-ethereum v1.9.12 h1:EPtimwsp/KGDSiXcNunzsI4kefdsMHZGJntKx3fvbaI=
github.com/ethereum/go-ethereum v1.9.12/go.mod h1:PvsVkQmhZFx92Y+h2ylythYlheEDt/uBgFbl61Js/jo=
github.com/ethereum/go-ethereum v1.9.13 h1:rOPqjSngvs1VSYH2H+PMPiWt4VEulvNRbFgqiGqJM3E=
github.com/ethereum/go-ethereum v1.9.13/go.mod h1:qwN9d1GLyDh0N7Ab8bMGd0H9knaji2jOBm2RrMGjXls=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@ -63,9 +64,10 @@ github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277/go.mod h1
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v0.0.0-20161224104101-679507af18f3/go.mod h1:MZ2ZmwcBpvOoJ22IJsc7va19ZwoheaBk43rKg12SKag=
github.com/iden3/go-circom-prover-verifier v0.0.0-20200409092022-a439651fafb0 h1:iyMhjvq7JKtKT6kEKuKghXiwanoa4/u7JSCKqUBqvds=
github.com/iden3/go-iden3-crypto v0.0.4 h1:rGQEFBvX6d4fDxqkQTizVq5UefB+xdZAg8j5FQ6uv6g=
github.com/iden3/go-iden3-crypto v0.0.4/go.mod h1:LLcgB7DLWAUs+8eBSKne+ZHy5z7xtAmlYlEz0M9M8gE=
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4 h1:C+WGAJM9G5MxU62cAVrcwivFLk1muyENjGD5DGADk5o=
github.com/iden3/go-iden3-crypto v0.0.5-0.20200421133134-14c3144613d4/go.mod h1:XKw1oDwYn2CIxKOtr7m/mL5jMn4mLOxAxtZBRxQBev8=
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
@ -116,16 +118,14 @@ github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUW
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 h1:QmwruyY+bKbDDL0BaglrbZABEali68eoMFhTZpCjYVA=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@ -148,6 +148,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20190213234257-ec84240a7772/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns=
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200316214253-d7b0ff38cac9/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 8
- 19
prover/arithmetic.go

@ -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
}

+ 1
- 1
prover/arithmetic_test.go

@ -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 {

+ 2
- 1
prover/ifft.go

@ -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++

+ 4
- 7
prover/prover.go

@ -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)
}

+ 3
- 0
types/types.go

@ -6,6 +6,9 @@ import (
bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare"
)
// R is the mod of the finite field
var R, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
// Proof is the data structure of the Groth16 zkSNARK proof
type Proof struct {
A *bn256.G1

+ 1
- 2
verifier/verifier.go

@ -5,7 +5,6 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/crypto/bn256"
"github.com/iden3/go-circom-prover-verifier/prover"
"github.com/iden3/go-circom-prover-verifier/types"
)
@ -26,7 +25,7 @@ func Verify(vk *types.Vk, proof *types.Proof, inputs []*big.Int) bool {
vkX := new(bn256.G1).ScalarBaseMult(big.NewInt(0))
for i := 0; i < len(inputs); i++ {
// check input inside field
if inputs[0].Cmp(prover.R) != -1 {
if inputs[0].Cmp(types.R) != -1 {
return false
}
vkX = new(bn256.G1).Add(vkX, new(bn256.G1).ScalarMult(vk.IC[i+1], inputs[i]))

Loading…
Cancel
Save