What Are Bitcoin Smart Contracts?
Smart contracts are one of the major selling points of blockchain technology. The blockchain-based programs are behind many of the most significant applications of crypto-currencies today, including decentralized finance (DeFi), NFTs, the Lightning Network, and more. However, most conversations about smart contracts focus on the Ethereum blockchain.
The main difference between Bitcoin and smart contract platforms such as Ethereum is the types of programmability they can support. It is entirely possible to write smart contracts on the Bitcoin blockchain - and actually extremely common. In fact, pretty much every transaction on the Bitcoin blockchain is a smart contract.
What is a Smart Contract?
Before diving into the details of different smart contracts, it’s important to define what a smart contract actually is. A smart contract is a program that is recorded on a blockchain’s digital ledger. Many blockchains include some form of scripting language to support these programs. In some cases, transactions performed on the blockchain can include some logic that defines how they can be processed. In others, programs can be deployed on the blockchain that other users can interact with to execute certain functionality. Both of these are examples of smart contracts. Smart contracts are useful because they have the same advantages as the blockchain’s digital ledger. Smart contracts run on decentralized infrastructure, ensuring resiliency and protecting against different types of attacks. They are recorded on an immutable digital ledger and can be visible to all participants.
What is Turing-Completeness?
When discussing smart contracts, a term that commonly comes up is Turing completeness. This concept, named for Alan Turing, defines the capabilities of a programming language and its execution environment. In a Turing-complete programming language, a program can solve any computational problem given adequate resources (time, memory, etc.). Most modern programming languages are Turing-complete, meaning that any program written in one language could also be written in another language.
A common point of contention is whether a smart contract language needs to be Turing-complete. Those who say it does claim that Ethereum and similar blockchains are smart contract platforms, while Bitcoin is not. This distinction is based on the fact that Bitcoin transactions are programmable but not Turing-complete.
How Bitcoin Supports Smart Contracts
Bitcoin can support a variety of smart contracts using various mechanisms. Some of the ways that Bitcoin implements programmable transactions and smart contract functionality include its built-in scripting language, the Lightning Network, Discreet Log Contracts, and sidechains.
Bitcoin Scripting Language
The Bitcoin protocol has a built-in scripting language called Script. The purpose of this language is to allow Bitcoin users to define rules for how a coin can be spent. For example, a Bitcoin output may require certain conditions to be met — such as being signed by multiple keys or waiting for a timelock to expire — to be spent.
With Script, it is possible to build smart contract functionality into any Bitcoin transaction. However, Script is not Turing-complete. It lacks support for loops which helps protect the Bitcoin network against denial-of-service (DoS) attacks. This means that — while Script is a powerful tool — there are some smart contract functions that can’t be natively implemented in Bitcoin.
Bitcoin has built-in support for a few different types of smart contracts, including:
- Pay-to-Public-Key-Hash (P2PKH): Ensures that only the recipient of a transaction can spend the Bitcoin it contains.
- Multi-Signature Scripts: Requires signatures from multiple wallets to release funds.
- Time-Locked Bitcoin Transactions: Prevents Bitcoin in a transaction from being spent until a certain period has elapsed.
- Pay-to-Script-Hash (P2SH): Sends Bitcoin to the hash of a script, improving efficiency and privacy.
Bitcoin Lightning Network
The core Bitcoin protocol has limited smart contract support. However, protocols implemented on the Bitcoin blockchain can provide additional capabilities.
The Lightning Network is a Layer 2 protocol that runs on the Bitcoin blockchain. With the Lightning Network, nodes can open a channel between each other, make an infinite number of off-chain transactions, and then close the channel by settling up using a transaction that is recorded on Bitcoin’s digital ledger. In addition to massively increasing the scalability and speed of Bitcoin, the Lightning Network is closely tied to Bitcoin’s smart contract capabilities. In fact, forwarding payments through a Lightning Channel requires using another type of smart contract called a Hashed Time-Locked Contract (HTLC).
Sidechains
The Bitcoin blockchain began as the original and only blockchain and was intended as a standalone system. However, over time, other blockchains have grown up alongside it. With these new blockchains comes the ability to integrate blockchains to provide various benefits.
Building Smart Contracts on Bitcoin
Every transaction performed on the Bitcoin network is inherently a smart contract. At a minimum, a Bitcoin transaction includes a script that specifies that only the transaction’s recipient can spend it. Otherwise, anyone could steal the Bitcoins stored in a particular Bitcoin account. However, this is only the beginning of Bitcoin’s smart contract capabilities. While the Script language is not Turing-complete, there is a great deal that it can do without the use of loops. Extending the Bitcoin protocol with the Lightning Network and other Layer 2 protocols and extensions broadens the possibilities even further.