X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Ffuzz_targets%2Ffull_stack_target.rs;h=e6515b41e7b087911c5796cc5f3caf661adb1c4e;hb=refs%2Fheads%2F2018-08-peer_handler-trace;hp=8f7ec2df0a76013918e2ec7b154deceed7057cab;hpb=0029f04fce6beba29e60b2c227d51bcf1ba15545;p=rust-lightning diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index 8f7ec2df..e6515b41 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -10,7 +10,6 @@ use bitcoin::network::constants::Network; use bitcoin::network::serialize::{serialize, BitcoinHash}; use bitcoin::util::hash::Sha256dHash; -use crypto::sha2::Sha256; use crypto::digest::Digest; use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil}; @@ -22,6 +21,7 @@ use lightning::ln::router::Router; use lightning::util::events::{EventsProvider,Event}; use lightning::util::reset_rng_state; use lightning::util::logger::Logger; +use lightning::util::sha2::Sha256; mod utils; @@ -174,7 +174,7 @@ pub fn do_test(data: &[u8]) { Err(_) => return, }; - let logger: Arc = Arc::new(test_logger::TestLogger::new()); + let logger: Arc = Arc::new(test_logger::TestLogger{}); let monitor = Arc::new(TestChannelMonitor{}); let watch = Arc::new(ChainWatchInterfaceUtil::new(Arc::clone(&logger))); let broadcast = Arc::new(TestBroadcaster{}); @@ -189,7 +189,7 @@ pub fn do_test(data: &[u8]) { }, our_network_key, Arc::clone(&logger)); let mut should_forward = false; - let mut payments_received = Vec::new(); + let mut payments_received: Vec<[u8; 32]> = Vec::new(); let mut payments_sent = 0; let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new(); let mut pending_funding_signatures = HashMap::new(); @@ -246,7 +246,6 @@ pub fn do_test(data: &[u8]) { let mut sha = Sha256::new(); sha.input(&payment_hash); sha.result(&mut payment_hash); - for i in 1..32 { payment_hash[i] = 0; } payments_sent += 1; match channelmanager.send_payment(route, payment_hash) { Ok(_) => {}, @@ -276,22 +275,14 @@ pub fn do_test(data: &[u8]) { }, 8 => { for payment in payments_received.drain(..) { - let mut payment_preimage = None; - for i in 0..payments_sent { - let mut payment_hash = [0; 32]; - payment_hash[0..8].copy_from_slice(&be64_to_array(i)); - let mut sha = Sha256::new(); - sha.input(&payment_hash); - sha.result(&mut payment_hash); - for i in 1..32 { payment_hash[i] = 0; } - if payment_hash == payment { - payment_hash = [0; 32]; - payment_hash[0..8].copy_from_slice(&be64_to_array(i)); - payment_preimage = Some(payment_hash); - break; - } - } - channelmanager.claim_funds(payment_preimage.unwrap()); + let mut payment_preimage = [0; 32]; + payment_preimage[0] = payment[0]; + let mut sha = Sha256::new(); + sha.input(&payment_preimage); + let mut payment_hash_check = [0; 32]; + sha.result(&mut payment_hash_check); + assert!(payment_hash_check == payment); + channelmanager.claim_funds(payment_preimage); } }, 9 => { @@ -300,13 +291,21 @@ pub fn do_test(data: &[u8]) { } }, 10 => { - for funding_generation in pending_funding_generation.drain(..) { + for funding_generation in pending_funding_generation.drain(..) { let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut { value: funding_generation.1, script_pubkey: funding_generation.2, }] }; let funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0); - channelmanager.funding_transaction_generated(&funding_generation.0, funding_output.clone()); - pending_funding_signatures.insert(funding_output, tx); + let mut found_duplicate_txo = false; + for chan in channelmanager.list_channels() { + if chan.channel_id == funding_output.to_channel_id() { + found_duplicate_txo = true; + } + } + if !found_duplicate_txo { + channelmanager.funding_transaction_generated(&funding_generation.0, funding_output.clone()); + pending_funding_signatures.insert(funding_output, tx); + } } }, 11 => {