mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
lnwire: add fuzz target for Schnorr sig conversion
Analogous to FuzzConvertFixedSignature but for Schnorr signatures.
This commit is contained in:
parent
b82ae51a0b
commit
f1b7d52308
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user