]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[fuzz] Add additional method calls in full_stack_target
authorMatt Corallo <git@bluematt.me>
Fri, 19 Jan 2024 00:42:17 +0000 (00:42 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 7 Feb 2024 02:32:52 +0000 (02:32 +0000)
The whole point of full_stack_target is to just expose our entire
API to the fuzzer and see what happens. Sadly, we're really only
exposing a small subset of our API. This improves that by exposing
a handful of other assorted methods from ChannelManager and
PeerManager.

fuzz/src/full_stack.rs

index cfa6712a07ab491220cfe6a1807416ac2f64f099..2a9e4a73ed1c23256f2a0f130703b7996e590dcb 100644 (file)
@@ -37,7 +37,7 @@ use lightning::chain::transaction::OutPoint;
 use lightning::sign::{InMemorySigner, Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
 use lightning::events::Event;
 use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
-use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId, RecipientOnionFields, Retry};
+use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId, RecipientOnionFields, Retry, InterceptId};
 use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
 use lightning::ln::msgs::{self, DecodeError};
 use lightning::ln::script::ShutdownScript;
@@ -505,6 +505,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
 
        let mut should_forward = false;
        let mut payments_received: Vec<PaymentHash> = Vec::new();
+       let mut intercepted_htlcs: Vec<InterceptId> = Vec::new();
        let mut payments_sent: u16 = 0;
        let mut pending_funding_generation: Vec<(ChannelId, PublicKey, u64, ScriptBuf)> = Vec::new();
        let mut pending_funding_signatures = HashMap::new();
@@ -580,6 +581,19 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
                                        PaymentId(payment_hash.0), params, Retry::Attempts(2)
                                );
                        },
+                       17 => {
+                               let final_value_msat = slice_to_be24(get_slice!(3)) as u64;
+                               let payment_params = PaymentParameters::from_node_id(get_pubkey!(), 42);
+                               let params = RouteParameters::from_payment_params_and_value(
+                                       payment_params, final_value_msat);
+                               let _ = channelmanager.send_preflight_probes(params, None);
+                       },
+                       18 => {
+                               let idx = u16::from_be_bytes(get_bytes!(2)) % cmp::max(payments_sent, 1);
+                               let mut payment_id = PaymentId([0; 32]);
+                               payment_id.0[0..2].copy_from_slice(&idx.to_be_bytes());
+                               channelmanager.abandon_payment(payment_id);
+                       },
                        5 => {
                                let peer_id = get_slice!(1)[0];
                                if !peers.borrow()[peer_id as usize] { return; }
@@ -714,7 +728,36 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
                                channels.sort_by(|a, b| { a.channel_id.cmp(&b.channel_id) });
                                channelmanager.force_close_broadcasting_latest_txn(&channels[channel_id].channel_id, &channels[channel_id].counterparty.node_id).unwrap();
                        },
-                       // 15 is above
+                       // 15, 16, 17, 18 is above
+                       19 => {
+                               let mut list = loss_detector.handler.get_peer_node_ids();
+                               list.sort_by_key(|v| v.0);
+                               if let Some((id, _)) = list.get(0) {
+                                       loss_detector.handler.disconnect_by_node_id(*id);
+                               }
+                       },
+                       20 => loss_detector.handler.disconnect_all_peers(),
+                       21 => loss_detector.handler.timer_tick_occurred(),
+                       22 =>
+                               loss_detector.handler.broadcast_node_announcement([42; 3], [43; 32], Vec::new()),
+                       32 => channelmanager.timer_tick_occurred(),
+                       33 => {
+                               for id in intercepted_htlcs.drain(..) {
+                                       channelmanager.fail_intercepted_htlc(id).unwrap();
+                               }
+                       }
+                       34 => {
+                               let amt = u64::from_be_bytes(get_bytes!(8));
+                               let chans = channelmanager.list_channels();
+                               for id in intercepted_htlcs.drain(..) {
+                                       if chans.is_empty() {
+                                               channelmanager.fail_intercepted_htlc(id).unwrap();
+                                       } else {
+                                               let chan = &chans[amt as usize % chans.len()];
+                                               channelmanager.forward_intercepted_htlc(id, &chan.channel_id, chan.counterparty.node_id, amt).unwrap();
+                                       }
+                               }
+                       }
                        _ => return,
                }
                loss_detector.handler.process_events();
@@ -730,6 +773,11 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
                                Event::PendingHTLCsForwardable {..} => {
                                        should_forward = true;
                                },
+                               Event::HTLCIntercepted { intercept_id, .. } => {
+                                       if !intercepted_htlcs.contains(&intercept_id) {
+                                               intercepted_htlcs.push(intercept_id);
+                                       }
+                               },
                                _ => {},
                        }
                }