Skip to content

Commit 84e45f4

Browse files
authored
Merge pull request #174 from yuntai/201809-funding_created_sig
verify incoming sig first to fail earlier
2 parents 648a31b + b6cbcc9 commit 84e45f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ln/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,17 +1263,17 @@ impl Channel {
12631263
fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Signature), HandleError> {
12641264
let funding_script = self.get_funding_redeemscript();
12651265

1266-
let remote_keys = self.build_remote_transaction_keys()?;
1267-
let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false).0;
1268-
let remote_sighash = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
1269-
12701266
let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
12711267
let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false).0;
12721268
let local_sighash = Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
12731269

12741270
// They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
12751271
secp_call!(self.secp_ctx.verify(&local_sighash, &sig, &self.their_funding_pubkey.unwrap()), "Invalid funding_created signature from peer", self.channel_id());
12761272

1273+
let remote_keys = self.build_remote_transaction_keys()?;
1274+
let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false).0;
1275+
let remote_sighash = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
1276+
12771277
// We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
12781278
Ok((remote_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key)))
12791279
}

0 commit comments

Comments
 (0)