Skip to content

Commit f1b7d52

Browse files
committed
lnwire: add fuzz target for Schnorr sig conversion
Analogous to FuzzConvertFixedSignature but for Schnorr signatures.
1 parent b82ae51 commit f1b7d52

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lnwire/fuzz_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,37 @@ func FuzzConvertFixedSignature(f *testing.F) {
797797
})
798798
}
799799

800+
// FuzzConvertFixedSchnorrSignature tests that conversion of fixed 64-byte
801+
// Schnorr signatures to and from the btcec format does not panic or mutate the
802+
// signatures.
803+
func FuzzConvertFixedSchnorrSignature(f *testing.F) {
804+
f.Fuzz(func(t *testing.T, data []byte) {
805+
var sig Sig
806+
if len(data) > len(sig.bytes[:]) {
807+
return
808+
}
809+
copy(sig.bytes[:], data)
810+
sig.ForceSchnorr()
811+
812+
btcecSig, err := sig.ToSignature()
813+
if err != nil {
814+
return
815+
}
816+
817+
sig2, err := NewSigFromSignature(btcecSig)
818+
require.NoError(t, err, "failed to parse signature")
819+
820+
btcecSig2, err := sig2.ToSignature()
821+
require.NoError(
822+
t, err, "failed to reconvert signature to btcec format",
823+
)
824+
825+
btcecBytes := btcecSig.Serialize()
826+
btcecBytes2 := btcecSig2.Serialize()
827+
require.Equal(t, btcecBytes, btcecBytes2, "signature mismatch")
828+
})
829+
}
830+
800831
// prefixWithFailCode adds a failure code prefix to data.
801832
func prefixWithFailCode(data []byte, code FailCode) []byte {
802833
var codeBytes [2]byte

0 commit comments

Comments
 (0)