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ยง
- Stack
Element - Stack element: inline up to 80 bytes when production (sigs, pubkeys, hashes), else Vec
.