From 1a574d205557f6770d00f6f297dfd9d6ff5a53c0 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 28 May 2020 16:03:03 -0400 Subject: [PATCH] Drop requirement that all ChannelKeys expose the payment_point --- lightning/src/chain/keysinterface.rs | 5 ----- lightning/src/ln/channel.rs | 9 ++++----- lightning/src/ln/channelmonitor.rs | 2 +- lightning/src/ln/functional_tests.rs | 4 ++-- lightning/src/util/enforcing_trait_impls.rs | 1 - 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 5859385d9..88040a04b 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -197,10 +197,6 @@ impl Readable for SpendableOutputDescriptor { pub trait ChannelKeys : Send+Clone { /// Gets the local secret key for blinded revocation pubkey fn revocation_base_key<'a>(&'a self) -> &'a SecretKey; - /// Gets the local secret key used in the to_remote output of remote commitment tx (ie the - /// output to us in transactions our counterparty broadcasts). - /// Also as part of obscured commitment number. - fn payment_key<'a>(&'a self) -> &'a SecretKey; /// Gets the local secret key used in HTLC-Success/HTLC-Timeout txn and to_local output fn delayed_payment_base_key<'a>(&'a self) -> &'a SecretKey; /// Gets the local htlc secret key used in commitment tx htlc outputs @@ -415,7 +411,6 @@ impl InMemoryChannelKeys { impl ChannelKeys for InMemoryChannelKeys { fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key } - fn payment_key(&self) -> &SecretKey { &self.payment_key } fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key } fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key } fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 9c8fc3431..48d6e674d 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -766,15 +766,14 @@ impl Channel { fn get_commitment_transaction_number_obscure_factor(&self) -> u64 { let mut sha = Sha256::engine(); - let our_payment_point = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()); let their_payment_point = &self.their_pubkeys.as_ref().unwrap().payment_point.serialize(); if self.channel_outbound { - sha.input(&our_payment_point.serialize()); + sha.input(&self.local_keys.pubkeys().payment_point.serialize()); sha.input(their_payment_point); } else { sha.input(their_payment_point); - sha.input(&our_payment_point.serialize()); + sha.input(&self.local_keys.pubkeys().payment_point.serialize()); } let res = Sha256::from_engine(sha).into_inner(); @@ -3317,7 +3316,7 @@ impl Channel { max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: local_keys.funding_pubkey, revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()), - payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()), + payment_point: local_keys.payment_point, delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()), htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()), first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret), @@ -3351,7 +3350,7 @@ impl Channel { max_accepted_htlcs: OUR_MAX_HTLCS, funding_pubkey: local_keys.funding_pubkey, revocation_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.revocation_base_key()), - payment_point: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.payment_key()), + payment_point: local_keys.payment_point, delayed_payment_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.delayed_payment_base_key()), htlc_basepoint: PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.htlc_base_key()), first_per_commitment_point: PublicKey::from_secret_key(&self.secp_ctx, &local_commitment_secret), diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 6d10fdb4f..4f20b1d42 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -1641,7 +1641,7 @@ impl ChannelMonitor { self.remote_payment_script = { // Note that the Network here is ignored as we immediately drop the address for the // script_pubkey version - let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &self.keys.payment_key()).serialize()); + let payment_hash160 = WPubkeyHash::hash(&self.keys.pubkeys().payment_point.serialize()); Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script() }; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 5eb360285..9513dc665 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -4293,10 +4293,10 @@ macro_rules! check_spendable_outputs { }; let secp_ctx = Secp256k1::new(); let keys = $keysinterface.derive_channel_keys($chan_value, key_derivation_params.0, key_derivation_params.1); - let remotepubkey = PublicKey::from_secret_key(&secp_ctx, &keys.payment_key()); + let remotepubkey = keys.pubkeys().payment_point; let witness_script = Address::p2pkh(&::bitcoin::PublicKey{compressed: true, key: remotepubkey}, Network::Testnet).script_pubkey(); let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap(); - let remotesig = secp_ctx.sign(&sighash, &keys.payment_key()); + let remotesig = secp_ctx.sign(&sighash, &keys.inner.payment_key); spend_tx.input[0].witness.push(remotesig.serialize_der().to_vec()); spend_tx.input[0].witness[0].push(SigHashType::All as u8); spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec()); diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index 416663748..ffb05762a 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -52,7 +52,6 @@ impl EnforcingChannelKeys { impl ChannelKeys for EnforcingChannelKeys { fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() } - fn payment_key(&self) -> &SecretKey { self.inner.payment_key() } fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() } fn htlc_base_key(&self) -> &SecretKey { self.inner.htlc_base_key() } fn commitment_seed(&self) -> &[u8; 32] { self.inner.commitment_seed() } -- 2.39.5