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.


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?


1 Answer 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);
        ::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):


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.

  • so, the short answer is: 9 bytes. ;>
    – dthorpe
    Commented Oct 28, 2014 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.