graph/db: convert TestLightningNodeSigVerification to versioned test
What changed, and why it matters
This commit only changes a test file. It renames an existing test and makes it run against two versions of the software's gossip protocol, adding Schnorr signature coverage for the newer version. There is no change to production code, so it does not introduce or fix a security vulnerability in the running software.
No security action required. This is a test-only change expanding signature-algorithm coverage. Review as normal code quality/test maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies graph/db/graph_test.go to convert TestLightningNodeSigVerification into a versioned test (testLightningNodeSigVerification) that runs against both lnwire.GossipVersion1 (ECDSA) and GossipVersion2 (Schnorr). It adds the schnorr import, registers the test in the versionedTests table, and branches signing logic based on gossip version while keeping verification shared. No production logic is altered.
Changed components
graph/db/graph_test.goInspect captured patch +36 / −14
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 8ff2f91..eada708 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -17,6 +17,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
+ "github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -218,6 +219,10 @@ var versionedTests = []versionedTest{
name: "node pruning update index deletion",
test: testNodePruningUpdateIndexDeletion,
},
+ {
+ name: "lightning node sig verification",
+ test: testLightningNodeSigVerification,
+ },
}
// TestVersionedDBs runs various tests against both v1 and v2 versioned
@@ -5541,9 +5546,11 @@ func compareEdgePolicies(t testing.TB, a, b *models.ChannelEdgePolicy) {
require.Equal(t, normalizedA, normalizedB)
}
-// TestLightningNodeSigVerification checks that we can use the Node's
-// pubkey to verify signatures.
-func TestLightningNodeSigVerification(t *testing.T) {
+// testLightningNodeSigVerification checks that we can use the Node's pubkey to
+// verify signatures. For v1 this exercises ECDSA, for v2 Schnorr.
+func testLightningNodeSigVerification(t *testing.T,
+ v lnwire.GossipVersion) {
+
t.Parallel()
// Create some dummy data to sign.
@@ -5551,23 +5558,38 @@ func TestLightningNodeSigVerification(t *testing.T) {
_, err := prand.Read(data[:])
require.NoError(t, err)
- // Create private key and sign the data with it.
+ // Create private key.
priv, err := btcec.NewPrivateKey()
- require.NoError(t, err, "unable to crete priv key")
-
- sign := ecdsa.Sign(priv, data[:])
-
- // Sanity check that the signature checks out.
- require.True(t, sign.Verify(data[:], priv.PubKey()))
+ require.NoError(t, err, "unable to create priv key")
// Create a Node from the same private key.
- node := createNode(t, lnwire.GossipVersion1, priv)
+ node := createNode(t, v, priv)
- // And finally check that we can verify the same signature from the
- // pubkey returned from the lightning node.
+ // Retrieve the public key from the node and verify a signature
+ // produced by the same private key.
nodePub, err := node.PubKey()
require.NoError(t, err, "unable to get pubkey")
- require.True(t, sign.Verify(data[:], nodePub))
+
+ // Sign the data using the appropriate scheme for the gossip version.
+ // V1 uses ECDSA, v2 uses Schnorr.
+ type verifiable interface {
+ Verify(hash []byte, pubKey *btcec.PublicKey) bool
+ }
+
+ var sig verifiable
+ switch v {
+ case lnwire.GossipVersion1:
+ sig = ecdsa.Sign(priv, data[:])
+ case lnwire.GossipVersion2:
+ schnorrSig, sErr := schnorr.Sign(priv, data[:])
+ require.NoError(t, sErr)
+ sig = schnorrSig
+ }
+
+ // Verify against the raw private key's pubkey, then against the
+ // pubkey extracted from the Node.
+ require.True(t, sig.Verify(data[:], priv.PubKey()))
+ require.True(t, sig.Verify(data[:], nodePub))
}
// TestComputeFee tests fee calculation based on the outgoing amt.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.