@@ -217,32 +217,33 @@ pub fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_com
217
217
218
218
/// Derives a per-commitment-transaction revocation key from its constituent parts.
219
219
///
220
+ /// Only the cheating participant owns a valid witness to propagate a revoked
221
+ /// commitment transaction, thus per_commitment_secret always come from cheater
222
+ /// and revocation_base_secret always come from punisher, which is the broadcaster
223
+ /// of the transaction spending with this key knowledge.
224
+ ///
220
225
/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
221
226
/// generated (ie our own).
222
- pub fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , SecpError > {
223
- let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret ) ;
227
+ pub fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , countersignatory_revocation_base_secret : & SecretKey ) -> Result < SecretKey , SecpError > {
228
+ let countersignatory_revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & countersignatory_revocation_base_secret ) ;
224
229
let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
225
230
226
231
let rev_append_commit_hash_key = {
227
232
let mut sha = Sha256 :: engine ( ) ;
228
- sha. input ( & revocation_base_point . serialize ( ) ) ;
233
+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
229
234
sha. input ( & per_commitment_point. serialize ( ) ) ;
230
235
231
236
Sha256 :: from_engine ( sha) . into_inner ( )
232
237
} ;
233
238
let commit_append_rev_hash_key = {
234
239
let mut sha = Sha256 :: engine ( ) ;
235
240
sha. input ( & per_commitment_point. serialize ( ) ) ;
236
- sha. input ( & revocation_base_point . serialize ( ) ) ;
241
+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
237
242
238
243
Sha256 :: from_engine ( sha) . into_inner ( )
239
244
} ;
240
245
241
- // Only the transaction broadcaster owns a valid witness to propagate
242
- // a revoked commitment transaction, thus per_commitment_secret always
243
- // come from broadcaster and revocation_base_secret always come
244
- // from countersignatory of the transaction.
245
- let mut countersignatory_contrib = revocation_base_secret. clone ( ) ;
246
+ let mut countersignatory_contrib = countersignatory_revocation_base_secret. clone ( ) ;
246
247
countersignatory_contrib. mul_assign ( & rev_append_commit_hash_key) ?;
247
248
let mut broadcaster_contrib = per_commitment_secret. clone ( ) ;
248
249
broadcaster_contrib. mul_assign ( & commit_append_rev_hash_key) ?;
@@ -254,29 +255,30 @@ pub fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1
254
255
/// the public equivalend of derive_private_revocation_key - using only public keys to derive a
255
256
/// public key instead of private keys.
256
257
///
258
+ /// Only the cheating participant owns a valid witness to propagate a revoked
259
+ /// commitment transaction, thus per_commitment_point always come from cheater
260
+ /// and revocation_base_point always come from punisher, which is the broadcaster
261
+ /// of the transaction spending with this key knowledge.
262
+ ///
257
263
/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
258
264
/// generated (ie our own).
259
- pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , SecpError > {
265
+ pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , countersignatory_revocation_base_point : & PublicKey ) -> Result < PublicKey , SecpError > {
260
266
let rev_append_commit_hash_key = {
261
267
let mut sha = Sha256 :: engine ( ) ;
262
- sha. input ( & revocation_base_point . serialize ( ) ) ;
268
+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
263
269
sha. input ( & per_commitment_point. serialize ( ) ) ;
264
270
265
271
Sha256 :: from_engine ( sha) . into_inner ( )
266
272
} ;
267
273
let commit_append_rev_hash_key = {
268
274
let mut sha = Sha256 :: engine ( ) ;
269
275
sha. input ( & per_commitment_point. serialize ( ) ) ;
270
- sha. input ( & revocation_base_point . serialize ( ) ) ;
276
+ sha. input ( & countersignatory_revocation_base_point . serialize ( ) ) ;
271
277
272
278
Sha256 :: from_engine ( sha) . into_inner ( )
273
279
} ;
274
280
275
- // Only the transaction broadcaster owns a valid witness to propagate
276
- // a revoked commitment transaction, thus per_commitment_point always
277
- // come from broadcaster and revocation_base_point always come
278
- // from countersignatory of the transaction.
279
- let mut countersignatory_contrib = revocation_base_point. clone ( ) ;
281
+ let mut countersignatory_contrib = countersignatory_revocation_base_point. clone ( ) ;
280
282
countersignatory_contrib. mul_assign ( & secp_ctx, & rev_append_commit_hash_key) ?;
281
283
let mut broadcaster_contrib = per_commitment_point. clone ( ) ;
282
284
broadcaster_contrib. mul_assign ( & secp_ctx, & commit_append_rev_hash_key) ?;
@@ -298,7 +300,7 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
298
300
pub struct TxCreationKeys {
299
301
/// The broadcaster's per-commitment public key which was used to derive the other keys.
300
302
pub per_commitment_point : PublicKey ,
301
- /// The broadcaster's revocation key which is used to allow the broadcaster of the commitment
303
+ /// The revocation key which is used to allow the broadcaster of the commitment
302
304
/// transaction to provide their counterparty the ability to punish them if they broadcast
303
305
/// an old state.
304
306
pub revocation_key : PublicKey ,
@@ -307,10 +309,10 @@ pub struct TxCreationKeys {
307
309
/// Countersignatory's HTLC Key
308
310
pub countersignatory_htlc_key : PublicKey ,
309
311
/// Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
310
- pub delayed_payment_key : PublicKey ,
312
+ pub broadcaster_delayed_payment_key : PublicKey ,
311
313
}
312
314
impl_writeable ! ( TxCreationKeys , 33 * 6 ,
313
- { per_commitment_point, revocation_key, broadcaster_htlc_key, countersignatory_htlc_key, delayed_payment_key } ) ;
315
+ { per_commitment_point, revocation_key, broadcaster_htlc_key, countersignatory_htlc_key, broadcaster_delayed_payment_key } ) ;
314
316
315
317
/// The per-commitment point and a set of pre-calculated public keys used for transaction creation
316
318
/// in the signer.
@@ -377,22 +379,22 @@ impl TxCreationKeys {
377
379
revocation_key : derive_public_revocation_key ( & secp_ctx, & per_commitment_point, & countersignatory_revocation_base) ?,
378
380
broadcaster_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_htlc_base) ?,
379
381
countersignatory_htlc_key : derive_public_key ( & secp_ctx, & per_commitment_point, & countersignatory_htlc_base) ?,
380
- delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_delayed_payment_base) ?,
382
+ broadcaster_delayed_payment_key : derive_public_key ( & secp_ctx, & per_commitment_point, & broadcaster_delayed_payment_base) ?,
381
383
} )
382
384
}
383
385
}
384
386
385
387
/// A script either spendable by the revocation
386
- /// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
388
+ /// key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
387
389
/// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions.
388
- pub fn get_revokeable_redeemscript ( revocation_key : & PublicKey , contest_delay : u16 , delayed_payment_key : & PublicKey ) -> Script {
390
+ pub fn get_revokeable_redeemscript ( revocation_key : & PublicKey , contest_delay : u16 , broadcaster_delayed_payment_key : & PublicKey ) -> Script {
389
391
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_IF )
390
392
. push_slice ( & revocation_key. serialize ( ) )
391
393
. push_opcode ( opcodes:: all:: OP_ELSE )
392
394
. push_int ( contest_delay as i64 )
393
395
. push_opcode ( opcodes:: all:: OP_CSV )
394
396
. push_opcode ( opcodes:: all:: OP_DROP )
395
- . push_slice ( & delayed_payment_key . serialize ( ) )
397
+ . push_slice ( & broadcaster_delayed_payment_key . serialize ( ) )
396
398
. push_opcode ( opcodes:: all:: OP_ENDIF )
397
399
. push_opcode ( opcodes:: all:: OP_CHECKSIG )
398
400
. into_script ( )
@@ -516,7 +518,7 @@ pub fn make_funding_redeemscript(broadcaster: &PublicKey, countersignatory: &Pub
516
518
}
517
519
518
520
/// panics if htlc.transaction_output_index.is_none()!
519
- pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u32 , contest_delay : u16 , htlc : & HTLCOutputInCommitment , delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
521
+ pub fn build_htlc_transaction ( prev_hash : & Txid , feerate_per_kw : u32 , contest_delay : u16 , htlc : & HTLCOutputInCommitment , broadcaster_delayed_payment_key : & PublicKey , revocation_key : & PublicKey ) -> Transaction {
520
522
let mut txins: Vec < TxIn > = Vec :: new ( ) ;
521
523
txins. push ( TxIn {
522
524
previous_output : OutPoint {
@@ -536,7 +538,7 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
536
538
537
539
let mut txouts: Vec < TxOut > = Vec :: new ( ) ;
538
540
txouts. push ( TxOut {
539
- script_pubkey : get_revokeable_redeemscript ( revocation_key, contest_delay, delayed_payment_key ) . to_v0_p2wsh ( ) ,
541
+ script_pubkey : get_revokeable_redeemscript ( revocation_key, contest_delay, broadcaster_delayed_payment_key ) . to_v0_p2wsh ( ) ,
540
542
value : htlc. amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
541
543
} ) ;
542
544
@@ -605,7 +607,7 @@ impl LocalCommitmentTransaction {
605
607
revocation_key : dummy_key. clone ( ) ,
606
608
broadcaster_htlc_key : dummy_key. clone ( ) ,
607
609
countersignatory_htlc_key : dummy_key. clone ( ) ,
608
- delayed_payment_key : dummy_key. clone ( ) ,
610
+ broadcaster_delayed_payment_key : dummy_key. clone ( ) ,
609
611
} ,
610
612
feerate_per_kw : 0 ,
611
613
per_htlc : Vec :: new ( )
@@ -701,7 +703,7 @@ impl LocalCommitmentTransaction {
701
703
702
704
for this_htlc in self . per_htlc . iter ( ) {
703
705
if this_htlc. 0 . transaction_output_index . is_some ( ) {
704
- let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . delayed_payment_key , & self . local_keys . revocation_key ) ;
706
+ let htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . broadcaster_delayed_payment_key , & self . local_keys . revocation_key ) ;
705
707
706
708
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys ( & this_htlc. 0 , & self . local_keys . broadcaster_htlc_key , & self . local_keys . countersignatory_htlc_key , & self . local_keys . revocation_key ) ;
707
709
@@ -724,7 +726,7 @@ impl LocalCommitmentTransaction {
724
726
// Further, we should never be provided the preimage for an HTLC-Timeout transaction.
725
727
if this_htlc. 0 . offered && preimage. is_some ( ) { unreachable ! ( ) ; }
726
728
727
- let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . delayed_payment_key , & self . local_keys . revocation_key ) ;
729
+ let mut htlc_tx = build_htlc_transaction ( & txid, self . feerate_per_kw , local_csv, & this_htlc. 0 , & self . local_keys . broadcaster_delayed_payment_key , & self . local_keys . revocation_key ) ;
728
730
// Channel should have checked that we have a remote signature for this HTLC at
729
731
// creation, and we should have a sensible htlc transaction:
730
732
assert ! ( this_htlc. 1 . is_some( ) ) ;
0 commit comments