]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Adopting (W)PubkeyHash types
authorDr. Maxim Orlovsky <orlovsky@pandoracore.com>
Mon, 27 Apr 2020 16:13:27 +0000 (18:13 +0200)
committerDr. Maxim Orlovsky <orlovsky@pandoracore.com>
Wed, 29 Apr 2020 10:37:57 +0000 (12:37 +0200)
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
lightning/src/chain/keysinterface.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmonitor.rs

index 8a57c4fc2693d75c88278e0d39369f44fad80ffd..b28bbaa12bd8872dc9bf510dc88589926aea8ff9 100644 (file)
@@ -17,9 +17,8 @@ use bitcoin::blockdata::opcodes;
 use bitcoin::network::constants::Network;
 
 use bitcoin::hashes::Hash as TraitImport;
-use bitcoin::hashes::hash160::Hash as Hash160;
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hash_types::BlockHash;
+use bitcoin::hash_types::{BlockHash, WPubkeyHash};
 
 use lightning::chain::chaininterface;
 use lightning::chain::transaction::OutPoint;
@@ -144,7 +143,7 @@ impl KeysInterface for KeyProvider {
        fn get_destination_script(&self) -> Script {
                let secp_ctx = Secp256k1::signing_only();
                let channel_monitor_claim_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, self.node_id]).unwrap();
-               let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+               let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
        }
 
index 377c9b0d7577294ed5180e7b2eef2c8cb435be62..d8d4abf9c7a93b5ec5aefc86728fabc714a16002 100644 (file)
@@ -14,9 +14,8 @@ use bitcoin::util::hash::BitcoinHash;
 
 use bitcoin::hashes::Hash as TraitImport;
 use bitcoin::hashes::HashEngine as TraitImportEngine;
-use bitcoin::hashes::hash160::Hash as Hash160;
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hash_types::{Txid, BlockHash};
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
 use lightning::chain::transaction::OutPoint;
