BitcoinMachine
BEGINNER_DOC_011 // BEGINNERS / LOCKS
LOCKS
Every bitcoin output is protected by a script/">locking script (ScriptPubKey) — a small program that defines exactly what must be proven to spend those funds. When you "send bitcoin to an address," you are writing a lock. The recipient holds the key. Only someone who can satisfy the lock's conditions can unlock and spend the output.
LOCKING SCRIPT — ScriptPubKey (STORED IN THE OUTPUT)
The "lock" placed on the output when it is created. Determines who can spend it and under what conditions. Example (P2PKH): OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
UNLOCKED BY
UNLOCKING SCRIPTScriptSig / Witness (STORED IN THE INPUT)
The "key" provided when spending the output. Must satisfy the conditions set by the locking script. Example (P2PKH): <Signature> <PublicKey>
MOST COMMON
Requires a valid signature from the private key corresponding to a specific public key hash. The most widely used lock type.
Lock: OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG Unlock: <Sig> <PubKey> To satisfy: prove you own the private key behind the address. Any other key produces an invalid signature → rejected by all nodes.
Multisig Lock (P2MS / P2SH)
M-OF-N
Requires M valid signatures out of N possible keys. Used for shared custody, corporate treasuries, and exchanges.
Lock (2-of-3): OP_2 <PubKey1> <PubKey2> <PubKey3> OP_3 OP_CHECKMULTISIG Unlock: OP_0 <Sig1> <Sig2> 2 of the 3 keyholders must sign. No single point of failure.
Timelock (CLTV / CSV)
TIME-BASED
Adds a time condition to the lock. The output cannot be spent before a specific block-height/">block height or relative time has passed.
CLTV — CheckLockTimeVerify (absolute): <blockheight> OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG → unspendable until block N CSV — CheckSequenceVerify (relative): <blocks> OP_CHECKSEQUENCEVERIFY OP_DROP ... → unspendable until N blocks after this tx is mined
Timelocks are the foundation of payment channels and the Lightning Network.
Hash Lock (HTLC)
HASH-BASED
Requires the spender to reveal a secret pre-image that hashes to a specific value. Used in atomic swaps and Lightning payment routing.
Lock: OP_HASH256 <HashValue> OP_EQUAL Unlock: <SecretPreimage> To satisfy: you must know the secret value R such that: SHA256(SHA256(R)) == HashValue Used in HTLCs (Hash Time-Locked Contracts) for cross-chain swaps.
THE LOCK IS THE LAW
NO COURT ORDER · NO OVERRIDE · ONLY VALID CRYPTOGRAPHIC PROOF UNLOCKS THE OUTPUT
TERMINOLOGY_INDEX
ScriptPubKey
The locking script embedded in an output. Defines spending conditions.
ScriptSig
The unlocking script in a transaction input. Provides data to satisfy the ScriptPubKey.
Witness
In SegWit transactions, the unlocking data is moved to a separate witness field outside the main tx body.
CLTV
OP_CHECKLOCKTIMEVERIFY. An opcode that enforces an absolute block height or timestamp before spending.
CSV
OP_CHECKSEQUENCEVERIFY. Enforces a relative timelock — a minimum number of blocks since the UTXO was created.
HTLC
Hash Time-Locked Contract. A script combining a hash lock and a timelock for atomic payments.