Skip to content

Commit

Permalink
feat(test): Add a new test to ensure proper signature checking
Browse files Browse the repository at this point in the history
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 <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jul 14, 2023
1 parent 5607d31 commit d7b7e89
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tests/test_bolt2-01-open_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
FundChannel,
ExpectMsg,
ExpectTx,
ExpectError,
MustNotMsg,
Msg,
RawMsg,
AcceptFunding,
Expand Down Expand Up @@ -45,7 +47,10 @@
pubkey_of,
gen_random_keyset,
)
from lnprototest.utils.ln_spec_utils import connect_to_node_helper
from lnprototest.utils.ln_spec_utils import (
connect_to_node_helper,
open_and_announce_channel_helper,
)


def test_open_channel_announce_features(runner: Runner) -> None:
Expand Down Expand Up @@ -278,3 +283,54 @@ def test_open_channel_opener_side(runner: Runner) -> None:
TryAll([], RawMsg(bytes.fromhex("270F"))),
]
run_runner(runner, merge_events_sequences(connections_events, test_events))


def test_open_channel_opener_side_wrong_announcement_signatures(runner: Runner) -> None:
"""Testing the case where the channel is announces in the correct way but one node
send the wrong signature inside the `announcement_signatures` message."""
connections_events = connect_to_node_helper(
runner=runner,
tx_spendable=tx_spendable,
conn_privkey="02",
)
opts = {}
open_channel_events = open_and_announce_channel_helper(runner, "02", opts=opts)
pre_events = merge_events_sequences(connections_events, open_channel_events)

short_channel_id = opts["short_channel_id"]
test_events = [
ExpectMsg(
"announcement_signatures",
channel_id=channel_id(),
short_channel_id=short_channel_id,
node_signature=stash_field_from_event(
"announcement_signatures", dummy_val="00"
),
bitcoin_signature=stash_field_from_event(
"announcement_signatures", dummy_val="00"
),
),
# BOLT 7:
# - if the node_signature OR the bitcoin_signature is NOT correct:
# - MAY send a warning and close the connection, or send an error and fail the channel.
#
# In our case, we send an error and stop the open channel procedure. This approach is
# considered overly strict since the peer can recover from it. However, this step is
# optional. If the peer sends it, we assume that the signature must be correct.
Msg(
"announcement_signatures",
channel_id=channel_id(),
short_channel_id=short_channel_id,
node_signature=stash_field_from_event(
"announcement_signatures", dummy_val="00"
),
bitcoin_signature=stash_field_from_event(
"announcement_signatures", dummy_val="00"
),
),
ExpectError(),
# BOLT 2: The channel is not practically usable until at least one side has
# announced its fee levels and expiry, using channel_update.
MustNotMsg("channel_update"),
]
run_runner(runner, merge_events_sequences(pre_events, test_events))

0 comments on commit d7b7e89

Please sign in to comment.