Skip to content

Commit 5e874fa

Browse files
committed
Adopting (W)PubkeyHash types
1 parent 257b576 commit 5e874fa

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use bitcoin::blockdata::opcodes;
1717
use bitcoin::network::constants::Network;
1818

1919
use bitcoin::hashes::Hash as TraitImport;
20-
use bitcoin::hashes::hash160::Hash as Hash160;
2120
use bitcoin::hashes::sha256::Hash as Sha256;
22-
use bitcoin::hash_types::BlockHash;
21+
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
2322

2423
use lightning::chain::chaininterface;
2524
use lightning::chain::transaction::OutPoint;
@@ -144,7 +143,7 @@ impl KeysInterface for KeyProvider {
144143
fn get_destination_script(&self) -> Script {
145144
let secp_ctx = Secp256k1::signing_only();
146145
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();
147-
let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
146+
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
148147
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
149148
}
150149

fuzz/src/full_stack.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use bitcoin::util::hash::BitcoinHash;
1414

1515
use bitcoin::hashes::Hash as TraitImport;
1616
use bitcoin::hashes::HashEngine as TraitImportEngine;
17-
use bitcoin::hashes::hash160::Hash as Hash160;
1817
use bitcoin::hashes::sha256::Hash as Sha256;
19-
use bitcoin::hash_types::{Txid, BlockHash};
18+
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2019

2120
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
2221
use lightning::chain::transaction::OutPoint;
@@ -240,7 +239,7 @@ impl KeysInterface for KeyProvider {
240239
fn get_destination_script(&self) -> Script {
241240
let secp_ctx = Secp256k1::signing_only();
242241
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
243-
let our_channel_monitor_claim_key_hash = <Hash160 as bitcoin::hashes::Hash>::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
242+
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
244243
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
245244
}
246245

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::hashes::{Hash, HashEngine};
1313
use bitcoin::hashes::sha256::HashEngine as Sha256State;
1414
use bitcoin::hashes::sha256::Hash as Sha256;
1515
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
16-
use bitcoin::hashes::hash160::Hash as Hash160;
16+
use bitcoin::hash_types::WPubkeyHash;
1717

1818
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
1919
use bitcoin::secp256k1::{Secp256k1, Signature, Signing};
@@ -513,9 +513,9 @@ impl KeysManager {
513513
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
514514
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
515515
Ok(destination_key) => {
516-
let pubkey_hash160 = Hash160::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.key.serialize()[..]);
516+
let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
517517
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
518-
.push_slice(&pubkey_hash160.into_inner())
518+
.push_slice(&wpubkey_hash.into_inner())
519519
.into_script()
520520
},
521521
Err(_) => panic!("Your RNG is busted"),

lightning/src/ln/chan_utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use bitcoin::util::bip143;
1111
use bitcoin::hashes::{Hash, HashEngine};
1212
use bitcoin::hashes::sha256::Hash as Sha256;
1313
use bitcoin::hashes::ripemd160::Hash as Ripemd160;
14-
use bitcoin::hashes::hash160::Hash as Hash160;
15-
use bitcoin::hash_types::Txid;
14+
use bitcoin::hash_types::{Txid, PubkeyHash};
1615

1716
use ln::channelmanager::{PaymentHash, PaymentPreimage};
1817
use ln::msgs::DecodeError;
@@ -364,7 +363,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
364363
if htlc.offered {
365364
Builder::new().push_opcode(opcodes::all::OP_DUP)
366365
.push_opcode(opcodes::all::OP_HASH160)
367-
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
366+
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
368367
.push_opcode(opcodes::all::OP_EQUAL)
369368
.push_opcode(opcodes::all::OP_IF)
370369
.push_opcode(opcodes::all::OP_CHECKSIG)
@@ -392,7 +391,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
392391
} else {
393392
Builder::new().push_opcode(opcodes::all::OP_DUP)
394393
.push_opcode(opcodes::all::OP_HASH160)
395-
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
394+
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
396395
.push_opcode(opcodes::all::OP_EQUAL)
397396
.push_opcode(opcodes::all::OP_IF)
398397
.push_opcode(opcodes::all::OP_CHECKSIG)

lightning/src/ln/channel.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use bitcoin::consensus::encode;
88

99
use bitcoin::hashes::{Hash, HashEngine};
1010
use bitcoin::hashes::sha256::Hash as Sha256;
11-
use bitcoin::hashes::hash160::Hash as Hash160;
12-
use bitcoin::hash_types::{Txid, BlockHash};
11+
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
1312

1413
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
1514
use bitcoin::secp256k1::{Secp256k1,Signature};
@@ -983,7 +982,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
983982
log_trace!(self, " ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
984983
txouts.push((TxOut {
985984
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
986-
.push_slice(&Hash160::hash(&keys.b_payment_key.serialize())[..])
985+
.push_slice(&WPubkeyHash::hash(&keys.b_payment_key.serialize())[..])
987986
.into_script(),
988987
value: value_to_b as u64
989988
}, None));
@@ -1025,7 +1024,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
10251024

10261025
#[inline]
10271026
fn get_closing_scriptpubkey(&self) -> Script {
1028-
let our_channel_close_key_hash = Hash160::hash(&self.shutdown_pubkey.serialize());
1027+
let our_channel_close_key_hash = WPubkeyHash::hash(&self.shutdown_pubkey.serialize());
10291028
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
10301029
}
10311030

@@ -4310,9 +4309,8 @@ mod tests {
43104309
use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
43114310
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
43124311
use bitcoin::hashes::sha256::Hash as Sha256;
4313-
use bitcoin::hashes::hash160::Hash as Hash160;
43144312
use bitcoin::hashes::Hash;
4315-
use bitcoin::hash_types::Txid;
4313+
use bitcoin::hash_types::{Txid, WPubkeyHash};
43164314
use std::sync::Arc;
43174315
use rand::{thread_rng,Rng};
43184316

@@ -4341,7 +4339,7 @@ mod tests {
43414339
fn get_destination_script(&self) -> Script {
43424340
let secp_ctx = Secp256k1::signing_only();
43434341
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
4344-
let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
4342+
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
43454343
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
43464344
}
43474345

lightning/src/ln/channelmonitor.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use bitcoin::util::hash::BitcoinHash;
2121

2222
use bitcoin::hashes::Hash;
2323
use bitcoin::hashes::sha256::Hash as Sha256;
24-
use bitcoin::hashes::hash160::Hash as Hash160;
25-
use bitcoin::hash_types::{Txid, BlockHash};
24+
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2625

2726
use bitcoin::secp256k1::{Secp256k1,Signature};
2827
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
@@ -1061,7 +1060,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
10611060
logger: Arc<Logger>) -> ChannelMonitor<ChanSigner> {
10621061

10631062
assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
1064-
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
1063+
let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
10651064
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
10661065

10671066
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> {
12311230
pub(super) fn provide_rescue_remote_commitment_tx_info(&mut self, their_revocation_point: PublicKey) {
12321231
if let Ok(payment_key) = chan_utils::derive_public_key(&self.secp_ctx, &their_revocation_point, &self.keys.pubkeys().payment_basepoint) {
12331232
let to_remote_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
1234-
.push_slice(&Hash160::hash(&payment_key.serialize())[..])
1233+
.push_slice(&WPubkeyHash::hash(&payment_key.serialize())[..])
12351234
.into_script();
12361235
if let Ok(to_remote_key) = chan_utils::derive_private_key(&self.secp_ctx, &their_revocation_point, &self.keys.payment_base_key()) {
12371236
self.broadcasted_remote_payment_script = Some((to_remote_script, to_remote_key));
@@ -1460,7 +1459,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14601459
self.broadcasted_remote_payment_script = {
14611460
// Note that the Network here is ignored as we immediately drop the address for the
14621461
// script_pubkey version
1463-
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
1462+
let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
14641463
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
14651464
};
14661465

@@ -1609,7 +1608,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16091608
self.broadcasted_remote_payment_script = {
16101609
// Note that the Network here is ignored as we immediately drop the address for the
16111610
// script_pubkey version
1612-
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
1611+
let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
16131612
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
16141613
};
16151614

0 commit comments

Comments
 (0)