mirror of
https://github.com/arnaucube/go-snark-study.git
synced 2026-02-02 17:26:41 +01:00
snark trusted setup + generate proof + verify proof working. Added test to bn128 pairing
This commit is contained in:
21
fields/fq.go
21
fields/fq.go
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user