Expand description
Transaction sighash / txid helpers from consensus.
Structs§
- Bip143
Precomputed Hashes - Precomputed hash components for BIP143 sighash. These are computed once per transaction and reused for all inputs.
- Sighash
Cache Key - Per-block sighash cache: (prevout, code_hash, sighash_byte) -> hash. Core-style. Uses hash of scriptCode instead of owned Vec to avoid allocation on insert.
- Sighash
Type - SIGHASH types for transaction signature verification
Functions§
- batch_
compute_ bip143_ sighashes - Batch compute BIP143 sighashes for all inputs. This is the optimal way to verify a SegWit transaction - compute precomputed hashes once, then calculate sighash for each input.
- batch_
compute_ legacy_ sighashes - Batch compute legacy sighashes for specified inputs. Roadmap #12: Precompute before script execution for P2PKH-heavy blocks (100k band). Each spec is (input_index, sighash_byte, script_code). Returns hashes in spec order. Uses thread-local reusable buffers; no per-spec Vec allocs.
- batch_
compute_ sighashes - Batch compute sighashes for all inputs of a transaction
- calculate_
bip143_ sighash - Calculate BIP143 sighash for SegWit transactions.
- calculate_
transaction_ sighash - Calculate transaction sighash for signature verification
- calculate_
transaction_ sighash_ single_ input - Calculate sighash for a single input without requiring full prevout arrays. Takes only (script_for_signing, prevout_value) for the current input. Non-signing inputs use empty script internally. Eliminates need for workers to build full refs per tx. script_for_signing is the script that goes into the preimage (scriptPubKey or redeem script).
- calculate_
transaction_ sighash_ with_ script_ code - Calculate transaction sighash with optional script code override
- clear_
sighash_ templates - Clear sighash cache. Useful for benchmarking to ensure consistent results. Clears the thread-local SIGHASH_CACHE on the current thread.
- compute_
legacy_ sighash_ buffered - Compute legacy sighash by pre-serializing the full preimage into a thread-local buffer, then hashing in one pass. Reduces function call overhead vs streaming h.update() calls.
- compute_
legacy_ sighash_ nocache - Compute legacy sighash without any caching layers. Uses incremental SHA256 - feeds data directly to the hasher, avoiding the preimage buffer allocation and double memory pass.
- compute_
sighashes_ batch - Batch-compute legacy sighashes for all inputs of a single transaction using SHA256 forward midstate caching. For SIGHASH_ALL (most common), the SHA256 state after processing inputs 0..i-1 with blank scripts is reused for input i, cutting the O(N²) hashing work roughly in half.