You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lightning/src/chain/keysinterface.rs
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
//! spendable on-chain outputs which the user owns and is responsible for using just as any other
12
12
//! on-chain output which is theirs.
13
13
14
-
use bitcoin::blockdata::transaction::{Transaction,TxOut};
14
+
use bitcoin::blockdata::transaction::{Transaction,TxOut,SigHashType};
15
15
use bitcoin::blockdata::script::{Script,Builder};
16
16
use bitcoin::blockdata::opcodes;
17
17
use bitcoin::network::constants::Network;
@@ -477,7 +477,7 @@ impl ChannelKeys for InMemoryChannelKeys {
477
477
let accepted_data = self.accepted_channel_data.as_ref().expect("must accept before signing");
478
478
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey,&accepted_data.remote_channel_pubkeys.funding_pubkey);
479
479
480
-
let commitment_sighash = hash_to_message!(&bip143::SighashComponents::new(&commitment_tx).sighash_all(&commitment_tx.input[0],&channel_funding_redeemscript,self.channel_value_satoshis)[..]);
480
+
let commitment_sighash = hash_to_message!(&bip143::SigHashCache::new(commitment_tx).signature_hash(0,&channel_funding_redeemscript,self.channel_value_satoshis,SigHashType::All)[..]);
481
481
let commitment_sig = secp_ctx.sign(&commitment_sighash,&self.funding_key);
482
482
483
483
let commitment_txid = commitment_tx.txid();
@@ -487,7 +487,7 @@ impl ChannelKeys for InMemoryChannelKeys {
487
487
ifletSome(_) = htlc.transaction_output_index{
488
488
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, feerate_per_kw, accepted_data.local_to_self_delay, htlc,&keys.a_delayed_payment_key,&keys.revocation_key);
489
489
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc,&keys);
490
-
let htlc_sighash = hash_to_message!(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0],&htlc_redeemscript, htlc.amount_msat / 1000)[..]);
490
+
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0,&htlc_redeemscript, htlc.amount_msat / 1000,SigHashType::All)[..]);
491
491
let our_htlc_key = match chan_utils::derive_private_key(&secp_ctx,&keys.per_commitment_point,&self.htlc_base_key){
492
492
Ok(s) => s,
493
493
Err(_) => returnErr(()),
@@ -548,8 +548,8 @@ impl ChannelKeys for InMemoryChannelKeys {
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0,&self.local_keys.a_htlc_key,&self.local_keys.b_htlc_key,&self.local_keys.revocation_key);
694
694
695
-
let sighash = hash_to_message!(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0],&htlc_redeemscript, this_htlc.0.amount_msat / 1000)[..]);
695
+
let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0,&htlc_redeemscript, this_htlc.0.amount_msat / 1000,SigHashType::All)[..]);
let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
1478
1478
let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number,&local_keys,true,false,self.feerate_per_kw, logger).0;
1479
-
let local_sighash = hash_to_message!(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0],&funding_script,self.channel_value_satoshis)[..]);
1479
+
let local_sighash = hash_to_message!(&bip143::SigHashCache::new(&local_initial_commitment_tx).signature_hash(0,&funding_script,self.channel_value_satoshis,SigHashType::All)[..]);
1480
1480
1481
1481
// They sign the "local" commitment transaction...
1482
1482
log_trace!(logger,"Checking funding_created tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}", log_bytes!(sig.serialize_compact()[..]), log_bytes!(self.their_funding_pubkey().serialize()), encode::serialize_hex(&local_initial_commitment_tx), log_bytes!(local_sighash[..]), encode::serialize_hex(&funding_script));
let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
1582
1582
let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number,&local_keys,true,false,self.feerate_per_kw, logger).0;
1583
-
let local_sighash = hash_to_message!(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0],&funding_script,self.channel_value_satoshis)[..]);
1583
+
let local_sighash = hash_to_message!(&bip143::SigHashCache::new(&local_initial_commitment_tx).signature_hash(0,&funding_script,self.channel_value_satoshis,SigHashType::All)[..]);
1584
1584
1585
1585
let their_funding_pubkey = &self.their_pubkeys.as_ref().unwrap().funding_pubkey;
let local_commitment_txid = local_commitment_tx.0.txid();
1984
-
let local_sighash = hash_to_message!(&bip143::SighashComponents::new(&local_commitment_tx.0).sighash_all(&local_commitment_tx.0.input[0],&funding_script,self.channel_value_satoshis)[..]);
1984
+
let local_sighash = hash_to_message!(&bip143::SigHashCache::new(&local_commitment_tx.0).signature_hash(0,&funding_script,self.channel_value_satoshis,SigHashType::All)[..]);
1985
1985
log_trace!(logger,"Checking commitment tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}", log_bytes!(msg.signature.serialize_compact()[..]), log_bytes!(self.their_funding_pubkey().serialize()), encode::serialize_hex(&local_commitment_tx.0), log_bytes!(local_sighash[..]), encode::serialize_hex(&funding_script));
returnErr(ChannelError::Close(format!("Remote sent us a closing_signed with a fee greater than the value they can claim. Fee in message: {}", msg.fee_satoshis)));
secp_check!(self.secp_ctx.verify(&sighash,&msg.signature,self.their_funding_pubkey()),"Invalid closing tx signature from peer".to_owned());
3029
3029
},
3030
3030
};
@@ -4453,7 +4453,7 @@ mod tests {
4453
4453
use bitcoin::util::bip143;
4454
4454
use bitcoin::consensus::encode::serialize;
4455
4455
use bitcoin::blockdata::script::{Script,Builder};
4456
-
use bitcoin::blockdata::transaction::{Transaction,TxOut};
4456
+
use bitcoin::blockdata::transaction::{Transaction,TxOut,SigHashType};
4457
4457
use bitcoin::blockdata::constants::genesis_block;
4458
4458
use bitcoin::blockdata::opcodes;
4459
4459
use bitcoin::network::constants::Network;
@@ -4691,7 +4691,7 @@ mod tests {
4691
4691
};
4692
4692
let redeemscript = chan.get_funding_redeemscript();
4693
4693
let their_signature = Signature::from_der(&hex::decode($their_sig_hex).unwrap()[..]).unwrap();
4694
-
let sighash = Message::from_slice(&bip143::SighashComponents::new(&unsigned_tx.0).sighash_all(&unsigned_tx.0.input[0],&redeemscript, chan.channel_value_satoshis)[..]).unwrap();
4694
+
let sighash = Message::from_slice(&bip143::SigHashCache::new(&unsigned_tx.0).signature_hash(0,&redeemscript, chan.channel_value_satoshis,SigHashType::All)[..]).unwrap();
let sighash_parts = bip143::SighashComponents::new(&claim_tx);
2760
2759
let inputs_des = vec![InputDescriptors::RevokedOutput,InputDescriptors::RevokedOfferedHTLC,InputDescriptors::RevokedOfferedHTLC,InputDescriptors::RevokedReceivedHTLC];
0 commit comments