Skip to content

Commit 95217d6

Browse files
committed
Revocation Key
1 parent d8e0a62 commit 95217d6

File tree

6 files changed

+137
-95
lines changed

6 files changed

+137
-95
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use bitcoin::{secp256k1, EcdsaSighashType};
3535
use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
3636
use crate::ln::{PaymentHash, PaymentPreimage};
3737
use crate::ln::msgs::DecodeError;
38-
use crate::ln::channel_keys::{DelayedPaymentKey, DelayedPaymentBasepoint, HtlcBasepoint};
38+
use crate::ln::channel_keys::{DelayedPaymentKey, DelayedPaymentBasepoint, HtlcBasepoint, HtlcKey, RevocationKey, RevocationBasepoint};
3939
use crate::ln::chan_utils::{self,CommitmentTransaction, CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLCClaim, ChannelTransactionParameters, HolderCommitmentTransaction, TxCreationKeys};
4040
use crate::ln::channelmanager::{HTLCSource, SentHTLCId};
4141
use crate::chain;
@@ -237,9 +237,9 @@ pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_
237237
struct HolderSignedTx {
238238
/// txid of the transaction in tx, just used to make comparison faster
239239
txid: Txid,
240-
revocation_key: PublicKey,
241-
a_htlc_key: PublicKey,
242-
b_htlc_key: PublicKey,
240+
revocation_key: RevocationKey,
241+
a_htlc_key: HtlcKey,
242+
b_htlc_key: HtlcKey,
243243
delayed_payment_key: DelayedPaymentKey,
244244
per_commitment_point: PublicKey,
245245
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
@@ -751,12 +751,12 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
751751
commitment_transaction_number_obscure_factor: u64,
752752

753753
destination_script: Script,
754-
broadcasted_holder_revokable_script: Option<(Script, PublicKey, PublicKey)>,
754+
broadcasted_holder_revokable_script: Option<(Script, PublicKey, RevocationKey)>,
755755
counterparty_payment_script: Script,
756756
shutdown_script: Option<Script>,
757757

758758
channel_keys_id: [u8; 32],
759-
holder_revocation_basepoint: PublicKey,
759+
holder_revocation_basepoint: RevocationBasepoint,
760760
funding_info: (OutPoint, Script),
761761
current_counterparty_commitment_txid: Option<Txid>,
762762
prev_counterparty_commitment_txid: Option<Txid>,
@@ -1162,8 +1162,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
11621162
let holder_commitment_tx = HolderSignedTx {
11631163
txid,
11641164
revocation_key: tx_keys.revocation_key,
1165-
a_htlc_key: tx_keys.broadcaster_htlc_key.to_public_key(),
1166-
b_htlc_key: tx_keys.countersignatory_htlc_key.to_public_key(),
1165+
a_htlc_key: tx_keys.broadcaster_htlc_key,
1166+
b_htlc_key: tx_keys.countersignatory_htlc_key,
11671167
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
11681168
per_commitment_point: tx_keys.per_commitment_point,
11691169
htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
@@ -2493,8 +2493,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24932493
let mut new_holder_commitment_tx = HolderSignedTx {
24942494
txid,
24952495
revocation_key: tx_keys.revocation_key,
2496-
a_htlc_key: tx_keys.broadcaster_htlc_key.to_public_key(),
2497-
b_htlc_key: tx_keys.countersignatory_htlc_key.to_public_key(),
2496+
a_htlc_key: tx_keys.broadcaster_htlc_key,
2497+
b_htlc_key: tx_keys.countersignatory_htlc_key,
24982498
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
24992499
per_commitment_point: tx_keys.per_commitment_point,
25002500
htlc_outputs,
@@ -2923,9 +2923,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29232923
let their_per_commitment_point = PublicKey::from_secret_key(
29242924
&self.onchain_tx_handler.secp_ctx, &per_commitment_key);
29252925

2926-
let revocation_pubkey = chan_utils::derive_public_revocation_key(
2927-
&self.onchain_tx_handler.secp_ctx, &their_per_commitment_point,
2928-
&self.holder_revocation_basepoint);
2926+
let revocation_pubkey = RevocationKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,
2927+
&RevocationBasepoint::from(self.holder_revocation_basepoint),
2928+
&their_per_commitment_point);
29292929
let delayed_payment_basepoint = DelayedPaymentBasepoint::from(self.counterparty_commitment_params.counterparty_delayed_payment_base_key);
29302930
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx,
29312931
&delayed_payment_basepoint,
@@ -2992,7 +2992,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29922992
let secret = self.get_secret(commitment_number).unwrap();
29932993
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
29942994
let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key);
2995-
let revocation_pubkey = chan_utils::derive_public_revocation_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint);
2995+
let revocation_pubkey = RevocationKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.holder_revocation_basepoint, &per_commitment_point,);
29962996
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.counterparty_commitment_params.counterparty_delayed_payment_base_key, &PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key));
29972997

29982998
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
@@ -3105,8 +3105,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31053105
} else { return (claimable_outpoints, to_counterparty_output_info); };
31063106

