What are Bitcoin Smart Contracts? Ordinals, NFTs, Runes Explained

While Bitcoin was originally created for decentralized storage and management of value, other networks have expanded into different areas, developing ways to host decentralized applications. Decentralized apps (DApps) have gained widespread popularity, leading to a movement to create these apps on the Bitcoin blockchain. However, this was not Bitcoin's original purpose, making it more complicated than many smart-contract-ready networks like Ethereum.

So, how do Bitcoin's versions of smart contracts function, and what capabilities are available using this approach?
 

Does Bitcoin support smart contracts?

The Bitcoin blockchain does indeed support smart contracts. Smart contracts can be written and deployed on Bitcoin using Script, a scripting language. Script is not Turing-complete, meaning it's less versatile than languages used for smart contracts on other blockchains, like Ethereum's Solidity, but it enhances security and predictability.

Unlike other blockchains, such as Ethereum, Bitcoin's Script lacks the opcodes that can read and write the current "state" of the blockchain. These opcodes are essential for creating complex automated tasks triggered by a blockchain transaction.

Bitcoin script does not have these opcodes, meaning it does not maintain a recorded current "state" at any moment. Instead, it focuses on recording ownership and enabling the transfer of coins via UTXOs, with limited conditions for value transfer execution.

Let's explore how they function.
 

How do Bitcoin smart contracts work?

Bitcoin smart contracts, similar to those on other networks, are code snippets that automatically carry out specified actions when certain conditions are met. It uses its own programming language, Script, which operates on a "lock and key" system to execute smart contracts. When initiating a transaction, the sender establishes a condition or rule acting as the "lock." At the same time, the recipient must provide a corresponding "key" in the form of code in Script to fulfill the sender's condition.

Types of Bitcoin smart contracts

Bitcoin smart contracts, though less flexible than those on Ethereum, can be implemented using various methods to facilitate complex transactions and functionalities.

  1. Pay-to-public key hash scripts (P2PKH)

Pay-to-public key hash (P2PKH) scripts are a type of Script used in Bitcoin to lock and unlock transactions. They are the most common script type and are used to send bitcoins to a public key hash.

Here's a breakdown of how it works:

  • Pay-to: Indicates the Script is used to send bitcoins to a recipient.
  • Public key hash: The Script locks the bitcoins to a hash of the recipient's public key.
  • Scripts: A set of instructions that must be executed to unlock the bitcoins.

The P2PKH script format is:

OP_DUP OP_HASH160 <pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG

Where:

  • OP_DUP duplicates the top stack item.
  • OP_HASH160 takes the public key and hashes it with SHA-256 and then RIPEMD-160.
  • <pubkey_hash> is the hashed public key.
  • OP_EQUALVERIFY verifies that the hashed public key matches the one provided.
  • OP_CHECKSIG checks the signature against the public key.

P2PKH scripts are used in most Bitcoin transactions and are considered a secure and efficient way to transfer bitcoins.

  1. Multisignature scripts (MultiSig)

Multisignature scripts (MultiSig) require multiple signatures (private keys) to authorize a transaction. This means that a transaction can only be spent if multiple parties agree to it, making it a powerful tool for secure and collaborative transactions.

The MultiSig script format is:

m <pubkey1> <pubkey2> ... <pubkeyN> n OP_CHECKMULTISIG

Where:

  • m is the minimum number of signatures required (threshold).
  • n is the total number of public keys.
  • <pubkey1> <pubkey2> ... <pubkeyN> are the public keys.
  • OP_CHECKMULTISIG checks the signatures against the public keys.

For example, a 2-of-3 MultiSig script would require two out of three signatures to authorize a transaction. MultiSig scripts provide an additional layer of security and flexibility in cryptocurrency transactions.

  1. Time Locked Bitcoin Transactions (nLockTime and nSequence)

This feature enables the creation of a transaction at any time, with validation only at a specified future date or block height. It's a method of scheduling a Bitcoin transaction and is beneficial for different financial agreements. It functions as a kind of time constraint for transactions. 

Time-locked transactions were made feasible through BIP-65 and the introduction of new opcodes related to the 'nLockTime' and nSequence fields by BIP-112. In essence, these opcodes enable an entry to specify the earliest time it can be included in a block, preventing the transaction from finalizing until a certain number of blocks or a specific amount of time has passed. 

nLockTime(TLS):

  • nLockTime is a transaction-level feature that allows setting a minimum block height or timestamp for when a transaction can be added to the blockchain.
  • It ensures that a transaction is not confirmed until a certain time or block height is reached.
  • nLockTime is specified in the transaction header and is enforced by nodes and miners.

nSequence(SQ):

  • nSequence is an input-level feature that allows setting a relative time lock for each input in a transaction.
  • It specifies the number of blocks that must pass before an input can be spent.
  • nSequence is used in combination with nLockTime to create more complex time-locked transactions.

nLockTime and nSequence help create more sophisticated and secure transaction workflows, enabling new use cases and applications on the blockchain.

  1. Pay to Script Hash (P2SH – BIP16)

Pay to Script Hash (P2SH) is a Bitcoin script feature introduced in 2012 through BIP16 (Bitcoin Improvement Proposal 16). It allows users to send bitcoins to a script hash instead of a public key hash, enabling more complex transaction scenarios.

nsec1a2c9azelclw0dgws4ldgv9xzs29m90gu5q0f86cusen0k7alc87qgm262d

P2SH enables the use of complex scripts, such as multi-signature (MultiSig) and smart contracts, without revealing the script details in the transaction. Only the hash of the Script is stored on the blockchain, reducing storage requirements and improving network efficiency. In addition, the Script remains private until the transaction is spent, enhancing user privacy.

