Skip to content

Commit

Permalink
Remove redeem_script from signing utility, it can derive it
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Sep 17, 2024
1 parent 05adf97 commit d8198d2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4286,11 +4286,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {

/// Create signature for the current funding tx input, used in the splicing case.
#[cfg(splicing)]
fn prev_funding_tx_create_holder_sig(&self, transaction: &Transaction, input_index: u16, input_value: u64, redeem_script: &ScriptBuf) -> Result<Signature, ChannelError> {
fn prev_funding_tx_create_holder_sig(&self, transaction: &Transaction, input_index: u16, input_value: u64/*, _redeem_script: &ScriptBuf*/) -> Result<Signature, ChannelError> {
// #SPLICE-SIG
match &self.holder_signer {
ChannelSignerType::Ecdsa(ecdsa) => {
ecdsa.sign_splicing_funding_input(transaction, input_index, input_value, &redeem_script, &self.secp_ctx)
ecdsa.sign_splicing_funding_input(transaction, input_index, input_value, /*&redeem_script, */&self.secp_ctx)
.map_err(|_e| ChannelError::Close("Failed to sign the previous funding input in the new splicing funding tx".to_owned()))
},
// TODO (taproot|arik)
Expand Down Expand Up @@ -4321,7 +4321,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
log_info!(logger, "Pubkeys used for redeem script: {} {} {}", &self.get_holder_pubkeys().funding_pubkey, &self.counterparty_funding_pubkey(), sig_order_ours_first);

let redeem_script = self.get_funding_redeemscript();
let holder_signature = self.prev_funding_tx_create_holder_sig(&transaction, prev_funding_input_index, pre_channel_value, &redeem_script)?;
let holder_signature = self.prev_funding_tx_create_holder_sig(&transaction, prev_funding_input_index, pre_channel_value)?; // , &redeem_script)?;
let mut holder_sig = holder_signature.serialize_der().to_vec();
holder_sig.push(EcdsaSighashType::All as u8);
// counterparty signature
Expand Down
3 changes: 1 addition & 2 deletions lightning/src/sign/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Defines ECDSA-specific signer types.

use bitcoin::Script;
use bitcoin::blockdata::transaction::Transaction;

use bitcoin::secp256k1;
Expand Down Expand Up @@ -215,7 +214,7 @@ pub trait EcdsaChannelSigner: ChannelSigner {
/// #SPLICING
/// Create a signature for a splicing funding transaction, for the input which is the previous funding tx.
fn sign_splicing_funding_input(
&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>
&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, /*redeem_script: &Script, */secp_ctx: &Secp256k1<secp256k1::All>
) -> Result<Signature, ()>;
}

Expand Down
7 changes: 5 additions & 2 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,8 +1675,11 @@ impl EcdsaChannelSigner for InMemorySigner {

/// #SPLICING
/// #SPLICE-SIG
fn sign_splicing_funding_input(&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
let sighash = &sighash::SighashCache::new(splicing_tx).segwit_signature_hash(splice_prev_funding_input_index as usize, &redeem_script, splice_prev_funding_input_value, EcdsaSighashType::All).unwrap()[..];
fn sign_splicing_funding_input(&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, /*_redeem_script0: &Script, */secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR);
let funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &counterparty_keys.funding_pubkey);
let sighash = &sighash::SighashCache::new(splicing_tx).segwit_signature_hash(splice_prev_funding_input_index as usize, &funding_redeemscript, splice_prev_funding_input_value, EcdsaSighashType::All).unwrap()[..];
let msg = hash_to_message!(sighash);
let sig = sign(secp_ctx, &msg, &self.funding_key);
Ok(sig)
Expand Down
5 changes: 2 additions & 3 deletions lightning/src/util/test_channel_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use core::cmp;
use crate::sync::{Mutex, Arc};
#[cfg(test)] use crate::sync::MutexGuard;

use bitcoin::Script;
use bitcoin::blockdata::transaction::Transaction;
use bitcoin::hashes::Hash;
use bitcoin::sighash;
Expand Down Expand Up @@ -297,8 +296,8 @@ impl EcdsaChannelSigner for TestChannelSigner {
self.inner.sign_channel_announcement_with_funding_key(msg, secp_ctx)
}

fn sign_splicing_funding_input(&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, redeem_script: &Script, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
self.inner.sign_splicing_funding_input(splicing_tx, splice_prev_funding_input_index, splice_prev_funding_input_value, redeem_script, secp_ctx)
fn sign_splicing_funding_input(&self, splicing_tx: &Transaction, splice_prev_funding_input_index: u16, splice_prev_funding_input_value: u64, /*redeem_script: &Script, */secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
self.inner.sign_splicing_funding_input(splicing_tx, splice_prev_funding_input_index, splice_prev_funding_input_value, /*redeem_script, */secp_ctx)
}
}

Expand Down

0 comments on commit d8198d2

Please sign in to comment.