@@ 1,6 1,9 @@
package math
import (
+ "crypto/rand"
+ "encoding/base64"
+ "io"
"testing"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
@@ 42,20 45,37 @@ func TestRandomPoly(t *testing.T) {
ballot[1] = make([]byte, 2)
ballot[0][1] = 1
- // pinput doesn't matter
-genpinput:
- pinput, err := new(fr.Element).SetRandom()
- if err != nil {
- panic(err)
- }
- if pinput.IsZero() {
- goto genpinput
- }
zero := new(fr.Element).SetZero()
// vary the number of points
for n := 2; n <= 20; n++ {
- poly := NewRandomPoly(ballot, n, pinput)
+ // inputs don't matter
+ inputs := make([]*fr.Element, n)
+ for i := range inputs {
+ input, err := new(fr.Element).SetRandom()
+ if err != nil {
+ panic(err)
+ }
+ for input.IsZero() {
+ input, err = input.SetRandom()
+ if err != nil {
+ panic(err)
+ }
+ }
+ inputs[i] = input
+ }
+
+ // hash seeds don't matter
+ hashSeeds := make([]string, n)
+ for i := range hashSeeds {
+ var hashSeed [32]byte
+ if _, err := io.ReadFull(rand.Reader, hashSeed[:]); err != nil {
+ t.Fatal(err)
+ }
+ hashSeeds[i] = base64.RawStdEncoding.EncodeToString(hashSeed[:])
+ }
+
+ poly := NewRandomPoly(ballot, hashSeeds, inputs)
points := make([]Point, n)
for i := 0; i < n; i++ {
genx: