Dive into How Bitcoin Ordinals NFTs Work

How Bitcoin Ordinals NFTs Work

In the past, it was impossible to create a fully on-chain NFT on Bitcoin, because Bitcoin was initially designed for financial transactions and not data storage. By using the OP_RETURN script, we could only put up 80 bytes of data, which is quite limited for an NFT. However, the Taproot and SegWit upgrade unleashed the potential with the witness field, which can store arbitrary data less than 400,000 bytes.

Casey Rodarmor launched Ordinals Protocol in January 2023 to the immediate attention of people in the blockchain world. According to dune.xyz, the market shows interest in this protocol even if the only way to mint out an NFT is from the command line in the beginning. Bitcoin has a certain place in history and is the highest decentralized and most secure blockchain, so it may be more suitable for digital artists to use this protocol to mint NFTs.

This article will go through the basic technical details of Ordinals NFTs from zero to one.

What are NFTs?

People who aren’t familiar with NFTs should start with Ethereum. One of the famous protocols is ERC721, which defines smart contract methods for getting and transferring ownership. Some celebrities or brands, like BAYC or Azuki, also hold popular ERC721 NFTs. Ordinals Protocol has its definition and name, called Digital Artifacts. It can have owners and can be traded without paying a mandatory royalty fee. Also, its content must be fully on-chain—which means it can’t be updated.

Before we dive into Bitcoin Ordinals NFTs, let’s see how transactions work in the Bitcoin blockchain.

How do Bitcoin transactions work?

Compared with an account-based system like a traditional bank or Ethereum, Bitcoin is more complicated. Its system involves sending and receiving whole batches of Bitcoins; a transaction of Bitcoin contains one or more inputs and outputs. An input of a transaction must also be an output of another transaction. An output which is not also an input of another transaction is called an Unspent Transaction Outputs (UTXO), and the total value of UTXO that belongs to an address is the balance of that address.

In the diagram below, the ones marked in yellow are UTXO. The total value of output has to be greater than the total value of inputs, because the difference is equal to the gas fee to the miner.

One block may contain multiple transactions, and a blockchain is a collection of blocks in order. In Bitcoin, the first transaction of a block is a coinbase transaction in which the miner collects the block reward and transaction fees from other transactions of this block. Here is a real-world example: block 777,936. The number 0 transaction is a coinbase transaction which collects 6.25 BTC of block reward and 0.12833154 BTC of transaction fees from number 1 to 3,565 transactions.

So far, we have only seen the fungible features of Bitcoin. Next, let’s see how to apply non-fungible features.

Ordinal Theory

A satoshi is the smallest unit of the Bitcoin currency. 1 BTC is equal to 100 million satoshis. Ordinal theory describes how to label every satoshi with a unique number. The total supply of Bitcoin is 2,100,000,000,000,000 satoshis—which are numbered in the order in which they’re mined. When a new block is mined out, there are some new satoshis with new unique numbers in the coinbase transaction, so every satoshi can have its owner.

Satoshis only live in UTXO. When transactions destroy inputs and create new ones in outputs, satoshis transfer in a first-in-first-out order by Ordinal theory. In the following example, there are two inputs with 5 sats, which are labeled 1 to 5, and 2 sats which are labeled 11 to 12. To assign satoshi numbers to UTXO, go through each satoshi in the inputs in order (1-5 and then 11-12), and assign each to the first available slot in the outputs, which are 1-3, 4-5 and 11. The number 12 doesn’t disappear, it’s just the gas fee that’s sent to the coinbase transaction. You can check out the whole algorithm here.

Ordinal theory virtually converts these fungible token satoshis into non-fungible tokens. Next, we’re going to introduce a way to write something into the witness field of one satoshi.

What’s the witness field?

The Bitcoin script is a stack-based execution language. For a basic transaction, an input has a locking script and an output has an unlocking script, and combining one unlocking script and one locking script is an execution. The transaction is verified if the stack finally returns true. The below script, which is called Pay-to-public-key hash (P2PK), runs step by step:

  1. push <sig> and <PubK> to the stack
  2. duplicate <PubK> and push it to the stack
  3. pop <PubK>, Hash160 generates <PubK>’s hash and then push <PubKHash>
  4. EQQUALVERIFY compares the top two values, remove them if they are the same
  5. CHECKSIG verifies if <sig> matches <PubK> and pushes true if true

(Combining scriptSig and scriptPubKey to evaluate a transaction script (source))

The Segwit upgrade introduces a new witness field in transaction output for privacy and performance. For more details, you can dive into the Pay-to-Witness-Public-Key-Hash (P2WPKH) topic from Advanced Transactions and Scripting. The witness field is not designed for data storage, but it actually gives us an opportunity to store NFT’s content. With the Taproot upgrade, we can store almost 400,000 bytes of arbitrary data into the witness field.

Inscriptions

Inscriptions inscribe a satoshi with arbitrary content, such as text, image or video. With the Taproot upgrade, inscriptions are included in a new type of output called a “pay-to-taproot” (P2TR). The inscription content pushes an unexecuted conditional, which consists of an <OP_FALSE OP_IF [Content] OP_ENDIF>, into the witness field, so it won’t affect the original script. There will be two phrases, commit and reveal, because the witness field is only revealed when spending UTXO.

Ordinals inscription supports a MIME type, which means we may see various types of NFTs. The below is a text inscription containing the string “Hello, world!” (from: ordinals doc)

“`

OP_FALSE

OP_IF

 OP_PUSH “ord”

 OP_1

 OP_PUSH “text/plain;charset=utf-8”

 OP_0

 OP_PUSH “Hello, world!”

OP_ENDIF

“`

Given a real-world example: commit and reveal. At the commit stage, the transaction created two P2TR outputs and the first one is what we need to see. Then at the reveal stage, the Ordinals inscription is able to be found in the witness field.

Ordinals Protocol of course leads to some debate on social media about whether Bitcoin can be used in non-financial applications, but there are more and more wallets that start supporting Bitcoin Ordinals as well as websites that provide services for users to inscrip text or image.


Blocto is focusing on the user experience of interacting with dApps. Will Blocto support Bitcoin in the future? It may not be impossible if more and more applications appear on Bitcoin! Stay tuned to be the first to know.

References

  1. https://docs.ordinals.com/
  2. https://github.com/casey/ord
  3. https://read.pourteaux.xyz/p/illegitimate-bitcoin-transactions
  4. https://github.com/bitcoinbook/bitcoinbook
  5. https://www.moonpay.com/learn/bitcoin/bitcoin-taproot-upgrade