lightningdevkit / rust-lightning

A highly modular Bitcoin Lightning library written in Rust. It's rust-lightning, not Rusty's Lightning!
Other
1.16k stars 367 forks source link

[Splicing] Signing utility for splicing #3312

Closed optout21 closed 1 month ago

optout21 commented 2 months ago

This is in preparation for Splicing (#1621 )

In splicing the channel has to sign the previous funding as an input to the new funding transactions. For this, the EcdsaChannelSigner trait has to be extended.

The proposed solution is visible in #3274, the EcdsaChannelSigner trait has been extended with this method:

    /// 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>
    ) -> Result<Signature, ()>;

with the implementation:

    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()[..];
        let msg = hash_to_message!(sighash);
        let sig = sign(secp_ctx, &msg, &self.funding_key);
        Ok(sig)
    }

(files src/sign/mod.rs src/sign/ecdsa.rs src/ln/channel.rs)