Skip to content

Commit

Permalink
Added fuzzer for tbls routine
Browse files Browse the repository at this point in the history
  • Loading branch information
matteosz committed Mar 4, 2024
1 parent 5fad44c commit 06e5dc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ coverage: tidy
# target to run all the possible checks; it's a good habit to run it before
# pushing code
check: lint vet test
echo "check done"
echo "check done"
29 changes: 23 additions & 6 deletions sign/tbls/tbls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,39 @@ import (
)

func TestTBLS(test *testing.T) {
var err error
msg := []byte("Hello threshold Boneh-Lynn-Shacham")
BLSRoutine(test, []byte("Hello threshold Boneh-Lynn-Shacham"), 10)
}

func FuzzBLS(f *testing.F) {
f.Fuzz(func(t *testing.T, msg []byte, n int) {
if (n < 1) || (n > 100) {
t.Skip("n must be between 1 and 100")
}
if (len(msg) < 1) || (len(msg) > 1000) {
t.Skip("msg must have byte length between 1 and 1000")
}
BLSRoutine(t, msg, n)
})
}

func BLSRoutine(test *testing.T, msg []byte, n int) {
suite := bn256.NewSuite()
n := 10
t := n/2 + 1
th := n/2 + 1

secret := suite.G1().Scalar().Pick(suite.RandomStream())
priPoly := share.NewPriPoly(suite.G2(), t, secret, suite.RandomStream())
priPoly := share.NewPriPoly(suite.G2(), th, secret, suite.RandomStream())
pubPoly := priPoly.Commit(suite.G2().Point().Base())
sigShares := make([][]byte, 0)

for _, x := range priPoly.Shares(n) {
sig, err := Sign(suite, x, msg)
require.Nil(test, err)
sigShares = append(sigShares, sig)
}
sig, err := Recover(suite, pubPoly, msg, sigShares, t, n)

sig, err := Recover(suite, pubPoly, msg, sigShares, th, n)
require.Nil(test, err)

err = bls.Verify(suite, pubPoly.Commit(), msg, sig)
require.Nil(test, err)
}

0 comments on commit 06e5dc1

Please sign in to comment.