changeset 3327:71eb723dde0e draft

When using SIGHASH_SINGLE, do not sign inputs that have no corresponding outputs. This fixes issue #1688
author Gavin Andresen <gavinandresen@gmail.com>
date Mon, 20 Aug 2012 14:06:27 -0400
parents f662dd42eefc
children 0481be91a53c
files src/rpcrawtransaction.cpp
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/rpcrawtransaction.cpp
+++ b/src/rpcrawtransaction.cpp
@@ -428,6 +428,8 @@
             throw JSONRPCError(-8, "Invalid sighash param");
     }
 
+    bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
+
     // Sign what we can:
     for (unsigned int i = 0; i < mergedTx.vin.size(); i++)
     {
@@ -440,7 +442,9 @@
         const CScript& prevPubKey = mapPrevOut[txin.prevout];
 
         txin.scriptSig.clear();
-        SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
+        // Only sign SIGHASH_SINGLE if there's a corresponding output:
+        if (!fHashSingle || (i < mergedTx.vout.size()))
+            SignSignature(keystore, prevPubKey, mergedTx, i, nHashType);
 
         // ... and merge in other signatures:
         BOOST_FOREACH(const CTransaction& txv, txVariants)