Skip to content

Commit 674fdca

Browse files
committed
Fix crash in chanmon_fail_consistency due to fuzz hash collisions
1 parent a9ab9b7 commit 674fdca

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

fuzz/fuzz_targets/chanmon_fail_consistency.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use utils::test_logger;
4949
use secp256k1::key::{PublicKey,SecretKey};
5050
use secp256k1::Secp256k1;
5151

52+
use std::collections::HashSet;
5253
use std::sync::{Arc,Mutex};
5354
use std::io::Cursor;
5455

@@ -435,13 +436,19 @@ pub fn do_test(data: &[u8]) {
435436

436437
macro_rules! process_events {
437438
($node: expr, $fail: expr) => { {
439+
// In case we get 256 payments we may have a hash collision, resulting in the
440+
// second claim/fail call not finding the duplicate-hash HTLC, so we have to
441+
// deduplicate the calls here.
442+
let mut claim_set = HashSet::new();
438443
for event in nodes[$node].get_and_clear_pending_events() {
439444
match event {
440445
events::Event::PaymentReceived { payment_hash, .. } => {
441-
if $fail {
442-
assert!(nodes[$node].fail_htlc_backwards(&payment_hash));
443-
} else {
444-
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0)));
446+
if claim_set.insert(payment_hash.0) {
447+
if $fail {
448+
assert!(nodes[$node].fail_htlc_backwards(&payment_hash));
449+
} else {
450+
assert!(nodes[$node].claim_funds(PaymentPreimage(payment_hash.0)));
451+
}
445452
}
446453
},
447454
events::Event::PaymentSent { .. } => {},

0 commit comments

Comments
 (0)