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
Legacy sighash cache key.
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.
derive_bip143_script_code
Derive BIP143 scriptCode for SegWit v0 spends.
derive_bip143_script_code_p2wpkh
BIP143 scriptCode for P2WPKH: P2PKH expansion of the 20-byte pubkey hash (BIP143 §4.3).
serialize_script_code_for_legacy_sighash
Serialize scriptCode bytes for legacy sighash, stripping OP_CODESEPARATOR (0xab) opcodes.

Type Aliases§

SighashMidstateCache