From a4e0e39f82db5a25cfa81b46f006405791124086 Mon Sep 17 00:00:00 2001 From: Jon Layton Date: Tue, 2 Oct 2018 17:13:32 -0500 Subject: [PATCH] [wallet] Add SIGHASH_FORKID where necessary, allowing raw transaction signing to succeed --- src/bitcoin-tx.cpp | 2 +- src/core_write.cpp | 12 ++++++------ src/rpc/rawtransaction.cpp | 16 ++++++++-------- src/script/sign.h | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 3fb505d73..dc3cc7ad4 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -633,7 +633,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) const CKeyStore& keystore = tempKeystore; - bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE); + bool fHashSingle = ((nHashType & ~(SIGHASH_ANYONECANPAY|SIGHASH_FORKID)) == SIGHASH_SINGLE); // Sign what we can: for (unsigned int i = 0; i < mergedTx.vin.size(); i++) { diff --git a/src/core_write.cpp b/src/core_write.cpp index ee6737201..59fb17a4a 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -62,12 +62,12 @@ std::string FormatScript(const CScript& script) } const std::map mapSigHashTypes = { - {static_cast(SIGHASH_ALL), std::string("ALL")}, - {static_cast(SIGHASH_ALL|SIGHASH_ANYONECANPAY), std::string("ALL|ANYONECANPAY")}, - {static_cast(SIGHASH_NONE), std::string("NONE")}, - {static_cast(SIGHASH_NONE|SIGHASH_ANYONECANPAY), std::string("NONE|ANYONECANPAY")}, - {static_cast(SIGHASH_SINGLE), std::string("SINGLE")}, - {static_cast(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")}, + {static_cast(SIGHASH_ALL|SIGHASH_FORKID), std::string("ALL|FORKID")}, + {static_cast(SIGHASH_ALL|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("ALL|ANYONECANPAY|FORKID")}, + {static_cast(SIGHASH_NONE|SIGHASH_FORKID), std::string("NONE|FORKID")}, + {static_cast(SIGHASH_NONE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("NONE|ANYONECANPAY|FORKID")}, + {static_cast(SIGHASH_SINGLE|SIGHASH_FORKID), std::string("SINGLE|FORKID")}, + {static_cast(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("SINGLE|ANYONECANPAY|FORKID")}, }; /** diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index ad2d55afe..45ec35d19 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -838,15 +838,15 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival } } - int nHashType = SIGHASH_ALL; + int nHashType = SIGHASH_ALL | SIGHASH_FORKID; if (!hashType.isNull()) { static std::map mapSigHashValues = { - {std::string("ALL"), int(SIGHASH_ALL)}, - {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, - {std::string("NONE"), int(SIGHASH_NONE)}, - {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, - {std::string("SINGLE"), int(SIGHASH_SINGLE)}, - {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, + {std::string("ALL|FORKID"), int(SIGHASH_ALL|SIGHASH_FORKID)}, + {std::string("ALL|ANYONECANPAY|FORKID"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)}, + {std::string("NONE|FORKID"), int(SIGHASH_NONE|SIGHASH_FORKID)}, + {std::string("NONE|ANYONECANPAY|FORKID"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)}, + {std::string("SINGLE|FORKID"), int(SIGHASH_SINGLE|SIGHASH_FORKID)}, + {std::string("SINGLE|ANYONECANPAY|FORKID"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)}, }; std::string strHashType = hashType.get_str(); if (mapSigHashValues.count(strHashType)) { @@ -856,7 +856,7 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival } } - bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE); + bool fHashSingle = ((nHashType & ~(SIGHASH_ANYONECANPAY|SIGHASH_FORKID)) == SIGHASH_SINGLE); // Script verification errors UniValue vErrors(UniValue::VARR); diff --git a/src/script/sign.h b/src/script/sign.h index 59b3fe790..d3b152cc9 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -45,7 +45,7 @@ class MutableTransactionSignatureCreator : public BaseSignatureCreator { const MutableTransactionSignatureChecker checker; public: - MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL|SIGHASH_FORKID); + MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL | SIGHASH_FORKID); const BaseSignatureChecker& Checker() const override { return checker; } bool CreateSig(const SigningProvider& provider, std::vector& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override; };