mirror of
https://github.com/luxfi/threshold.git
synced 2026-10-30 15:15:53 +00:00
- Fix go vet error in lss_bench_test.go: replace b.Fatal with panic in goroutine - Fix go vet error in lss_test.go: remove t.Skip call from goroutine - Apply gofmt to all files to fix formatting issues All go vet errors and formatting issues have been resolved.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package polynomial
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
mrand "math/rand"
|
|
"testing"
|
|
|
|
"github.com/cronokirby/saferith"
|
|
"github.com/luxfi/threshold/pkg/math/curve"
|
|
"github.com/luxfi/threshold/pkg/math/sample"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPolynomial_Constant(t *testing.T) {
|
|
group := curve.Secp256k1{}
|
|
|
|
deg := 10
|
|
secret := sample.Scalar(rand.Reader, group)
|
|
poly := NewPolynomial(group, deg, secret)
|
|
require.True(t, poly.Constant().Equal(secret))
|
|
}
|
|
|
|
func TestPolynomial_Evaluate(t *testing.T) {
|
|
group := curve.Secp256k1{}
|
|
|
|
polynomial := &Polynomial{group, make([]curve.Scalar, 3)}
|
|
polynomial.coefficients[0] = group.NewScalar().SetNat(new(saferith.Nat).SetUint64(1))
|
|
polynomial.coefficients[1] = group.NewScalar()
|
|
polynomial.coefficients[2] = group.NewScalar().SetNat(new(saferith.Nat).SetUint64(1))
|
|
|
|
for index := 0; index < 100; index++ {
|
|
x := big.NewInt(int64(mrand.Uint32()))
|
|
result := new(big.Int).Set(x)
|
|
result.Mul(result, result)
|
|
result.Add(result, big.NewInt(1))
|
|
xScalar := group.NewScalar().SetNat(new(saferith.Nat).SetBig(x, x.BitLen()))
|
|
computedResult := polynomial.Evaluate(xScalar)
|
|
expectedResult := group.NewScalar().SetNat(new(saferith.Nat).SetBig(result, result.BitLen()))
|
|
assert.True(t, expectedResult.Equal(computedResult))
|
|
}
|
|
}
|