31073107
if let Some(transaction) = tx {
3108-
let revocation_pubkey = chan_utils::derive_public_revocation_key(
3109-
&self.onchain_tx_handler.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint);
3108+
let revocation_pubkey = RevocationKey::from_basepoint(
3109+
&self.onchain_tx_handler.secp_ctx, &self.holder_revocation_basepoint, &per_commitment_point);
31103110

31113111
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.counterparty_commitment_params.counterparty_delayed_payment_base_key, &per_commitment_point);
31123112

@@ -3204,7 +3204,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32043204
// Returns (1) `PackageTemplate`s that can be given to the OnchainTxHandler, so that the handler can
32053205
// broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable
32063206
// script so we can detect whether a holder transaction has been seen on-chain.
3207-
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, conf_height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, PublicKey)>) {
3207+
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, conf_height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, RevocationKey)>) {
32083208
let mut claim_requests = Vec::with_capacity(holder_tx.htlc_outputs.len());
32093209

32103210
let redeemscript = chan_utils::get_revokeable_redeemscript(&holder_tx.revocation_key, self.on_holder_tx_csv, &holder_tx.delayed_payment_key);
@@ -4093,7 +4093,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40934093
per_commitment_point: broadcasted_holder_revokable_script.1,
40944094
to_self_delay: self.on_holder_tx_csv,
40954095
output: outp.clone(),
4096-
revocation_pubkey: broadcasted_holder_revokable_script.2.clone(),
4096+
revocation_pubkey: broadcasted_holder_revokable_script.2,
40974097
channel_keys_id: self.channel_keys_id,
40984098
channel_value_satoshis: self.channel_value_satoshis,
40994099
}));
@@ -4505,7 +4505,7 @@ mod tests {
45054505
use crate::chain::transaction::OutPoint;
45064506
use crate::sign::InMemorySigner;
45074507
use crate::ln::{PaymentPreimage, PaymentHash};
4508-
use crate::ln::channel_keys::{DelayedPaymentBasepoint, DelayedPaymentKey, HtlcBasepoint};
4508+
use crate::ln::channel_keys::{DelayedPaymentBasepoint, DelayedPaymentKey, HtlcBasepoint, RevocationBasepoint, RevocationKey};
45094509
use crate::ln::chan_utils::{self,HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
45104510
use crate::ln::channelmanager::{PaymentSendFailure, PaymentId, RecipientOnionFields};
45114511
use crate::ln::functional_test_utils::*;
@@ -4672,7 +4672,7 @@ mod tests {
46724672

46734673
let counterparty_pubkeys = ChannelPublicKeys {
46744674
funding_pubkey: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
4675-
revocation_basepoint: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap()),
4675+
revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
46764676
payment_point: PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
46774677
delayed_payment_basepoint: DelayedPaymentBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[47; 32]).unwrap())),
46784678
htlc_basepoint: HtlcBasepoint::from(PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[48; 32]).unwrap()))
@@ -4775,7 +4775,7 @@ mod tests {
47754775
payment_hash: PaymentHash([1; 32]),
47764776
transaction_output_index: Some($idx as u32),
47774777
};
4778-
let redeem_script = if *$weight == WEIGHT_REVOKED_OUTPUT { chan_utils::get_revokeable_redeemscript(&pubkey, 256, &DelayedPaymentKey::from_basepoint(&secp_ctx, &DelayedPaymentBasepoint::from(pubkey), &pubkey)) } else { chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, $opt_anchors, &HtlcKey::from_basepoint(&secp_ctx, &HtlcBasepoint::from(pubkey), &pubkey), &HtlcKey::from_basepoint(&secp_ctx, &HtlcBasepoint::from(pubkey), &pubkey), &pubkey) };
4778+
let redeem_script = if *$weight == WEIGHT_REVOKED_OUTPUT { chan_utils::get_revokeable_redeemscript(&RevocationKey::from_basepoint(&secp_ctx, &RevocationBasepoint::from(pubkey), &pubkey), 256, &DelayedPaymentKey::from_basepoint(&secp_ctx, &DelayedPaymentBasepoint::from(pubkey), &pubkey)) } else { chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, $opt_anchors, &HtlcKey::from_basepoint(&secp_ctx, &HtlcBasepoint::from(pubkey), &pubkey), &HtlcKey::from_basepoint(&secp_ctx, &HtlcBasepoint::from(pubkey), &pubkey), &RevocationKey::from_basepoint(&secp_ctx, &RevocationBasepoint::from(pubkey), &pubkey)) };
47794779
let sighash = hash_to_message!(&$sighash_parts.segwit_signature_hash($idx, &redeem_script, $amount, EcdsaSighashType::All).unwrap()[..]);
47804780
let sig = secp_ctx.sign_ecdsa(&sighash, &privkey);
47814781
let mut ser_sig = sig.serialize_der().to_vec();

lightning/src/chain/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl PackageSolvingData {
599599
let mut ser_sig = sig.serialize_der().to_vec();
600600
ser_sig.push(EcdsaSighashType::All as u8);
601601
bumped_tx.input[i].witness.push(ser_sig);
602-
bumped_tx.input[i].witness.push(chan_keys.revocation_key.clone().serialize().to_vec());
602+
bumped_tx.input[i].witness.push(chan_keys.revocation_key.to_public_key().serialize().to_vec());
603603
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
604604
} else { return false; }
605605
},

0 commit comments

Comments
 (0)