snark trusted setup + generate proof + verify proof working. Added test to bn128 pairing

This commit is contained in:
arnaucube
2018-12-23 16:19:33 +01:00
parent 7aafcfd5f3
commit f555ae4b18
10 changed files with 187 additions and 161 deletions

View File

@@ -2,6 +2,7 @@ package fields
import (
"bytes"
"crypto/rand"
"math/big"
)
@@ -117,6 +118,26 @@ func (fq Fq) Exp(base *big.Int, e *big.Int) *big.Int {
return res
}
func (fq Fq) Rand() (*big.Int, error) {
// twoexp := new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(maxbits)), nil)
// max := new(big.Int).Sub(twoexp, big.NewInt(1))
maxbits := fq.Q.BitLen()
b := make([]byte, (maxbits/8)-1)
// b := make([]byte, 3)
// b := make([]byte, 3)
_, err := rand.Read(b)
if err != nil {
return nil, err
}
r := new(big.Int).SetBytes(b)
rq := new(big.Int).Mod(r, fq.Q)
// return r over q, nil
return rq, nil
}
func (fq Fq) IsZero(a *big.Int) bool {
return bytes.Equal(a.Bytes(), fq.Zero().Bytes())
}