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
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
EvalScript: ๐’ฎ๐’ž ร— ๐’ฎ๐’ฏ ร— โ„• ร— SigVersion โ†’ {true, false}
p2sh_push_only_check
P2SH Push-Only Validation (Orange Paper 5.2.1). Returns true if script_sig contains only push opcodes (valid), false otherwise (invalid).
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
VerifyScript with full context including block height, median time-past, and network
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
VerifyScript: ๐’ฎ๐’ž ร— ๐’ฎ๐’ž ร— ๐’ฒ ร— โ„• โ†’ {true, false}
verify_script_with_context
VerifyScript with transaction context for signature verification
verify_script_with_context_full

Type Aliasesยง

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