How P2SH works:

  1. A user creates a script and hashes it.
  2. The user sends bitcoins to the hash of the Script (P2SH address).
  3. To spend the bitcoins, the user reveals the original Script and satisfies its conditions.

P2SH addresses start with "3" and are longer than traditional Bitcoin addresses. Wallets and nodes widely support them and have become an essential feature of the Bitcoin network.

  1. Pay-to-taproot (P2TR – BIP341)

Pay-to-Taproot (P2TR - BIP341) smart contracts are a type of Bitcoin smart contract that utilizes the Taproot protocol upgrade (BIP341) to enhance privacy, flexibility, and efficiency. These smart contracts enable complex conditions for spending bitcoins while maintaining a high level of confidentiality and efficiency.

Taproot smart contracts hide the complexity of the spending conditions, making it difficult for outsiders to determine the exact conditions required to spend the bitcoins. P2TR smart contracts support various spending conditions, including complex logic and multiple signatures. They are also more efficient regarding blockchain space, as the complex spending conditions are not revealed until the bitcoins are spent.
 

Do NFTs exist on the Bitcoin network?

NFTs (Non-Fungible Tokens) on the Bitcoin network have gained traction through several innovative methods and protocols, despite Bitcoin's original design not catering to complex data storage or smart contracts like Ethereum.

Bitcoin's NFT landscape

Bitcoin's network was not initially designed to support NFTs, but several methods and protocols have emerged to enable this functionality. One of the earliest attempts to create NFTs on Bitcoin was through Colored Coins. This concept utilizes small amounts of Bitcoin, or "satoshis," as markers to represent ownership of assets. 

However, it faced limitations due to Bitcoin's scripting language constraints, leading to limited functionality and adoption. Counterparty (XCP), launched in 2014, operates as a protocol running on top of the Bitcoin blockchain, allowing users to create and trade tokens, including NFTs. It embeds data within Bitcoin transactions to manage tokens, with notable projects like "Rare Pepes," collectible meme cards, exemplifying its use.

Stacks

Stacks (formerly Blockstack) is another significant player, offering a layer-2 blockchain that integrates with Bitcoin. It introduces Clarity, a new smart contract language, facilitating the creation and management of NFTs while leveraging Bitcoin's security. Similarly, RSK (Rootstock) functions as a sidechain, enabling smart contracts on Bitcoin. It uses a 2-way peg to convert Bitcoin to "Smart Bitcoin" (RBTC) for use in smart contracts, thus supporting NFTs.

Ordinals

Bitcoin Ordinals, introduced on January 20, 2023, by developer Casey Rodarmor, marked a significant step in tokenization on the Bitcoin blockchain. This protocol allows users to inscribe data such as text, images, videos, and even smart contracts directly onto the Bitcoin blockchain. Known as Bitcoin NFTs, Ordinals have generated both enthusiasm and skepticism in the cryptocurrency community.

Ordinals were made possible by key Bitcoin network upgrades: the 2017 Segregated Witness (SegWit) and the 2021 Taproot upgrade. These improvements enhanced Bitcoin's ability to handle smart contracts and large data inscriptions. Inscriptions are pieces of information embedded into satoshis, the smallest units of Bitcoin.

BRC-20

Like Ethereum's ERC-20 standard, BRC-20 allows for the creation and transfer of fungible tokens on the Bitcoin network through Ordinal inscriptions.

BRC-20 tokens experienced rapid growth in just three months, achieving a market cap of $1 billion. However, this surge led to significant network congestion due to the numerous unspent transaction outputs (UTXOs) being generated, causing a backlog in the network.

Bitcoin Runes

Bitcoin Runes introduces a new way to implement smart contracts and programmable assets on the Bitcoin network without altering its core structure. Designed to simplify fungible token creation and address UTXO bloat issues from BRC-20 tokens, Runes uses Bitcoin's UTXO model and the OP_RETURN opcode.

Runes assigns unique digital assets to UTXOs using protocol messages that include details like Rune ID, output index, and amount, all stored in OP_RETURN outputs. This method leverages Bitcoin's on-chain data storage, reducing the creation of excessive UTXOs that can congest the network.

Rune balances are tracked within UTXOs rather than linked to wallet addresses. They are transferred through Bitcoin transactions with OP_RETURN outputs specifying the transfer details. Runes can be created (etched), generated (minted), and transferred using messages (runestones) stored in Bitcoin transaction outputs. Etching sets properties like name and symbol, minting creates tokens based on these properties, and transferring involves specifying the output number, Rune ID, and amount.
 

Challenges of implementing NFTs on the Bitcoin blockchain

Integrating NFTs on the Bitcoin network faces challenges due to Bitcoin's block size and transaction throughput limitations, making scalability a significant issue. Implementing NFT functionalities often requires layer-2 solutions or sidechains due to their complexity.

Use cases and examples

NFTs have various uses on the Bitcoin network. Digital art, collectibles, and unique digital assets are some examples. Projects like Rare Pepes and the Ordinals protocol have made digital art collections and collectibles possible. NFTs have also been integrated into gaming platforms using Stacks or RSK, showing how versatile they can be.

Future prospects

NFTs have a promising future on the Bitcoin network. Ongoing development in Bitcoin-based NFT protocols and increased interest from users and developers indicate growing adoption. There is potential for cross-chain solutions that could enhance interoperability, allowing NFTs to move between Bitcoin and other blockchains, expanding their utility and reach.