Skip to main content

The Bitcoin Script Pieces Behind Cross-Chain Verification

Oliver Bennett 7 min read

OP_CHECKLOCKTIMEVERIFY arrived on Bitcoin in December 2015 with BIP 65. Before that, a time-based spend condition had to be coaxed through the nLockTime field rather than stated outright in the script. BIP 65 turned the timelock into an opcode the script can assert on its own: the output cannot be spent until a given block height passes. Anyone reading the transaction output can then check the condition directly.

That property is why Bitcoin Script suits cross-chain HTLC conditions. The terms are not parked in a database, in a contract on some other chain, or in an operator's API reply. They live in the Bitcoin output, open to any participant running a full node.

A Language Built to Say No

Bitcoin Script is stack-based and deliberately not Turing-complete. Its business is deciding whether a UTXO may be spent. An output carries a locking script, the spending transaction carries an unlocking script, and the network runs the two together: the unlocking data goes onto the stack, the locking script executes, and a TRUE result validates the spend.

The missing features are the point. No loops. No external calls. No reading another chain's state. Each omission makes execution deterministic, time-bounded, and checkable offline with nothing but the transaction itself.

Building an HTLC calls on four opcodes: OP_HASH160, OP_EQUALVERIFY, OP_CHECKLOCKTIMEVERIFY, and OP_CHECKSIG. OP_HASH160 runs SHA-256 then RIPEMD-160 over the top stack item. OP_EQUALVERIFY compares the top two items and fails on a mismatch. OP_CHECKLOCKTIMEVERIFY tests the transaction's nLockTime against a stack value. OP_CHECKSIG validates a signature against a public key.

Inside the Locking Script

A standard HTLC on Bitcoin carries two ways out: the preimage path and the timeout path.

The preimage path releases funds to the counterparty once they supply the correct secret. The script hashes what it is given, compares the result with the expected hash, and, provided the hashes agree and the counterparty's signature is valid, lets the spend through.

The timeout path returns funds to the original funder after the locktime lapses. The script checks that block height has passed the agreed deadline, then verifies the funder's signature.

OP_IF/OP_ELSE branching holds both paths in one locking script; the unlocking script picks which branch runs. Read straight from a transaction output, the script answers three questions for any observer: which hash must be supplied, whose key may claim on each path, and what block height governs the timeout. Those are the whole set of conditions, and every one of them sits on-chain.

Checking a Lock Before You Commit

In a cross-chain swap, the party creating the second lock (Party B) has to satisfy itself about Party A's HTLC before putting its own funds at stake. The Bitcoin transaction supplies everything needed for that check.

Party B reads Party A's locking script before building its counterparty HTLC. Three things need to line up: the hash matches what was agreed, the timeout sits correctly against the swap window, and the authorised claiming key is Party B's own. Any mismatch and Party B simply does not lock, so nothing is at risk.

One integration team asked exactly this question: which parts of the verification could be done on-chain, and which parts relied on trusting our infrastructure? We walked the Script output with them, and the answer held up. The complete HTLC conditions were readable and checkable independently, without a single call to a BuiId on Bitcoin API. The chain held the authoritative record; our API merely reported it. That split mattered to their compliance and audit teams.

How the Two Chains Stay Bound

Bitcoin Script cannot look at Ethereum or any other chain; the language gives it no mechanism for that. So nothing in the Script enforces the cross-chain link. The protocol enforces it through the shared preimage.

Both HTLCs commit to the same hash. Either lock can only be claimed by publishing the preimage, and publishing it on one chain makes it readable there. The other party sees the reveal and uses the same secret to claim on the second chain.

The timing does the coordination work. Party B's timeout falls before Party A's, which leaves Party B room to observe the reveal and claim from Party A's HTLC in time. Bitcoin Script polices the Bitcoin side; the contract on the other chain polices its own. The hash and the timeout asymmetry are the only things joining them, with no direct on-chain call between the two.

None of this means Bitcoin Script can inspect another chain's transactions; it cannot. What it does is create a Bitcoin-side spend condition whose terms are bound to another chain's conditions through a shared secret. The verification across chains happens in the protocol, not inside the Script.

Reading It From a Full Node

To check your own HTLC conditions, take the locking script from any node that indexes transaction outputs. On a full node, the decodescript RPC renders the hex into readable opcodes. The hash and block height appear as literal values, no BuiId on Bitcoin tooling involved.

The script will show the OP_HASH160 value as a 20-byte hex string, with the timeout height as an integer just ahead of OP_CHECKLOCKTIMEVERIFY. Feed that integer through Bitcoin's current height and average block time and you get a plain estimate of when the timeout falls due.

Why It Matters When You Integrate

For a team wiring a cross-chain swap protocol into an app, Script verifiability is operational, not philosophical. Compliance can read conditions straight from the chain. Security can confirm HTLC parameters without trusting an API. Users can check that the swap terms match what they agreed to before the counterparty lock goes out.

All of that runs on ordinary Bitcoin tooling. The same holds on the other side: an Ethereum HTLC exposes its conditions through standard contract calls. Both legs sit on-chain and are readable by both parties, with no route into any BuiId on Bitcoin internal system required.

The chains do not talk to each other. What on-chain verification gives you is a swap where neither side has to trust anything beyond the transactions.

Back to Protocol Notes

Inspect the Scripts

The SDK hands back raw HTLC script parameters for every swap. Decode them on testnet before you move to production.