<p>Transaction outputs have a "value" field that's an 8-byte signed integer (always 8 bytes) indicating how many satoshis (0.00000001 BTC each) are available for that output.  That is the thing that gets set to -1 on the other outputs in SIGHASH_SINGLE mode.</p>

<p>This looks to be the code responsible for making this happen, from script.cpp:</p>



<pre><code>/** Serialize an output of txTo */
template&lt;typename S&gt;
void SerializeOutput(S &amp;s, unsigned int nOutput, int nType, int nVersion) const {
    if (fHashSingle &amp;&amp; nOutput != nIn)
        // Do not lock-in the txout payee at other indices as txin
        ::Serialize(s, CTxOut(), nType, nVersion);
    else
        ::Serialize(s, txTo.vout[nOutput], nType, nVersion);
}
</code></pre>

<p>If we're in SIGHASH_SINGLE mode, and the index of the output is different from the index of the input, then the thing that we sign in this spot is just a dummy CTxOut object, whose parameterless constructor (in core.h) calls SetNull(), which sets the field called "nValue" to -1 (-0.00000001 BTC) and clears the scriptPubKey, which ensures that it's a 0-byte vector.</p>

<p>When CTxOut gets serialized, it writes the nValue and scriptPubKey per this (core.h again):</p>

<pre><code>IMPLEMENT_SERIALIZE
(
    READWRITE(nValue);
    READWRITE(scriptPubKey);
)
</code></pre>

<p>nValue serializes as the 8-byte twos-complement representation of -1, or 0xFFFFFFFFFFFFFFFF.
scriptPubKey serializes as a 1-byte CompactSize that indicates that the script is 0 bytes long, or 0x0.</p>

CC BY-SA 3.0
2014-10-28T00:10:54.340Z
so, the short answer is: 9 bytes.  ;>
dthorpe
CC BY-SA 3.0
2014-04-20T21:26:11.303Z
2014-04-20T21:26:11.303Z
Joe Amenta
<p>The bitcoin wiki says:</p>

<blockquote>
  <p>All other txCopy outputs aside from the output that is the same as the
  current input index are set to a blank script and a value of (long)
  -1.</p>
</blockquote>

<p><a href="https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_SINGLE" rel="nofollow">https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_SINGLE</a></p>

<p>It's hard finding what this means in the C++ client. Does it mean that the outputs, other than the output with the same index as the input being signed for, only have 8 bytes for the value or does it mean they also have another byte for the VarInt set to zero; 9 bytes in total?</p>

<p>Thanks.</p>

<transactions><protocol><development><signature>
For SIGHASH_SINGLE do the outputs other than at the input index, have 8 bytes or 9 bytes including a VarInt?
Matthew Mitchell
# For SIGHASH_SINGLE do the outputs other than at the input index, have 8 bytes or 9 bytes including a VarInt?

(Asked by: username_0 on 2012-06-04)

The bitcoin wiki says:

> All other txCopy outputs aside from the output that is the same as the
> current input index are set to a blank script and a value of (long)
> -1.

<https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_SINGLE>

It's hard finding what this means in the C++ client. Does it mean that the outputs, other than the output with the same index as the input being signed for, only have 8 bytes for the value or does it mean they also have another byte for the VarInt set to zero; 9 bytes in total?

Thanks.

**Tags:** transactions, protocol, development, signature


---

## 1 answers

### Answer by username_1 on 2014-04-20. Score: 1

Transaction outputs have a "value" field that's an 8-byte signed integer (always 8 bytes) indicating how many satoshis (0.00000001 BTC each) are available for that output. That is the thing that gets set to -1 on the other outputs in SIGHASH\_SINGLE mode.

This looks to be the code responsible for making this happen, from script.cpp:

```
/** Serialize an output of txTo */
template<typename S>
void SerializeOutput(S &s, unsigned int nOutput, int nType, int nVersion) const {
    if (fHashSingle && nOutput != nIn)
        // Do not lock-in the txout payee at other indices as txin
        ::Serialize(s, CTxOut(), nType, nVersion);
    else
        ::Serialize(s, txTo.vout[nOutput], nType, nVersion);
}

```

If we're in SIGHASH\_SINGLE mode, and the index of the output is different from the index of the input, then the thing that we sign in this spot is just a dummy CTxOut object, whose parameterless constructor (in core.h) calls SetNull(), which sets the field called "nValue" to -1 (-0.00000001 BTC) and clears the scriptPubKey, which ensures that it's a 0-byte vector.

When CTxOut gets serialized, it writes the nValue and scriptPubKey per this (core.h again):

```
IMPLEMENT_SERIALIZE
(
    READWRITE(nValue);
    READWRITE(scriptPubKey);
)

```

nValue serializes as the 8-byte twos-complement representation of -1, or 0xFFFFFFFFFFFFFFFF.
scriptPubKey serializes as a 1-byte CompactSize that indicates that the script is 0 bytes long, or 0x0.

> **Comments:**
> **username_2**: so, the short answer is: 9 bytes.  ;>  

---

