Module script

Source
Expand description

§Bitcoin Script Construction

This module provides a collection of builders for creating various Bitcoin scripts utilized within the Clementine bridge. It defines a SpendableScript trait, implemented by specific script structures (e.g., CheckSig, WinternitzCommit, TimelockScript, BaseDepositScript) to standardize script generation and witness creation.

Each script builder offers:

  • A constructor to initialize the script with its specific parameters.
  • A method to convert the script structure into a bitcoin::ScriptBuf.
  • A method to generate the corresponding bitcoin::Witness required to spend an output locked with this script.

The module also includes ScriptKind, an enum to differentiate between various spendable script types, facilitating dynamic dispatch and script management. Helper functions like extract_winternitz_commits are provided for parsing specific data committed using witnernitz keys from witness.

Structs§

BaseDepositScript
Struct for deposit script that commits Citrea address to be deposited into onchain.
CheckSig
Struct for scripts that only includes a CHECKSIG
Multisig
OtherSpendable
Struct for scripts that do not conform to any other type of SpendableScripts
PreimageRevealScript
Struct for scripts that reveal a preimage of a OP_HASH160 and verify it against the given hash in the script.
ReplacementDepositScript
Struct for deposit script that replaces an old move tx with a replacement deposit (to update bridge design on chain) It commits to the old move txid inside the script.
TimelockScript
Struct for scripts that include a relative timelock (by block count) and optionally a CHECKSIG if a pubkey is provided. Generates a relative timelock script with a given [XOnlyPublicKey] that CHECKSIG checks the signature against.
WinternitzCommit
Struct for scripts that commit to a message using Winternitz keys Contains the Winternitz PK, CheckSig PK, message length respectively can contain multiple different Winternitz public keys for different messages

Enums§

ScriptKind
SpendPath

Traits§

SpendableScript
A trait that marks all script types. Each script has a generate_script_inputs (eg. WinternitzCommit::generate_script_inputs) function that generates the witness for the script using various arguments. A dyn SpendableScript is cast into a concrete ScriptKind to generate a witness, the trait object can be used to generate the script_buf.

Functions§

extract_winternitz_commits
Extracts the committed data from the witness. Note: The function is hardcoded for winternitz_log_d = 4 currently, will not work for others.
extract_winternitz_commits_with_sigs
Extracts the committed data from the witness. Note: The function is hardcoded for winternitz_log_d = 4 currently, will not work for others.
from_minimal_to_u32_le_bytes 🔒
Converts a minimal serialized u32 (trailing zeros removed) to full 4 byte representation