Skip to content

Commit d5e93c6

Browse files
committed
Panic on txn with value > 21mill in ChannelMonitor::block_connected
full_stack_target found a crash where we may overflow ruring fee calculation if a transaction appears on-chain with massive value available for us to claim. Since these transactions are clearly bogus, we shouldn't allow full_stack_target to connect them, but we also improve the error generated by explicitly panicing on them.
1 parent b8dbf27 commit d5e93c6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

fuzz/src/full_stack.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
487487
} else {
488488
let txres: Result<Transaction, _> = deserialize(get_slice!(txlen));
489489
if let Ok(tx) = txres {
490+
let mut output_val = 0;
491+
for out in tx.output.iter() {
492+
if out.value > 21_000_000_0000_0000 { return; }
493+
output_val += out.value;
494+
if output_val > 21_000_000_0000_0000 { return; }
495+
}
490496
loss_detector.connect_block(&[tx]);
491497
} else {
492498
return;

lightning/src/ln/channelmonitor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,15 @@ impl ChannelMonitor {
23352335
}
23362336

23372337
fn block_connected(&mut self, txn_matched: &[&Transaction], height: u32, block_hash: &Sha256dHash, broadcaster: &BroadcasterInterface, fee_estimator: &FeeEstimator)-> (Vec<(Sha256dHash, Vec<TxOut>)>, Vec<SpendableOutputDescriptor>, Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)>) {
2338+
for tx in txn_matched {
2339+
let mut output_val = 0;
2340+
for out in tx.output.iter() {
2341+
if out.value > 21_000_000_0000_0000 { panic!("Value-overflowing transaction provided to block connected"); }
2342+
output_val += out.value;
2343+
if output_val > 21_000_000_0000_0000 { panic!("Value-overflowing transaction provided to block connected"); }
2344+
}
2345+
}
2346+
23382347
log_trace!(self, "Block {} at height {} connected with {} txn matched", block_hash, height, txn_matched.len());
23392348
let mut watch_outputs = Vec::new();
23402349
let mut spendable_outputs = Vec::new();

0 commit comments

Comments
 (0)