lnwire: add fuzz target for Schnorr sig conversion

Analogous to FuzzConvertFixedSignature but for Schnorr signatures.
This commit is contained in:
Matt Morehouse 2024-11-08 15:01:48 -06:00
parent b82ae51a0b
commit f1b7d52308
No known key found for this signature in database
GPG Key ID: CC8ECA224831C982

View File

@ -797,6 +797,37 @@ func FuzzConvertFixedSignature(f *testing.F) {
})
}
// FuzzConvertFixedSchnorrSignature tests that conversion of fixed 64-byte
// Schnorr signatures to and from the btcec format does not panic or mutate the
// signatures.
func FuzzConvertFixedSchnorrSignature(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
var sig Sig
if len(data) > len(sig.bytes[:]) {
return
}
copy(sig.bytes[:], data)
sig.ForceSchnorr()
btcecSig, err := sig.ToSignature()
if err != nil {
return
}
sig2, err := NewSigFromSignature(btcecSig)
require.NoError(t, err, "failed to parse signature")
btcecSig2, err := sig2.ToSignature()
require.NoError(
t, err, "failed to reconvert signature to btcec format",
)
btcecBytes := btcecSig.Serialize()
btcecBytes2 := btcecSig2.Serialize()
require.Equal(t, btcecBytes, btcecBytes2, "signature mismatch")
})
}
// prefixWithFailCode adds a failure code prefix to data.
func prefixWithFailCode(data []byte, code FailCode) []byte {
var codeBytes [2]byte