@@ -203,7 +203,18 @@ Where
203
203
return GetDefaultCheckTemplateVerifyHash(current_tx, current_input_index) == uint256(hash);
204
204
}
205
205
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
+ }
207
218
// not DoS safe, for reference/testing!
208
219
uint256 GetDefaultCheckTemplateVerifyHash(const CTransaction& tx, uint32_t input_index) {
209
220
return GetDefaultCheckTemplateVerifyHash(tx, GetOutputsSHA256(tx), GetSequenceSHA256(tx), input_index);
@@ -244,6 +255,21 @@ The hash is computed as follows:
244
255
return h.GetSHA256();
245
256
}
246
257
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
+
247
273
A PayToBareDefaultCheckTemplateVerifyHash output matches the following template:
248
274
249
275
bool CScript::IsPayToBareDefaultCheckTemplateVerifyHash() const
0 commit comments