From: Devrandom Date: Wed, 15 Jan 2020 19:11:13 +0000 (-0800) Subject: move expensive checks to enforcing trait X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=81afee9ff2143ef890b80e7a467c26d4b1be98d2;p=rust-lightning move expensive checks to enforcing trait --- 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); {