From 57935b20d6a81a0335261d0ded350aef41a0f2d3 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Sat, 29 May 2021 14:25:13 +0530 Subject: [PATCH] lightningd: check closing tx signature Changelog-None --- lightningd/closing_control.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index 2df07d6f5..a4769cdf8 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -97,15 +97,27 @@ static void peer_received_closing_signature(struct channel *channel, struct bitcoin_tx *tx; struct bitcoin_txid tx_id; struct lightningd *ld = channel->peer->ld; + u8 *funding_wscript; if (!fromwire_closingd_received_signature(msg, msg, &sig, &tx)) { - channel_internal_error(channel, "Bad closing_received_signature %s", + channel_internal_error(channel, + "Bad closing_received_signature %s", tal_hex(msg, msg)); return; } tx->chainparams = chainparams; - /* FIXME: Make sure signature is correct! */ + funding_wscript = bitcoin_redeem_2of2(tmpctx, + &channel->local_funding_pubkey, + &channel->channel_info.remote_fundingkey); + if (!check_tx_sig(tx, 0, NULL, funding_wscript, + &channel->channel_info.remote_fundingkey, &sig)) { + channel_internal_error(channel, + "Bad closing_received_signature %s", + tal_hex(msg, msg)); + return; + } + if (closing_fee_is_acceptable(ld, channel, tx)) { channel_set_last_tx(channel, tx, &sig, TX_CHANNEL_CLOSE); wallet_channel_save(ld->wallet, channel);