Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

secp256k1 -- add fuzz tests #1809

Merged
merged 9 commits into from
Aug 15, 2023
21 changes: 21 additions & 0 deletions utils/crypto/secp256k1/secp256k1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,24 @@ func TestSigning(t *testing.T) {
})
}
}

func FuzzVerifySignature(f *testing.F) {
factory := Factory{}

f.Fuzz(func(t *testing.T, data []byte) {
require := require.New(t)

privateKey, err := factory.NewPrivateKey()
require.NoError(err)

publicKey := privateKey.PublicKey()

sig, err := privateKey.Sign(data)
require.NoError(err)

recoveredPublicKey, err := factory.RecoverPublicKey(data, sig)
require.NoError(err)

require.Equal(publicKey.Bytes(), recoveredPublicKey.Bytes())
})
}