Skip to content

Commit ffaa96f

Browse files
feat(test): Add a new test to ensure proper signature checking
Fixes a bug in lnprototest by removing the problematic code outlined in patch [1]. During our investigation of the cln code, we discovered that the message verification was not performed correctly as the BOL 7 suggest. This commit includes a patch [2] that fixes the issue and introduces an integration test to validate that core lightning adheres to the signature verification guidelines outlined in BOLT7. [1] #91 [2] ElementsProject/lightning#6384 Reported-by: lnprototest (#91) Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 5607d31 commit ffaa96f

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

tests/test_bolt2-01-open_channel.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
FundChannel,
66
ExpectMsg,
77
ExpectTx,
8+
ExpectError,
9+
MustNotMsg,
810
Msg,
911
RawMsg,
1012
AcceptFunding,
@@ -45,7 +47,10 @@
4547
pubkey_of,
4648
gen_random_keyset,
4749
)
48-
from lnprototest.utils.ln_spec_utils import connect_to_node_helper
50+
from lnprototest.utils.ln_spec_utils import (
51+
connect_to_node_helper,
52+
open_and_announce_channel_helper,
53+
)
4954

5055

5156
def test_open_channel_announce_features(runner: Runner) -> None:
@@ -278,3 +283,55 @@ def test_open_channel_opener_side(runner: Runner) -> None:
278283
TryAll([], RawMsg(bytes.fromhex("270F"))),
279284
]
280285
run_runner(runner, merge_events_sequences(connections_events, test_events))
286+
287+
288+
def test_open_channel_opener_side_wrong_announcement_signatures(runner: Runner) -> None:
289+
"""Testing the case where the channel is announces in the correct way but one node
290+
send the wrong signature inside the `announcement_signatures` message."""
291+
connections_events = connect_to_node_helper(
292+
runner=runner,
293+
tx_spendable=tx_spendable,
294+
conn_privkey="02",
295+
)
296+
opts = {}
297+
open_channel_events = open_and_announce_channel_helper(runner, "02", opts=opts)
298+
pre_events = merge_events_sequences(connections_events, open_channel_events)
299+
300+
dummy_sign = "138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053"
301+
short_channel_id = opts["short_channel_id"]
302+
test_events = [
303+
ExpectMsg(
304+
"announcement_signatures",
305+
channel_id=channel_id(),
306+
short_channel_id=short_channel_id,
307+
node_signature=stash_field_from_event(
308+
"announcement_signatures", dummy_val=dummy_sign
309+
),
310+
bitcoin_signature=stash_field_from_event(
311+
"announcement_signatures", dummy_val=dummy_sign
312+
),
313+
),
314+
# BOLT 7:
315+
# - if the node_signature OR the bitcoin_signature is NOT correct:
316+
# - MAY send a warning and close the connection, or send an error and fail the channel.
317+
#
318+
# In our case, we send an error and stop the open channel procedure. This approach is
319+
# considered overly strict since the peer can recover from it. However, this step is
320+
# optional. If the peer sends it, we assume that the signature must be correct.
321+
Msg(
322+
"announcement_signatures",
323+
channel_id=channel_id(),
324+
short_channel_id=short_channel_id,
325+
node_signature=stash_field_from_event(
326+
"announcement_signatures", dummy_val=dummy_sign
327+
),
328+
bitcoin_signature=stash_field_from_event(
329+
"announcement_signatures", dummy_val=dummy_sign
330+
),
331+
),
332+
ExpectError(),
333+
# BOLT 2: The channel is not practically usable until at least one side has
334+
# announced its fee levels and expiry, using channel_update.
335+
MustNotMsg("channel_update"),
336+
]
337+
run_runner(runner, merge_events_sequences(pre_events, test_events))

0 commit comments

Comments
 (0)