Skip to main content

Module script

Module script 

Source
Expand description

Script execution engine from Orange Paper Section 5.2

Performance optimizations (VM):

  • Secp256k1 context reuse (thread-local, zero-cost abstraction)
  • Script result caching (production feature only, maintains correctness)
  • Hash operation result caching (OP_HASH160, OP_HASH256)
  • Stack pooling (thread-local pool of pre-allocated Vec)
  • Memory allocation optimizations

Enums§

SigVersion
Script version for policy/consensus behavior (BIP141/BIP341 SigVersion)

Functions§

batch_verify_signatures
Spec-locked to Orange Paper Section 5.2: BatchVerifySignatures
cast_to_bool
CastToBool: truthiness check for stack elements (BIP62/consensus). Returns true if ANY byte is non-zero, except for “negative zero” (0x80 in last byte, rest zeros).
clear_all_caches
Clear all caches
clear_hash_cache
Clear hash operation cache
clear_script_cache
clear_stack_pool
Clear thread-local stack pool
disable_caching
Disable caching for benchmarking
eval_script
Spec-locked to Orange Paper Section 5.2: EvalScript
p2sh_push_only_check
Spec-locked to Orange Paper Section 5.2.1: P2SHPushOnlyCheck
reset_benchmarking_state
Reset all benchmarking state
to_stack_element
Convert bytes to StackElement (for tests and callers needing explicit conversion).
try_verify_p2pk_fast_path
Spec-locked to Orange Paper Section 5.2: TryVerifyP2pkFastPath
try_verify_p2pkh_fast_path
P2PKH fast-path. Returns Some(Ok(bool)) if script is P2PKH and we handled it; Returns None to fall back to full interpreter.
verify_p2pk_inline
P2PK (Pay-to-Public-Key) inline verify.
verify_p2pkh_inline
Fully inlined P2PKH verification for the rayon fast path. Caller MUST have already verified script_pubkey is a valid P2PKH (25 bytes, correct opcodes). Eliminates: redundant pattern check, Option unwrapping for precomputed values (always None), assumevalid lookup, sighash cache overhead. Returns Ok(true/false) directly — no Option wrapping.
verify_pre_extracted_ecdsa
Verify pre-extracted ECDSA (P2PKH/P2PK) inline without re-parsing script_sig.
verify_script
Spec-locked to Orange Paper Section 5.2: VerifyScript
verify_script_with_context
Spec-locked to Orange Paper Section 5.2: VerifyScriptWithContext
verify_script_with_context_full
Spec-locked to Orange Paper Section 5.2: VerifyScriptWithContextFull

Type Aliases§

StackElement
Stack element: inline up to 80 bytes when production (sigs, pubkeys, hashes), else Vec.