Skip to content

Commit 04215c4

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 a343cf9 commit 04215c4

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
@@ -485,6 +485,12 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
485485
} else {
486486
let txres: Result<Transaction, _> = deserialize(get_slice!(txlen));
487487
if let Ok(tx) = txres {
488+
let mut output_val = 0;
489+
for out in tx.output.iter() {
490+
if out.value > 21_000_000_0000_0000 { return; }
491+
output_val += out.value;
492+
if output_val > 21_000_000_0000_0000 { return; }
493+
}
488494
loss_detector.connect_block(&[tx]);
489495
} else {
490496
return;

lightning/src/ln/channelmonitor.rs

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

23362336
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)>) {
2337+
for tx in txn_matched {
2338+
let mut output_val = 0;
2339+
for out in tx.output.iter() {
2340+
if out.value > 21_000_000_0000_0000 { panic!("Value-overflowing transaction provided to block connected"); }
2341+
output_val += out.value;
2342+
if output_val > 21_000_000_0000_0000 { panic!("Value-overflowing transaction provided to block connected"); }
2343+
}
2344+
}
2345+
23372346
log_trace!(self, "Block {} at height {} connected with {} txn matched", block_hash, height, txn_matched.len());
23382347
let mut watch_outputs = Vec::new();
23392348
let mut spendable_outputs = Vec::new();

0 commit comments

Comments
 (0)