@@ -240,7 +239,7 @@ impl KeysInterface for KeyProvider {
        fn get_destination_script(&self) -> Script {
                let secp_ctx = Secp256k1::signing_only();
                let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
-               let our_channel_monitor_claim_key_hash = <Hash160 as bitcoin::hashes::Hash>::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+               let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
        }
 
index 51a7923963e599891fddb4a20107964184f6ba91..ce865107abc3ee831b25263a7281b08921547155 100644 (file)
@@ -13,7 +13,7 @@ use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::HashEngine as Sha256State;
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
-use bitcoin::hashes::hash160::Hash as Hash160;
+use bitcoin::hash_types::WPubkeyHash;
 
 use bitcoin::secp256k1::key::{SecretKey, PublicKey};
 use bitcoin::secp256k1::{Secp256k1, Signature, Signing};
@@ -513,9 +513,9 @@ impl KeysManager {
                                let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
                                let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
                                        Ok(destination_key) => {
-                                               let pubkey_hash160 = Hash160::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.key.serialize()[..]);
+                                               let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
                                                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                                                             .push_slice(&pubkey_hash160.into_inner())
+                                                             .push_slice(&wpubkey_hash.into_inner())
                                                              .into_script()
                                        },
                                        Err(_) => panic!("Your RNG is busted"),
index d833eca91c5fcf185f347bf88f788cb6b1dff20e..9be3f38a78e6c027c7328a6d5e6c35e69013c8bd 100644 (file)
@@ -11,8 +11,7 @@ use bitcoin::util::bip143;
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::ripemd160::Hash as Ripemd160;
-use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hash_types::Txid;
+use bitcoin::hash_types::{Txid, PubkeyHash};
 
 use ln::channelmanager::{PaymentHash, PaymentPreimage};
 use ln::msgs::DecodeError;
@@ -364,7 +363,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        if htlc.offered {
                Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&Hash160::hash(&revocation_key.serialize())[..])
+                             .push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
                              .push_opcode(opcodes::all::OP_EQUAL)
                              .push_opcode(opcodes::all::OP_IF)
                              .push_opcode(opcodes::all::OP_CHECKSIG)
@@ -392,7 +391,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
        } else {
                Builder::new().push_opcode(opcodes::all::OP_DUP)
                              .push_opcode(opcodes::all::OP_HASH160)
-                             .push_slice(&Hash160::hash(&revocation_key.serialize())[..])
+                             .push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
                              .push_opcode(opcodes::all::OP_EQUAL)
                              .push_opcode(opcodes::all::OP_IF)
                              .push_opcode(opcodes::all::OP_CHECKSIG)
index cfb5e8096e32d93680d4912c9c9e0f841f192f2a..bef69235b3e139b95d3a129b6eec1cbe7462b19f 100644 (file)
@@ -8,8 +8,7 @@ use bitcoin::consensus::encode;
 
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hash_types::{Txid, BlockHash};
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use bitcoin::secp256k1::key::{PublicKey,SecretKey};
 use bitcoin::secp256k1::{Secp256k1,Signature};
@@ -983,7 +982,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                        log_trace!(self, "   ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
                        txouts.push((TxOut {
                                script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                                                            .push_slice(&Hash160::hash(&keys.b_payment_key.serialize())[..])
+                                                            .push_slice(&WPubkeyHash::hash(&keys.b_payment_key.serialize())[..])
                                                             .into_script(),
                                value: value_to_b as u64
                        }, None));
@@ -1025,7 +1024,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
 
        #[inline]
        fn get_closing_scriptpubkey(&self) -> Script {
-               let our_channel_close_key_hash = Hash160::hash(&self.shutdown_pubkey.serialize());
+               let our_channel_close_key_hash = WPubkeyHash::hash(&self.shutdown_pubkey.serialize());
                Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
        }
 
@@ -4310,9 +4309,8 @@ mod tests {
        use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
        use bitcoin::secp256k1::key::{SecretKey,PublicKey};
        use bitcoin::hashes::sha256::Hash as Sha256;
-       use bitcoin::hashes::hash160::Hash as Hash160;
        use bitcoin::hashes::Hash;
-       use bitcoin::hash_types::Txid;
+       use bitcoin::hash_types::{Txid, WPubkeyHash};
        use std::sync::Arc;
        use rand::{thread_rng,Rng};
 
@@ -4341,7 +4339,7 @@ mod tests {
                fn get_destination_script(&self) -> Script {
                        let secp_ctx = Secp256k1::signing_only();
                        let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
-                       let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
+                       let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
                        Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
                }
 
index edf87da6c59eba8dfde6c76d6181f55aab21e73c..71196252a3ca25313f9489086299079438531da0 100644 (file)
@@ -21,8 +21,7 @@ use bitcoin::util::hash::BitcoinHash;
 
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::sha256::Hash as Sha256;
-use bitcoin::hashes::hash160::Hash as Hash160;
-use bitcoin::hash_types::{Txid, BlockHash};
+use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use bitcoin::secp256k1::{Secp256k1,Signature};
 use bitcoin::secp256k1::key::{SecretKey,PublicKey};
@@ -1061,7 +1060,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        logger: Arc<Logger>) -> ChannelMonitor<ChanSigner> {
 
                assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
-               let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
+               let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
                let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
 
                let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), their_to_self_delay, logger.clone());
@@ -1231,7 +1230,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
        pub(super) fn provide_rescue_remote_commitment_tx_info(&mut self, their_revocation_point: PublicKey) {
                if let Ok(payment_key) = chan_utils::derive_public_key(&self.secp_ctx, &their_revocation_point, &self.keys.pubkeys().payment_basepoint) {
                        let to_remote_script =  Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
-                               .push_slice(&Hash160::hash(&payment_key.serialize())[..])
+                               .push_slice(&WPubkeyHash::hash(&payment_key.serialize())[..])
                                .into_script();
                        if let Ok(to_remote_key) = chan_utils::derive_private_key(&self.secp_ctx, &their_revocation_point, &self.keys.payment_base_key()) {
                                self.broadcasted_remote_payment_script = Some((to_remote_script, to_remote_key));
@@ -1460,7 +1459,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        self.broadcasted_remote_payment_script = {
                                // Note that the Network here is ignored as we immediately drop the address for the
                                // script_pubkey version
-                               let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
+                               let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
                                Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
                        };
 
@@ -1609,7 +1608,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                                        self.broadcasted_remote_payment_script = {
                                                // Note that the Network here is ignored as we immediately drop the address for the
                                                // script_pubkey version
-                                               let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
+                                               let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
                                                Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
                                        };