Skip to content

Commit fd2db40

Browse files
committed
check the input shape in LocalCommitmentTransaction.new_missing_local_sig
1 parent f600263 commit fd2db40

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lightning/src/ln/chan_utils.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,26 @@ impl LocalCommitmentTransaction {
599599
}
600600

601601
/// Generate a new LocalCommitmentTransaction based on a raw commitment transaction,
602-
/// remote signature and both parties keys
602+
/// remote signature and both parties keys.
603+
///
604+
/// The unsigned transaction outputs must be consistent with htlc_data. This function
605+
/// only checks that the shape and amounts are consistent, but does not check the scriptPubkey.
603606
pub fn new_missing_local_sig(unsigned_tx: Transaction, their_sig: Signature, our_funding_key: &PublicKey, their_funding_key: &PublicKey, local_keys: TxCreationKeys, feerate_per_kw: u32, htlc_data: Vec<(HTLCOutputInCommitment, Option<Signature>)>) -> LocalCommitmentTransaction {
604607
if unsigned_tx.input.len() != 1 { panic!("Tried to store a commitment transaction that had input count != 1!"); }
605608
if unsigned_tx.input[0].witness.len() != 0 { panic!("Tried to store a signed commitment transaction?"); }
606609

610+
for htlc in &htlc_data {
611+
if let Some(index) = htlc.0.transaction_output_index {
612+
let out = &unsigned_tx.output[index as usize];
613+
if out.value != htlc.0.amount_msat / 1000 {
614+
panic!("HTLC at index {} has incorrect amount", index);
615+
}
616+
if !out.script_pubkey.is_v0_p2wsh() {
617+
panic!("HTLC at index {} doesn't have p2wsh scriptPubkey", index);
618+
}
619+
}
620+
}
621+
607622
Self {
608623
unsigned_tx,
609624
their_sig,

0 commit comments

Comments
 (0)