Skip to content

Commit 276c31b

Browse files
committed
Check script_pubkey against expected channel_announcement
1 parent 52aecbd commit 276c31b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ln/router.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use secp256k1::{Secp256k1,Message};
33
use secp256k1;
44

55
use bitcoin::util::hash::Sha256dHash;
6+
use bitcoin::blockdata::script::Builder;
7+
use bitcoin::blockdata::opcodes;
68

79
use chain::chaininterface::{ChainError, ChainWatchInterface};
810
use ln::channelmanager;
@@ -209,7 +211,15 @@ impl RoutingMessageHandler for Router {
209211

210212
match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
211213
Ok((script_pubkey, _value)) => {
212-
//TODO: Check if script_pubkey matches bitcoin_key_1 and bitcoin_key_2
214+
let expected_script = Builder::new().push_opcode(opcodes::All::OP_PUSHNUM_2)
215+
.push_slice(&msg.contents.bitcoin_key_1.serialize())
216+
.push_slice(&msg.contents.bitcoin_key_2.serialize())
217+
.push_opcode(opcodes::All::OP_PUSHNUM_2).push_opcode(opcodes::All::OP_CHECKMULTISIG).into_script().to_v0_p2wsh();
218+
if script_pubkey != expected_script {
219+
return Err(HandleError{err: "Channel announcement keys didn't match on-chain script", action: Some(ErrorAction::IgnoreError)});
220+
}
221+
//TODO: Check if value is worth storing, use it to inform routing, and compare it
222+
//to the new HTLC max field in channel_update
213223
},
214224
Err(ChainError::NotSupported) => {
215225
// Tenatively accept, potentially exposing us to DoS attacks

0 commit comments

Comments
 (0)