Use EnforcingChannelKeys in fuzz targets to get more coverage
authorMatt Corallo <git@bluematt.me>
Fri, 6 Dec 2019 19:08:34 +0000 (14:08 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 12 Dec 2019 18:37:07 +0000 (13:37 -0500)
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs

index 9cdeace668a7b60b7428224eb8f7c3d95a16d2f4..3cae8f8eb4833b43a33f3cb8577342af1d3cf082 100644 (file)
@@ -24,12 +24,13 @@ use bitcoin_hashes::sha256d::Hash as Sha256d;
 use lightning::chain::chaininterface;
 use lightning::chain::transaction::OutPoint;
 use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
-use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
+use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
 use lightning::ln::channelmonitor;
 use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
 use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, ChannelManagerReadArgs};
 use lightning::ln::router::{Route, RouteHop};
 use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, LightningError, UpdateAddHTLC, LocalFeatures};
+use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
 use lightning::util::events;
 use lightning::util::logger::Logger;
 use lightning::util::config::UserConfig;
@@ -130,7 +131,7 @@ struct KeyProvider {
        channel_id: atomic::AtomicU8,
 }
 impl KeysInterface for KeyProvider {
-       type ChanKeySigner = InMemoryChannelKeys;
+       type ChanKeySigner = EnforcingChannelKeys;
 
        fn get_node_secret(&self) -> SecretKey {
                SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_id]).unwrap()
@@ -148,15 +149,15 @@ impl KeysInterface for KeyProvider {
                PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, self.node_id]).unwrap())
        }
 
-       fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys {
-               InMemoryChannelKeys {
+       fn get_channel_keys(&self, _inbound: bool) -> EnforcingChannelKeys {
+               EnforcingChannelKeys::new(InMemoryChannelKeys {
                        funding_key:               SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, self.node_id]).unwrap(),
                        revocation_base_key:       SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, self.node_id]).unwrap(),
                        payment_base_key:          SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, self.node_id]).unwrap(),
                        delayed_payment_base_key:  SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, self.node_id]).unwrap(),
                        htlc_base_key:             SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, self.node_id]).unwrap(),
                        commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, self.node_id],
-               }
+               })
        }
 
        fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) {
@@ -225,7 +226,7 @@ pub fn do_test(data: &[u8]) {
                                channel_monitors: &monitor_refs,
                        };
 
-                       let res = (<(Sha256d, ChannelManager<InMemoryChannelKeys>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor);
+                       let res = (<(Sha256d, ChannelManager<EnforcingChannelKeys>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor);
                        for (_, was_good) in $old_monitors.latest_updates_good_at_last_ser.lock().unwrap().iter() {
                                if !was_good {
                                        // If the last time we updated a monitor we didn't successfully update (and we
index 4408c4392bc7e4d9bcbad7b90b03394008db7ad2..fc8232f29c00f57fb1abf925e95ec8587bbb7487 100644 (file)
@@ -26,6 +26,7 @@ use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage
 use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
 use lightning::ln::router::Router;
 use lightning::util::events::{EventsProvider,Event};
+use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
 use lightning::util::logger::Logger;
 use lightning::util::config::UserConfig;
 
@@ -135,7 +136,7 @@ impl<'a> Hash for Peer<'a> {
 }
 
 struct MoneyLossDetector<'a, 'b> {
-       manager: Arc<ChannelManager<'b, InMemoryChannelKeys>>,
+       manager: Arc<ChannelManager<'b, EnforcingChannelKeys>>,
        monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>,
        handler: PeerManager<Peer<'a>>,
 
@@ -148,7 +149,7 @@ struct MoneyLossDetector<'a, 'b> {
        blocks_connected: u32,
 }
 impl<'a, 'b> MoneyLossDetector<'a, 'b> {
-       pub fn new(peers: &'a RefCell<[bool; 256]>, manager: Arc<ChannelManager<'b, InMemoryChannelKeys>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>, handler: PeerManager<Peer<'a>>) -> Self {
+       pub fn new(peers: &'a RefCell<[bool; 256]>, manager: Arc<ChannelManager<'b, EnforcingChannelKeys>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>, handler: PeerManager<Peer<'a>>) -> Self {
                MoneyLossDetector {
                        manager,
                        monitor,
@@ -228,7 +229,7 @@ struct KeyProvider {
        counter: AtomicU64,
 }
 impl KeysInterface for KeyProvider {
-       type ChanKeySigner = InMemoryChannelKeys;
+       type ChanKeySigner = EnforcingChannelKeys;
 
        fn get_node_secret(&self) -> SecretKey {
                self.node_secret.clone()
@@ -246,9 +247,9 @@ impl KeysInterface for KeyProvider {
                PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).unwrap())
        }
 
-       fn get_channel_keys(&self, inbound: bool) -> InMemoryChannelKeys {
+       fn get_channel_keys(&self, inbound: bool) -> EnforcingChannelKeys {
                let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;
-               if inbound {
+               EnforcingChannelKeys::new(if inbound {
                        InMemoryChannelKeys {
                                funding_key:               SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ctr]).unwrap(),
                                revocation_base_key:       SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, ctr]).unwrap(),
@@ -266,7 +267,7 @@ impl KeysInterface for KeyProvider {
                                htlc_base_key:             SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, ctr]).unwrap(),
                                commitment_seed: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, ctr],
                        }
-               }
+               })
        }
 
        fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) {