From 7f14f9b40d79f4ca08cb1b1500d43d92559c6544 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 23 Aug 2017 13:48:49 +0300 Subject: [PATCH] uahf: input_index check is back in SignatureHash --- network/src/consensus.rs | 1 - script/src/sign.rs | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/network/src/consensus.rs b/network/src/consensus.rs index a25ed609..0daaa027 100644 --- a/network/src/consensus.rs +++ b/network/src/consensus.rs @@ -1,4 +1,3 @@ -use std::cmp::max; use hash::H256; use {Magic, Deployment}; diff --git a/script/src/sign.rs b/script/src/sign.rs index 1c738a5b..33453194 100644 --- a/script/src/sign.rs +++ b/script/src/sign.rs @@ -235,10 +235,6 @@ impl TransactionInputSigner { } fn signature_hash_witness0(&self, input_index: usize, input_amount: u64, script_pubkey: &Script, sighashtype: u32, sighash: Sighash) -> H256 { - self.signature_hash_fork_id(input_index, input_amount, script_pubkey, sighashtype, sighash) - } - - fn signature_hash_fork_id(&self, input_index: usize, input_amount: u64, script_pubkey: &Script, sighashtype: u32, sighash: Sighash) -> H256 { let hash_prevouts = compute_hash_prevouts(sighash, &self.inputs); let hash_sequence = compute_hash_sequence(sighash, &self.inputs); let hash_outputs = compute_hash_outputs(sighash, input_index, &self.outputs); @@ -257,6 +253,18 @@ impl TransactionInputSigner { let out = stream.out(); dhash256(&out) } + + fn signature_hash_fork_id(&self, input_index: usize, input_amount: u64, script_pubkey: &Script, sighashtype: u32, sighash: Sighash) -> H256 { + if input_index >= self.inputs.len() { + return 1u8.into(); + } + + if sighash.base == SighashBase::Single && input_index >= self.outputs.len() { + return 1u8.into(); + } + + self.signature_hash_witness0(input_index, input_amount, script_pubkey, sighashtype, sighash) + } } fn compute_hash_prevouts(sighash: Sighash, inputs: &[UnsignedTransactionInput]) -> H256 {