<p>Just in case someone struggles with the same issue, the code was actually incorrect. <a href="https://github.com/vbuterin/pybitcointools/pull/163" rel="nofollow noreferrer">Pull request #163</a> fixes the issue.</p>

<p><a href="https://github.com/sr-gi/bitcoin_tools/blob/dev/bitcoin_tools/transaction.py#L381-L444" rel="nofollow noreferrer">Here</a> you can also see an equivalent solution properly commented and cited.</p>

CC BY-SA 3.0
2017-06-27T11:06:31.883Z
2017-06-27T11:06:31.883Z
sr_gi
<p>Checking the implementation of Buterin's bitcoin tools I've noticed something strange. According to <a href="https://bitcoin.org/en/developer-guide#signature-hash-types" rel="nofollow noreferrer">the Bitcoin developers guide</a>, sighash_single signs only the outputs that match the input where the scriptSig is going to be placed, that is, input <code>i</code> should sign only output <code>i</code>. However, <a href="https://github.com/vbuterin/pybitcointools/blob/6db88d846d3dd0414f9064febd98d2553e14f953/bitcoin/transaction.py#L139" rel="nofollow noreferrer">the code</a> is always signing the current input with the last output of the transaction.</p>

<p>Is it a workaround to deal with a non-matching number of inputs and outputs, or I am missing something?</p>

<script><python><sighash-flags><pybitcointools>
SIGHASH_SINGLE vbuterin/pybitcointools
sr_gi
# SIGHASH_SINGLE vbuterin/pybitcointools

(Asked by: username_0 on 2017-02-03)

Checking the implementation of Buterin's bitcoin tools I've noticed something strange. According to [the Bitcoin developers guide](https://bitcoin.org/en/developer-guide#signature-hash-types), sighash\_single signs only the outputs that match the input where the scriptSig is going to be placed, that is, input `i` should sign only output `i`. However, [the code](https://github.com/vbuterin/pybitcointools/blob/6db88d846d3dd0414f9064febd98d2553e14f953/bitcoin/transaction.py#L139) is always signing the current input with the last output of the transaction.

Is it a workaround to deal with a non-matching number of inputs and outputs, or I am missing something?

**Tags:** script, python, sighash-flags, pybitcointools


---

## 1 answers

### Answer by username_0 on 2017-06-27. Score: 0 | Accepted answer

Just in case someone struggles with the same issue, the code was actually incorrect. [Pull request #163](https://github.com/vbuterin/pybitcointools/pull/163) fixes the issue.

[Here](https://github.com/sr-gi/bitcoin_tools/blob/dev/bitcoin_tools/transaction.py#L381-L444) you can also see an equivalent solution properly commented and cited.


---

