Skip to content

Commit 79c0f98

Browse files
committed
Check tx output matches monitor output data (and is sufficient len)
Fixes a panic found by fuzzer in case the monitor per-commitment data is garbage. We had a similar check for revoked commitment tx but didn't copy it down to non-revoked commitment tx, so do that now.
1 parent 33553d7 commit 79c0f98

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ln/channelmonitor.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,12 @@ impl ChannelMonitor {
11571157
}
11581158

11591159
for (idx, htlc) in per_commitment_data.iter().enumerate() {
1160+
let expected_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey);
1161+
if htlc.transaction_output_index as usize >= tx.output.len() ||
1162+
tx.output[htlc.transaction_output_index as usize].value != htlc.amount_msat / 1000 ||
1163+
tx.output[htlc.transaction_output_index as usize].script_pubkey != expected_script.to_v0_p2wsh() {
1164+
return (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs); // Corrupted per_commitment_data, fuck this user
1165+
}
11601166
if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) {
11611167
let input = TxIn {
11621168
previous_output: BitcoinOutPoint {

0 commit comments

Comments
 (0)