@@ -203,7 +203,18 @@ Where
203203 return GetDefaultCheckTemplateVerifyHash(current_tx, current_input_index) == uint256(hash);
204204 }
205205
206- The hash is computed as follows:
206+ The hash is computed as follows, where the outputs_hash and sequences_hash are computed as defined in BIP-341.
207+
208+ /** Compute the (single) SHA256 of the concatenation of all scriptSigs in a tx. */
209+ template <class T>
210+ uint256 GetScriptSigsSHA256(const T& txTo)
211+ {
212+ CHashWriter ss(SER_GETHASH, 0);
213+ for (const auto& in : txTo.vin) {
214+ ss << in.scriptSig;
215+ }
216+ return ss.GetSHA256();
217+ }
207218 // not DoS safe, for reference/testing!
208219 uint256 GetDefaultCheckTemplateVerifyHash(const CTransaction& tx, uint32_t input_index) {
209220 return GetDefaultCheckTemplateVerifyHash(tx, GetOutputsSHA256(tx), GetSequenceSHA256(tx), input_index);
@@ -244,6 +255,21 @@ The hash is computed as follows:
244255 return h.GetSHA256();
245256 }
246257
258+ In python, this can be written as (but note this implementation is DoS-able).
259+
260+ def get_default_check_template_hash(self, nIn):
261+ r = b""
262+ r += struct.pack("<i", self.nVersion)
263+ r += struct.pack("<I", self.nLockTime)
264+ if any(inp.scriptSig for inp in self.vin):
265+ r += sha256(b"".join(ser_string(inp.scriptSig) for inp in self.vin))
266+ r += struct.pack("<I", len(self.vin))
267+ r += sha256(b"".join(struct.pack("<I", inp.nSequence) for inp in self.vin))
268+ r += struct.pack("<I", len(self.vout))
269+ r += sha256(b"".join(out.serialize() for out in self.vout))
270+ r += struct.pack("<I", nIn)
271+ return sha256(r)
272+
247273A PayToBareDefaultCheckTemplateVerifyHash output matches the following template:
248274
249275 bool CScript::IsPayToBareDefaultCheckTemplateVerifyHash() const
0 commit comments