Skip to content

Require static_remotekey #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions fuzz/src/full_stack.rs

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub enum SpendableOutputDescriptor {
/// The output which is referenced by the given outpoint
output: TxOut,
},
// TODO: Note that because key is now static and exactly what is provided by us, we should drop
// this in favor of StaticOutput:
/// An output to a P2WPKH, spendable exclusively by the given private key.
/// The witness in the spending input, is, thus, simply:
/// <BIP 143 signature generated with the given key> <public key derived from the given key>
Expand Down Expand Up @@ -194,9 +196,10 @@ pub trait ChannelKeys : Send+Clone {
fn funding_key<'a>(&'a self) -> &'a SecretKey;
/// 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 to_remote output of remote commitment tx
/// (and also as part of obscured commitment number)
fn payment_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
Expand Down Expand Up @@ -273,8 +276,8 @@ pub struct InMemoryChannelKeys {
funding_key: SecretKey,
/// Local secret key for blinded revocation pubkey
revocation_base_key: SecretKey,
/// Local secret key used in commitment tx htlc outputs
payment_base_key: SecretKey,
/// Local secret key used for our balance in remote-broadcasted commitment transactions
payment_key: SecretKey,
/// Local secret key used in HTLC tx
delayed_payment_base_key: SecretKey,
/// Local htlc secret key used in commitment tx htlc outputs
Expand All @@ -295,19 +298,19 @@ impl InMemoryChannelKeys {
secp_ctx: &Secp256k1<C>,
funding_key: SecretKey,
revocation_base_key: SecretKey,
payment_base_key: SecretKey,
payment_key: SecretKey,
delayed_payment_base_key: SecretKey,
htlc_base_key: SecretKey,
commitment_seed: [u8; 32],
channel_value_satoshis: u64) -> InMemoryChannelKeys {
let local_channel_pubkeys =
InMemoryChannelKeys::make_local_keys(secp_ctx, &funding_key, &revocation_base_key,
&payment_base_key, &delayed_payment_base_key,
&payment_key, &delayed_payment_base_key,
&htlc_base_key);
InMemoryChannelKeys {
funding_key,
revocation_base_key,
payment_base_key,
payment_key,
delayed_payment_base_key,
htlc_base_key,
commitment_seed,
Expand All @@ -320,14 +323,14 @@ impl InMemoryChannelKeys {
fn make_local_keys<C: Signing>(secp_ctx: &Secp256k1<C>,
funding_key: &SecretKey,
revocation_base_key: &SecretKey,
payment_base_key: &SecretKey,
payment_key: &SecretKey,
delayed_payment_base_key: &SecretKey,
htlc_base_key: &SecretKey) -> ChannelPublicKeys {
let from_secret = |s: &SecretKey| PublicKey::from_secret_key(secp_ctx, s);
ChannelPublicKeys {
funding_pubkey: from_secret(&funding_key),
revocation_basepoint: from_secret(&revocation_base_key),
payment_basepoint: from_secret(&payment_base_key),
payment_point: from_secret(&payment_key),
delayed_payment_basepoint: from_secret(&delayed_payment_base_key),
htlc_basepoint: from_secret(&htlc_base_key),
}
Expand All @@ -337,7 +340,7 @@ impl InMemoryChannelKeys {
impl ChannelKeys for InMemoryChannelKeys {
fn funding_key(&self) -> &SecretKey { &self.funding_key }
fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
fn payment_base_key(&self) -> &SecretKey { &self.payment_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 }
Expand Down Expand Up @@ -422,7 +425,7 @@ impl Writeable for InMemoryChannelKeys {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
self.funding_key.write(writer)?;
self.revocation_base_key.write(writer)?;
self.payment_base_key.write(writer)?;
self.payment_key.write(writer)?;
self.delayed_payment_base_key.write(writer)?;
self.htlc_base_key.write(writer)?;
self.commitment_seed.write(writer)?;
Expand All @@ -437,7 +440,7 @@ impl Readable for InMemoryChannelKeys {
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
let funding_key = Readable::read(reader)?;
let revocation_base_key = Readable::read(reader)?;
let payment_base_key = Readable::read(reader)?;
let payment_key = Readable::read(reader)?;
let delayed_payment_base_key = Readable::read(reader)?;
let htlc_base_key = Readable::read(reader)?;
let commitment_seed = Readable::read(reader)?;
Expand All @@ -446,13 +449,13 @@ impl Readable for InMemoryChannelKeys {
let secp_ctx = Secp256k1::signing_only();
let local_channel_pubkeys =
InMemoryChannelKeys::make_local_keys(&secp_ctx, &funding_key, &revocation_base_key,
&payment_base_key, &delayed_payment_base_key,
&payment_key, &delayed_payment_base_key,
&htlc_base_key);

Ok(InMemoryChannelKeys {
funding_key,
revocation_base_key,
payment_base_key,
payment_key,
delayed_payment_base_key,
htlc_base_key,
commitment_seed,
Expand Down Expand Up @@ -598,15 +601,15 @@ impl KeysInterface for KeysManager {
}
let funding_key = key_step!(b"funding key", commitment_seed);
let revocation_base_key = key_step!(b"revocation base key", funding_key);
let payment_base_key = key_step!(b"payment base key", revocation_base_key);
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_base_key);
let payment_key = key_step!(b"payment key", revocation_base_key);
let delayed_payment_base_key = key_step!(b"delayed payment base key", payment_key);
let htlc_base_key = key_step!(b"HTLC base key", delayed_payment_base_key);

InMemoryChannelKeys::new(
&self.secp_ctx,
funding_key,
revocation_base_key,
payment_base_key,
payment_key,
delayed_payment_base_key,
htlc_base_key,
commitment_seed,
Expand Down
17 changes: 7 additions & 10 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,9 @@ pub struct TxCreationKeys {
pub(crate) b_htlc_key: PublicKey,
/// A's Payment Key (which isn't allowed to be spent from for some delay)
pub(crate) a_delayed_payment_key: PublicKey,
/// B's Payment Key
pub(crate) b_payment_key: PublicKey,
}
impl_writeable!(TxCreationKeys, 33*6,
{ per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key, b_payment_key });
{ per_commitment_point, revocation_key, a_htlc_key, b_htlc_key, a_delayed_payment_key });

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


impl TxCreationKeys {
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> {
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> {
Ok(TxCreationKeys {
per_commitment_point: per_commitment_point.clone(),
revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &b_revocation_base)?,
a_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_htlc_base)?,
b_htlc_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_htlc_base)?,
a_delayed_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &a_delayed_payment_base)?,
b_payment_key: derive_public_key(&secp_ctx, &per_commitment_point, &b_payment_base)?,
})
}
}
Expand Down Expand Up @@ -537,7 +535,6 @@ impl LocalCommitmentTransaction {
a_htlc_key: dummy_key.clone(),
b_htlc_key: dummy_key.clone(),
a_delayed_payment_key: dummy_key.clone(),
b_payment_key: dummy_key.clone(),
},
feerate_per_kw: 0,
per_htlc: Vec::new()
Expand Down
Loading