Skip to content

Commit 16df97d

Browse files
authored
Merge pull request #268 from TheBlueMatt/2015-12-fuzz-fix-output-idx
Check tx output matches monitor output data (and is sufficient len)
2 parents 33553d7 + 79c0f98 commit 16df97d

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)