From ce9353164bdb6215a62b2b6dcb2121d331796f60 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 27 Feb 2021 20:24:31 -0800 Subject: Permit full precomputation in PrecomputedTransactionData At verification time, the to be precomputed data can be inferred from the transaction itself. For signing, the necessary witnesses don't exist yet, so just permit precomputing everything in that case. --- src/script/interpreter.cpp | 12 ++++++------ src/script/interpreter.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 6c49d4a5ab..2dd173ee20 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1420,7 +1420,7 @@ uint256 GetSpentScriptsSHA256(const std::vector& outputs_spent) } // namespace template -void PrecomputedTransactionData::Init(const T& txTo, std::vector&& spent_outputs) +void PrecomputedTransactionData::Init(const T& txTo, std::vector&& spent_outputs, bool force) { assert(!m_spent_outputs_ready); @@ -1431,9 +1431,9 @@ void PrecomputedTransactionData::Init(const T& txTo, std::vector&& spent } // Determine which precomputation-impacting features this transaction uses. - bool uses_bip143_segwit = false; - bool uses_bip341_taproot = false; - for (size_t inpos = 0; inpos < txTo.vin.size(); ++inpos) { + bool uses_bip143_segwit = force; + bool uses_bip341_taproot = force; + for (size_t inpos = 0; inpos < txTo.vin.size() && !(uses_bip143_segwit && uses_bip341_taproot); ++inpos) { if (!txTo.vin[inpos].scriptWitness.IsNull()) { if (m_spent_outputs_ready && m_spent_outputs[inpos].scriptPubKey.size() == 2 + WITNESS_V1_TAPROOT_SIZE && m_spent_outputs[inpos].scriptPubKey[0] == OP_1) { @@ -1478,8 +1478,8 @@ PrecomputedTransactionData::PrecomputedTransactionData(const T& txTo) } // explicit instantiation -template void PrecomputedTransactionData::Init(const CTransaction& txTo, std::vector&& spent_outputs); -template void PrecomputedTransactionData::Init(const CMutableTransaction& txTo, std::vector&& spent_outputs); +template void PrecomputedTransactionData::Init(const CTransaction& txTo, std::vector&& spent_outputs, bool force); +template void PrecomputedTransactionData::Init(const CMutableTransaction& txTo, std::vector&& spent_outputs, bool force); template PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo); template PrecomputedTransactionData::PrecomputedTransactionData(const CMutableTransaction& txTo); diff --git a/src/script/interpreter.h b/src/script/interpreter.h index fa4ee83e04..399d775181 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -168,7 +168,7 @@ struct PrecomputedTransactionData PrecomputedTransactionData() = default; template - void Init(const T& tx, std::vector&& spent_outputs); + void Init(const T& tx, std::vector&& spent_outputs, bool force = false); template explicit PrecomputedTransactionData(const T& tx); -- cgit v1.2.3