From 81afee9ff2143ef890b80e7a467c26d4b1be98d2 Mon Sep 17 00:00:00 2001 From: Devrandom Date: Wed, 15 Jan 2020 11:11:13 -0800 Subject: [PATCH] move expensive checks to enforcing trait --- lightning/src/chain/keysinterface.rs | 11 ----------- lightning/src/util/enforcing_trait_impls.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 3e4cb612f..2f4454cf6 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -202,17 +202,6 @@ impl ChannelKeys for InMemoryChannelKeys { if commitment_tx.input.len() != 1 { return Err(()); } if commitment_tx.output.len() != redeem_scripts.len() { return Err(()); } - for (out, redeem_script) in commitment_tx.output.iter().zip(redeem_scripts.iter()) { - if out.script_pubkey.is_v0_p2wpkh() { - if !redeem_script.is_empty() { - return Err(()) - } - } else { - if out.script_pubkey != redeem_script.to_v0_p2wsh() { - return Err(()) - } - } - } let commitment_sighash = hash_to_message!(&bip143::SighashComponents::new(&commitment_tx).sighash_all(&commitment_tx.input[0], &channel_funding_redeemscript, channel_value_satoshis)[..]); let commitment_sig = secp_ctx.sign(&commitment_sighash, &self.funding_key); diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index 39905b413..4653e3cd2 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -39,6 +39,18 @@ impl ChannelKeys for EnforcingChannelKeys { if commitment_tx.input.len() != 1 { panic!(); } if commitment_tx.output.len() != redeem_scripts.len() { panic!(); } + for (out, redeem_script) in commitment_tx.output.iter().zip(redeem_scripts.iter()) { + if out.script_pubkey.is_v0_p2wpkh() { + if !redeem_script.is_empty() { + return Err(()) + } + } else { + if out.script_pubkey != redeem_script.to_v0_p2wsh() { + return Err(()) + } + } + } + let obscured_commitment_transaction_number = (commitment_tx.lock_time & 0xffffff) as u64 | ((commitment_tx.input[0].sequence as u64 & 0xffffff) << 3*8); { -- 2.39.5