aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorJeremy Rubin <j@rubin.io>2020-02-05 12:31:20 -0800
committerJeremy Rubin <j@rubin.io>2020-08-07 11:08:40 -0700
commit9ab4cafabda227ccee5b241d7690fc67f9a27221 (patch)
treec0a4c4bd8aeaf77ad532f9dd14554d0f6417cda9 /src/script
parent6510d0ff4173a7b01d6728051303c7c38eb34533 (diff)
downloadbitcoin-9ab4cafabda227ccee5b241d7690fc67f9a27221.tar.xz
Refactor Get{Prevout,Sequence,Outputs}Hash to Get{Prevouts,Sequences,Outputs}SHA256.
Several proposals (Taproot, MuHash, CTV) require access to the single hash.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/interpreter.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
index 39feb4ccc9..7b2457a5e3 100644
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -1258,34 +1258,37 @@ public:
}
};
+/** Compute the (single) SHA256 of the concatenation of all prevouts of a tx. */
template <class T>
-uint256 GetPrevoutHash(const T& txTo)
+uint256 GetPrevoutsSHA256(const T& txTo)
{
CHashWriter ss(SER_GETHASH, 0);
for (const auto& txin : txTo.vin) {
ss << txin.prevout;
}
- return ss.GetHash();
+ return ss.GetSHA256();
}
+/** Compute the (single) SHA256 of the concatenation of all nSequences of a tx. */
template <class T>
-uint256 GetSequenceHash(const T& txTo)
+uint256 GetSequencesSHA256(const T& txTo)
{
CHashWriter ss(SER_GETHASH, 0);
for (const auto& txin : txTo.vin) {
ss << txin.nSequence;
}
- return ss.GetHash();
+ return ss.GetSHA256();
}
+/** Compute the (single) SHA256 of the concatenation of all txouts of a tx. */
template <class T>
-uint256 GetOutputsHash(const T& txTo)
+uint256 GetOutputsSHA256(const T& txTo)
{
CHashWriter ss(SER_GETHASH, 0);
for (const auto& txout : txTo.vout) {
ss << txout;
}
- return ss.GetHash();
+ return ss.GetSHA256();
}
} // namespace
@@ -1297,9 +1300,9 @@ void PrecomputedTransactionData::Init(const T& txTo)
// Cache is calculated only for transactions with witness
if (txTo.HasWitness()) {
- hashPrevouts = GetPrevoutHash(txTo);
- hashSequence = GetSequenceHash(txTo);
- hashOutputs = GetOutputsHash(txTo);
+ hashPrevouts = SHA256Uint256(GetPrevoutsSHA256(txTo));
+ hashSequence = SHA256Uint256(GetSequencesSHA256(txTo));
+ hashOutputs = SHA256Uint256(GetOutputsSHA256(txTo));
}
m_ready = true;
@@ -1329,16 +1332,16 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn
const bool cacheready = cache && cache->m_ready;
if (!(nHashType & SIGHASH_ANYONECANPAY)) {
- hashPrevouts = cacheready ? cache->hashPrevouts : GetPrevoutHash(txTo);
+ hashPrevouts = cacheready ? cache->hashPrevouts : SHA256Uint256(GetPrevoutsSHA256(txTo));
}
if (!(nHashType & SIGHASH_ANYONECANPAY) && (nHashType & 0x1f) != SIGHASH_SINGLE && (nHashType & 0x1f) != SIGHASH_NONE) {
- hashSequence = cacheready ? cache->hashSequence : GetSequenceHash(txTo);
+ hashSequence = cacheready ? cache->hashSequence : SHA256Uint256(GetSequencesSHA256(txTo));
}
if ((nHashType & 0x1f) != SIGHASH_SINGLE && (nHashType & 0x1f) != SIGHASH_NONE) {
- hashOutputs = cacheready ? cache->hashOutputs : GetOutputsHash(txTo);
+ hashOutputs = cacheready ? cache->hashOutputs : SHA256Uint256(GetOutputsSHA256(txTo));
} else if ((nHashType & 0x1f) == SIGHASH_SINGLE && nIn < txTo.vout.size()) {
CHashWriter ss(SER_GETHASH, 0);
ss << txTo.vout[nIn];