Skip to content

Commit b50f59d

Browse files
authored
Merge pull request #1666 from TheBlueMatt/2022-08-fix-script-check
Correct the on-chain script checked in gossip verification
2 parents 12687d7 + 6265da0 commit b50f59d

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

lightning/src/routing/gossip.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ use bitcoin::secp256k1;
1616

1717
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
1818
use bitcoin::hashes::Hash;
19-
use bitcoin::blockdata::script::Builder;
2019
use bitcoin::blockdata::transaction::TxOut;
21-
use bitcoin::blockdata::opcodes;
2220
use bitcoin::hash_types::BlockHash;
2321

2422
use chain;
2523
use chain::Access;
24+
use ln::chan_utils::make_funding_redeemscript;
2625
use ln::features::{ChannelFeatures, NodeFeatures};
2726
use ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
2827
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
@@ -1442,11 +1441,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
14421441
&Some(ref chain_access) => {
14431442
match chain_access.get_utxo(&msg.chain_hash, msg.short_channel_id) {
14441443
Ok(TxOut { value, script_pubkey }) => {
1445-
let expected_script = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2)
1446-
.push_slice(&msg.bitcoin_key_1.serialize())
1447-
.push_slice(&msg.bitcoin_key_2.serialize())
1448-
.push_opcode(opcodes::all::OP_PUSHNUM_2)
1449-
.push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script().to_v0_p2wsh();
1444+
let expected_script =
1445+
make_funding_redeemscript(&msg.bitcoin_key_1, &msg.bitcoin_key_2).to_v0_p2wsh();
14501446
if script_pubkey != expected_script {
14511447
return Err(LightningError{err: format!("Channel announcement key ({}) didn't match on-chain script ({})", script_pubkey.to_hex(), expected_script.to_hex()), action: ErrorAction::IgnoreError});
14521448
}
@@ -1823,6 +1819,7 @@ impl ReadOnlyNetworkGraph<'_> {
18231819
#[cfg(test)]
18241820
mod tests {
18251821
use chain;
1822+
use ln::chan_utils::make_funding_redeemscript;
18261823
use ln::PaymentHash;
18271824
use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
18281825
use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate, NodeAlias, MAX_EXCESS_BYTES_FOR_RELAY, NodeId, RoutingFees, ChannelUpdateInfo, ChannelInfo, NodeAnnouncementInfo, NodeInfo};
@@ -1840,9 +1837,8 @@ mod tests {
18401837
use bitcoin::hashes::Hash;
18411838
use bitcoin::network::constants::Network;
18421839
use bitcoin::blockdata::constants::genesis_block;
1843-
use bitcoin::blockdata::script::{Builder, Script};
1840+
use bitcoin::blockdata::script::Script;
18441841
use bitcoin::blockdata::transaction::TxOut;
1845-
use bitcoin::blockdata::opcodes;
18461842

18471843
use hex;
18481844

@@ -1932,14 +1928,10 @@ mod tests {
19321928
}
19331929

19341930
fn get_channel_script(secp_ctx: &Secp256k1<secp256k1::All>) -> Script {
1935-
let node_1_btckey = &SecretKey::from_slice(&[40; 32]).unwrap();
1936-
let node_2_btckey = &SecretKey::from_slice(&[39; 32]).unwrap();
1937-
Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2)
1938-
.push_slice(&PublicKey::from_secret_key(&secp_ctx, node_1_btckey).serialize())
1939-
.push_slice(&PublicKey::from_secret_key(&secp_ctx, node_2_btckey).serialize())
1940-
.push_opcode(opcodes::all::OP_PUSHNUM_2)
1941-
.push_opcode(opcodes::all::OP_CHECKMULTISIG).into_script()
1942-
.to_v0_p2wsh()
1931+
let node_1_btckey = SecretKey::from_slice(&[40; 32]).unwrap();
1932+
let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap();
1933+
make_funding_redeemscript(&PublicKey::from_secret_key(secp_ctx, &node_1_btckey),
1934+
&PublicKey::from_secret_key(secp_ctx, &node_2_btckey)).to_v0_p2wsh()
19431935
}
19441936

19451937
fn get_signed_channel_update<F: Fn(&mut UnsignedChannelUpdate)>(f: F, node_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> ChannelUpdate {

0 commit comments

Comments
 (0)