How Do Smart Contracts Work on Bitcoin Layer 2?
Bitcoin's base layer cannot run general smart contracts. Layer 2 networks add that ability in different ways, from EVM sidechains to BitVM proofs.
On this page
Short answer
Bitcoin's base layer runs a small scripting language, so it cannot run general smart contracts. Layer 2 networks add that ability by running contracts elsewhere and anchoring the result to Bitcoin. Sidechains such as Rootstock run Ethereum-style contracts with merged mining, Stacks runs Clarity contracts anchored by proof of transfer, and BitVM aims to verify arbitrary computation with fraud proofs. Each approach trades security for flexibility.
Why can't Bitcoin run smart contracts itself?
Bitcoin cannot run general smart contracts because its scripting language was designed to be small and predictable. Bitcoin Script can check signatures, enforce time locks and combine a few conditions, but it has no loops and no way to store state between transactions. A contract that needs to remember a balance or run a long calculation has nowhere to live.
That limit is a design choice, not an oversight. A small script language means every node can check every transaction cheaply, and a bug in a script cannot lock the network in an endless loop. Ethereum chose the opposite trade: a general language that can run any program, with gas fees to pay for the work. Bitcoin kept the base layer simple and pushed complex logic elsewhere.
The result is a gap. Bitcoin holds the largest store of value in crypto, but it cannot run the lending, trading and token contracts that run on Ethereum. Layer 2 networks exist to close that gap: they run the contracts off the base layer and anchor the result to Bitcoin. Our explainer of what Bitcoin layer 2 is covers the general idea first.
How do layer 2 smart contracts work?
A layer 2 smart contract runs on a separate network that is connected to Bitcoin by a peg. Bitcoin is locked on the base layer, an equivalent asset is issued on the layer 2, and contracts run against that asset. When the user is done, the asset is burned and the original bitcoin is released.
| Approach | Where contracts run | How Bitcoin is linked |
|---|---|---|
| EVM sidechain | Rootstock, own chain | Merged mining, two-way peg |
| Proof-of-transfer chain | Stacks, own chain | BTC spent to mine blocks, sBTC peg |
| ZK rollup | Citrea, off-chain execution | Proofs anchored via Taproot |
| BitVM | Off-chain computation | Challenge-response fraud proofs |
The peg is the weakest link in every design. Moving bitcoin in and out needs either a federation, a multisignature group, or a proof system that Bitcoin can check. If the peg fails, the contracts keep running but the bitcoin behind them is stuck. Check the peg before you trust the contracts.
Which networks offer smart contracts today?
The networks that offer smart contracts on Bitcoin today fall into three groups: sidechains that have run for years, newer rollups, and research designs that are not yet live. The table in the previous section shows the split; this section looks at what each group actually runs.
Rootstock, often called RSK, is the oldest. It launched in 2018 as an EVM-compatible sidechain, so contracts written in Solidity run on it, and Bitcoin miners can validate its blocks through merged mining. Its gas token, Smart Bitcoin (RBTC), is pegged to BTC. It has run DeFi apps, stablecoins and oracles for years, which makes it the most battle-tested option.
Stacks takes a different route. It runs its own chain with the Clarity language, a decidable language that cannot loop forever, and anchors its blocks to Bitcoin through proof of transfer, where miners spend BTC to earn the right to produce blocks. Its sBTC asset is pegged one to one with bitcoin and lets contracts hold real BTC value. The Nakamoto upgrade made its blocks faster and its settlement more direct.
The newest group is rollups and BitVM. Citrea is a zero-knowledge rollup that runs contracts off chain and anchors proofs to Bitcoin through Taproot. BOB (Build on Bitcoin) is a hybrid rollup that runs EVM contracts with Bitcoin security. BitVM, first described in 2023, verifies arbitrary computation with challenge-response proofs. These designs are younger, and their bridges still rely on multisignature groups or operator sets.
What can you build with Bitcoin layer 2 contracts?
You can build most of what runs on Ethereum, with Bitcoin as the collateral. Lending desks let users borrow stablecoins against BTC, trading protocols run swaps and perpetuals, and token platforms issue real-world assets such as tokenized treasury bills. The contracts are the same shape as Ethereum contracts; only the settlement asset changes. Enterprise teams are already building this way, as our guide to building enterprise DeFi on Bitcoin layer 2 shows.
Payments and identity are smaller but real uses. A contract can release payment when a delivery is confirmed, hold funds in escrow until both sides agree, or check a credential before granting access. These uses need less liquidity than DeFi, so they are often the first contracts a team ships.
What you cannot build yet is a contract that Bitcoin itself enforces. If the layer 2 fails, the contract's promises depend on the peg and the operators, not on Bitcoin consensus. That is the trade every Bitcoin layer 2 makes, and it is why the trust model matters more than the feature list.
What are the trade-offs?
The trade-offs start with the peg. A two-way peg needs a custodian, a federation or a proof system, and each one can fail in a different way. A federation can be pressured or hacked; a proof system can have a bug; a multisignature bridge can lose keys. Bitcoin's security does not automatically extend to the layer above it. Our explainer of how cross-chain bridges work covers the same risk in general terms.
The second trade-off is finality. A transaction on the layer 2 settles when the layer 2 says so, and the anchor to Bitcoin may come later. If the layer 2 reorganises or halts, recent transactions can be reversed or delayed. Teams that need hard finality should check how often the layer anchors to Bitcoin and what happens during an outage.
The third trade-off is maturity. Rootstock has run since 2018, but most Bitcoin rollups are a few years old or younger, and BitVM is still a framework rather than a live network. Newer code means fewer audits, fewer users and thinner liquidity. That is not a reason to avoid them, but it is a reason to test with small amounts first.
How do you choose a network, step by step?
You choose by the job, the trust you accept, and the tooling your team already knows. A network that is right for payments can be wrong for lending, and a network with familiar tools can be wrong if its peg is weak.
- Name the job. Payments need speed; lending needs a strong peg; tokenized assets need compliance hooks.
- Check the peg. Who holds the bitcoin, how many signatures are needed, and what happens if the bridge stops?
- Check the language. Solidity teams start with Rootstock or BOB; Clarity teams start with Stacks.
- Check the anchor. How often does the layer settle to Bitcoin, and what happens if it halts?
- Test the exit. Move a small amount in, use it, and move it back out before you commit real funds.
- Check the audits. Read the audit reports for the contracts and the bridge, not just the marketing page.
A comparison such as the top Bitcoin layer 2 solutions helps at this stage, because it scores the live networks against each other on the same questions.
Example (hypothetical): a lending desk on a Bitcoin layer 2
Example (hypothetical): a small lending desk locks 2 BTC as collateral on a Bitcoin layer 2. At a price of 50,000 dollars per BTC, the collateral is worth 100,000 dollars. The desk borrows 40,000 dollars in stablecoins, which is 40 percent of the collateral value.
The contract liquidates the position if the loan reaches 75 percent of the collateral value. If the price of bitcoin falls by 30 percent, the collateral is worth 70,000 dollars, and the loan of 40,000 dollars is about 57 percent of it, so the position survives. If the price falls by 50 percent, the collateral is worth 50,000 dollars, the loan is 80 percent of it, and the contract liquidates.
The desk's job is to watch two numbers: the price of bitcoin and the peg. If the peg breaks, the collateral is still on the layer 2 but the bitcoin behind it cannot be withdrawn, and the loan cannot be repaid from the base layer. That is why the desk tests the exit with a small amount before it locks the full 2 BTC.
What are the common mistakes?
The most common Bitcoin layer 2 mistakes are treating the layer as Bitcoin itself, skipping the exit test, and copying an Ethereum design without adapting it.
- Treating the layer as the base chain. A layer 2 transaction is not a Bitcoin transaction. It settles on the layer's rules, and the anchor to Bitcoin comes later.
- Skipping the exit test. A layer that takes deposits easily but cannot return them is a trap. Move a small amount out before you commit.
- Copying Ethereum designs. Gas, finality and reverts behave differently on a Bitcoin layer. Test the contract on the layer it will run on.
- Trusting the peg without checking it. Read who holds the bitcoin and how many signatures are needed before you lock funds.
- Ignoring bridge risk. Most layer 2 losses come from bridges, not from the contracts. Audit the bridge as carefully as the app.
Key takeaways
- Bitcoin Script has no loops or state, so general contracts cannot run on the base layer
- Layer 2 contracts run off chain and anchor the result to Bitcoin through a peg
- Rootstock runs Solidity contracts; Stacks runs Clarity contracts with sBTC
- Rollups and BitVM are younger designs whose bridges still rely on multisignature groups
- Check the peg, the anchor and the exit before locking real funds
Frequently asked questions
Why can't Bitcoin run smart contracts like Ethereum?
Bitcoin Script is a small language with no loops and no way to store state between transactions. That keeps the base layer simple and cheap to verify. Ethereum chose a general language with gas fees instead. Bitcoin pushes complex logic to layer 2 networks.
What is the difference between Rootstock and Stacks?
Rootstock is an EVM-compatible sidechain launched in 2018 that runs Solidity contracts and uses merged mining. Stacks runs its own chain with the Clarity language and anchors blocks to Bitcoin through proof of transfer. Both peg bitcoin in and out, but their trust models differ.
What is BitVM?
BitVM is a framework first described in 2023 for verifying arbitrary computation on Bitcoin without changing its consensus rules. It uses challenge-response proofs between a prover and a verifier, enforced with Taproot trees and pre-signed transactions. It is a framework, not yet a live network.
Can I use Bitcoin layer 2 contracts for DeFi?
Yes. Lending, trading and tokenized assets already run on Rootstock, Stacks and newer rollups, with BTC as the collateral. The contracts work, but the peg and the bridge carry the risk, so test the exit with a small amount first.
Does the Lightning Network run smart contracts?
Only in a narrow sense. Lightning uses hashed timelock contracts to route payments, but it cannot run general contracts such as lending or token logic. For those you need a sidechain, a rollup or a BitVM design.
What happens if a Bitcoin layer 2 bridge fails?
If the bridge fails, the assets on the layer 2 keep trading but the bitcoin behind them cannot be withdrawn. That is why the peg is the first thing to check: who holds the bitcoin, how many signatures are needed, and what happens if the bridge stops.