Skip to main content

Module transaction_hash

Module transaction_hash 

Source
Expand description

Transaction sighash / txid helpers from consensus.

Structs§

Bip143PrecomputedHashes
Precomputed hash components for BIP143 sighash. These are computed once per transaction and reused for all inputs.
SighashCacheKey
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.
SighashType
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.

Type Aliases§

SighashMidstateCache