Skip to content

Commit

Permalink
A draft implementation of SIGHASH_NOINPUT
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Aug 2, 2015
1 parent 86cfd23 commit 4b3c3f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,15 @@ class CTransactionSignatureSerializer {
const CScript &scriptCode; //! output script being consumed
const unsigned int nIn; //! input index of txTo being signed
const bool fAnyoneCanPay; //! whether the hashtype has the SIGHASH_ANYONECANPAY flag set
const bool fNoInput; //! whether the hashtype has the SIGHASH_NOINPUT flag set
const bool fHashSingle; //! whether the hashtype is SIGHASH_SINGLE
const bool fHashNone; //! whether the hashtype is SIGHASH_NONE

public:
CTransactionSignatureSerializer(const CTransaction &txToIn, const CScript &scriptCodeIn, unsigned int nInIn, int nHashTypeIn) :
txTo(txToIn), scriptCode(scriptCodeIn), nIn(nInIn),
fAnyoneCanPay(!!(nHashTypeIn & SIGHASH_ANYONECANPAY)),
fNoInput(!!(nHashTypeIn & SIGHASH_NOINPUT)),
fHashSingle((nHashTypeIn & 0x1f) == SIGHASH_SINGLE),
fHashNone((nHashTypeIn & 0x1f) == SIGHASH_NONE) {}

Expand Down Expand Up @@ -1027,8 +1029,13 @@ class CTransactionSignatureSerializer {
// In case of SIGHASH_ANYONECANPAY, only the input being signed is serialized
if (fAnyoneCanPay)
nInput = nIn;
// Serialize the prevout
::Serialize(s, txTo.vin[nInput].prevout, nType, nVersion);
// If using SIGHASH_NOINPUT, the prevout is not included under the signature
if (fNoInput)
// Serialize a "NULL" prevout: 00000000000000000000000000000000:4294967295
::Serialize(s, COutPoint(), nType, nVersion);
else
// Serialize the prevout
::Serialize(s, txTo.vin[nInput].prevout, nType, nVersion);
// Serialize the script
if (nInput != nIn)
// Blank out other inputs' signatures
Expand Down
1 change: 1 addition & 0 deletions src/script/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum
SIGHASH_ALL = 1,
SIGHASH_NONE = 2,
SIGHASH_SINGLE = 3,
SIGHASH_NOINPUT = 0x40,
SIGHASH_ANYONECANPAY = 0x80,
};

Expand Down

0 comments on commit 4b3c3f1

Please sign in to comment.