Skip to content

Commit d2520f4

Browse files
authored
Merge pull request #539 from TheBlueMatt/2020-03-static-remotekey
Require static_remotekey
2 parents 8a27d8e + 07db23d commit d2520f4

11 files changed

+340
-384
lines changed

fuzz/src/full_stack.rs

+15-15
Large diffs are not rendered by default.

lightning/src/chain/keysinterface.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub enum SpendableOutputDescriptor {
7474
/// The output which is referenced by the given outpoint
7575
output: TxOut,
7676
},
77+
// TODO: Note that because key is now static and exactly what is provided by us, we should drop
78+
// this in favor of StaticOutput:
7779
/// An output to a P2WPKH, spendable exclusively by the given private key.
7880
/// The witness in the spending input, is, thus, simply:
7981
/// <BIP 143 signature generated with the given key> <public key derived from the given key>
@@ -194,9 +196,10 @@ pub trait ChannelKeys : Send+Clone {
194196
fn funding_key<'a>(&'a self) -> &'a SecretKey;
195197
/// Gets the local secret key for blinded revocation pubkey
196198
fn revocation_base_key<'a>(&'a self) -> &'a SecretKey;
197-
/// Gets the local secret key used in to_remote output of remote commitment tx
198-
/// (and also as part of obscured commitment number)
199-
fn payment_base_key<'a>(&'a self) -> &'a SecretKey;
199+
/// Gets the local secret key used in the to_remote output of remote commitment tx (ie the
200+
/// output to us in transactions our counterparty broadcasts).
201+
/// Also as part of obscured commitment number.
202+
fn payment_key<'a>(&'a self) -> &'a SecretKey;
200203
/// Gets the local secret key used in HTLC-Success/HTLC-Timeout txn and to_local output
201204
fn delayed_payment_base_key<'a>(&'a self) -> &'a SecretKey;
202205
/// Gets the local htlc secret key used in commitment tx htlc outputs
@@ -273,8 +276,8 @@ pub struct InMemoryChannelKeys {
273276
funding_key: SecretKey,
274277
/// Local secret key for blinded revocation pubkey
275278
revocation_base_key: SecretKey,
276-
/// Local secret key used in commitment tx htlc outputs
277-
payment_base_key: SecretKey,
279+
/// Local secret key used for our balance in remote-broadcasted commitment transactions
280+
payment_key: SecretKey,
278281
/// Local secret key used in HTLC tx
279282
delayed_payment_base_key: SecretKey,
280283
/// Local htlc secret key used in commitment tx htlc outputs
@@ -295,19 +298,19 @@ impl InMemoryChannelKeys {
295298
secp_ctx: &Secp256k1<C>,
296299
funding_key: SecretKey,
297300
revocation_base_key: SecretKey,
298-
payment_base_key: SecretKey,
301+
payment_key: SecretKey,
299302
delayed_payment_base_key: SecretKey,
300303
htlc_base_key: SecretKey,
301304
commitment_seed: [u8; 32],
302305
channel_value_satoshis: u64) -> InMemoryChannelKeys {
303306
let local_channel_pubkeys =
304307
InMemoryChannelKeys::make_local_keys(secp_ctx, &funding_key, &revocation_base_key,
305-
&payment_base_key, &delayed_payment_base_key,
308+
&payment_key, &delayed_payment_base_key,
306309
&htlc_base_key);
307310
InMemoryChannelKeys {
308311
funding_key,
309312
revocation_base_key,
310-
payment_base_key,
313+
payment_key,
311314
delayed_payment_base_key,
312315
htlc_base_key,
313316
commitment_seed,
@@ -320,14 +323,14 @@ impl InMemoryChannelKeys {
320323
fn make_local_keys<C: Signing>(secp_ctx: &Secp256k1<C>,
321324
funding_key: &SecretKey,
322325
revocation_base_key: &SecretKey,
323-
payment_base_key: &SecretKey,
326+
payment_key: &SecretKey,
324327
delayed_payment_base_key: &SecretKey,
325328
htlc_base_key: &SecretKey) -> ChannelPublicKeys {
326329
let from_secret = |s: &SecretKey| PublicKey::from_secret_key(secp_ctx, s);
327330
ChannelPublicKeys {
328331
funding_pubkey: from_secret(&funding_key),
329332
revocation_basepoint: from_secret(&revocation_base_key),
330-
payment_basepoint: from_secret(&payment_base_key),
333+
payment_point: from_secret(&payment_key),
331334
delayed_payment_basepoint: from_secret(&delayed_payment_base_key),
332335
htlc_basepoint: from_secret(&htlc_base_key),
333336
}
@@ -337,7 +340,7 @@ impl InMemoryChannelKeys {
337340
impl ChannelKeys for InMemoryChannelKeys {
338341
fn funding_key(&self) -> &SecretKey { &self.funding_key }
339342
fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
340-
fn payment_base_key(&self) -> &SecretKey { &self.payment_base_key }
343+
fn payment_key(&self) -> &SecretKey { &self.payment_key }
341344
fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key }
342345
fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key }
343346
fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed }
@@ -422,7 +425,7 @@ impl Writeable for InMemoryChannelKeys {
422425
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
423426
self.funding_key.write(writer)?;
424427
self.revocation_base_key.write(writer)?;
425-
self.payment_base_key.write(writer)?;
428+
self.payment_key.write(writer)?;
426429
self.delayed_payment_base_key.write(writer)?;
427430
self.htlc_base_key.write(writer)?;
428431
self.commitment_seed.write(writer)?;
@@ -437,7 +440,7 @@ impl Readable for InMemoryChannelKeys {
437440
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
438441
let funding_key = Readable::read(reader)?;
439442
let revocation_base_key = Readable::read(reader)?;
440-
let payment_base_key = Readable::read(reader)?;
443+
let payment_key = Readable::read(reader)?;
441444
let delayed_payment_base_key = Readable::read(reader)?;
442445
let htlc_base_key = Readable::read(reader)?;
443446
let commitment_seed = Readable::read(reader)?;
@@ -446,13 +449,13 @@ impl Readable for InMemoryChannelKeys {
446449
let secp_ctx = Secp256k1::signing_only();
447450
let local_channel_pubkeys =
448451
InMemoryChannelKeys::make_local_keys(&secp_ctx, &funding_key, &revocation_base_key,
449-
&payment_base_key, &delayed_payment_base_key,
452+
&payment_key, &delayed_payment_base_key,
450453
&htlc_base_key);
451454

452455
Ok(InMemoryChannelKeys {
453456
funding_key,
454457
revocation_base_key,
455-
payment_base_key,
458+
payment_key,
456459
delayed_payment_base_key,
457460
htlc_base_key,
458461
commitment_seed,
@@ -598,15 +601,15 @@ impl KeysInterface for KeysManager {
598601
}
599602
let funding_key = key_step!(b"funding key", commitment_seed);
600603
let revocation_base_key = key_step!(b"revocation base key", funding_key);
601-
let payment_base_key = key_step!(b"payment base key", revocation_base_key);
602-
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_base_key);
604+
let payment_key = key_step!(b"payment key", revocation_base_key);
605+
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_key);
603606
let htlc_base_key = key_step!(b"HTLC base key", delayed_payment_base_key);
604607

605608
InMemoryChannelKeys::new(
606609
&self.secp_ctx,
607610
funding_key,
608611
revocation_base_key,
609-
payment_base_key,
612+
payment_key,
610613
delayed_payment_base_key,
611614
htlc_base_key,
612615
commitment_seed,

lightning/src/ln/chan_utils.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,9 @@ pub struct TxCreationKeys {
262262
pub(crate) b_htlc_key: PublicKey,
263263
/// A's Payment Key (which isn't allowed to be spent from for some delay)
264264
pub(crate) a_delayed_payment_key: PublicKey,
265-
/// B's Payment Key
266-
pub(crate) b_payment_key: PublicKey,
267265
}
268266
impl_writeable!(TxCreationKeys, 33*6,
269-
{ per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key, b_payment_key });
267+
{ per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key });
270268

271269
/// One counterparty's public keys which do not change over the life of a channel.
272270
#[derive(Clone, PartialEq)]
@@ -279,9 +277,10 @@ pub struct ChannelPublicKeys {
279277
/// a commitment transaction so that their counterparty can claim all available funds if they
280278
/// broadcast an old state.
281279
pub revocation_basepoint: PublicKey,
282-
/// The base point which is used (with derive_public_key) to derive a per-commitment payment
283-
/// public key which receives immediately-spendable non-HTLC-encumbered funds.
284-
pub payment_basepoint: PublicKey,
280+
/// The public key which receives our immediately spendable primary channel balance in
281+
/// remote-broadcasted commitment transactions. This key is static across every commitment
282+
/// transaction.
283+
pub payment_point: PublicKey,
285284
/// The base point which is used (with derive_public_key) to derive a per-commitment payment
286285
/// public key which receives non-HTLC-encumbered funds which are only available for spending
287286
/// after some delay (or can be claimed via the revocation path).
@@ -294,21 +293,20 @@ pub struct ChannelPublicKeys {
294293
impl_writeable!(ChannelPublicKeys, 33*5, {
295294
funding_pubkey,
296295
revocation_basepoint,
297-
payment_basepoint,
296+
payment_point,
298297
delayed_payment_basepoint,
299298
htlc_basepoint
300299
});
301300

302301

303302
impl TxCreationKeys {
304-
pub(crate) fn new<T: secp256k1::Signing + secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_payment_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, secp256k1::Error> {
303+
pub(crate) fn new<T: secp256k1::Signing + secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, secp256k1::Error> {
305304
Ok(TxCreationKeys {
306305
per_commitment_point: per_commitment_point.clone(),
307306
revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &b_revocation_base)?,
308307
a_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_htlc_base)?,
309308
b_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_htlc_base)?,
310309
a_delayed_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_delayed_payment_base)?,
311-
b_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_payment_base)?,
312310
})
313311
}
314312
}
@@ -537,7 +535,6 @@ impl LocalCommitmentTransaction {
537535
a_htlc_key: dummy_key.clone(),
538536
b_htlc_key: dummy_key.clone(),
539537
a_delayed_payment_key: dummy_key.clone(),
540-
b_payment_key: dummy_key.clone(),
541538
},
542539
feerate_per_kw: 0,
543540
per_htlc: Vec::new()

0 commit comments

Comments
 (0)