
Author: Captainz, former gametaversedao researcher Source: X,@hicaptainz
In the past two weeks, when I was studying the BTC ecology and various inscription projects, I found that few articles can clearly introduce the principles and technical details: for example, how the transaction was initiated when the inscription was cast, and the SATS in UTXO in UTXOHow is it tracked, the inscription content is placed in the script, and why does the BRC20 need to operate twice when transferring?I find that I do n’t understand these technical details, it is difficult to understand the differences between BRC20, BRC420, Atomicals, Stamps, Rune Runes, this article will penetrate the basic knowledge of the BTC blockchain and try to answer the above questions.
BTC’s block structure
Blockchain is essentially a multi -user bookkeeping technology. In terms of computer science terms, it is a distributed database. The records (accounts) for each time form a block, and then expand the ledger according to the order of time.
>
We used Excel to make a form to explain the working principle of the blockchain.An Excel file represents a blockchain, each of which shows a separate form. The block will be packaged from 560331, 560332. Until the latest 560336.560336 will be packaged in the block.The main part of the block is the most common duplex bookkeeping method in the accounting field. On one side of the address, Debit is the INPUTS FROM, and the other address is written as the outputs to.Value corresponds to the corresponding address of the corresponding address.The number of Inputs coins will be greater than the number of Outputs coins. The difference is the transfer fee at the user level, and it is also a handling fee obtained by the miner (bookkeeper).The block head will obtain the height of the previous block, the hash value of the previous block, the establishment time (timestamp) of this block, and the random number.So, as a decentralized bookkeeping technology, who will grab the bookkeeping rights of the next block?Relying on this random number and corresponding hash value.Miners with computing power calculate the hash computing of the current blocks, and the first miners who get the qualified hash value have the next block bookkeeping right and win the block reward and transfer fee.Finally, the script area can be used to make some expansion applications. For example, the script OP_RETURN can be used as an attachment bar.It should be noted that in the actual block, the script area is attached to the input and output information, not a separate area.For example, the script attached to the INPUT is the unlocking script (scriptsig), which requires the wallet address to perform the private key signature authorization to allow the transfer.The condition is “people with the corresponding private key can consume”).
>
>
The above two figures are data structure tables of the original Input and Output. At the execution level, the script is manifested as the attached parameters of the transaction information.Data).
Isolation Witness and Taproot#
Although the Bitcoin network has been operating for more than 10 years, there have been no significant events, but the transaction costs have soared to high points that are no longer feasible.Therefore, Bitcoin developers have been discussing how the best expansion of the network to deal with the growing transaction volume in the future.
In 2017, the debate reached a climax, and the Bitcoin development community was divided into two factions. One faction supported the use of soft forks to implement the function of SEGWIT, and the other was a “large block” school that supported direct block expansion.
We mentioned above that understanding that the lock script needs to use private key to generate “witness data”, so can we separate this witness data from the block, so as to increase the number of transactions that can be accommodated by each block?The Segregated Witness was officially activated in August 2017.Its implementation method is to divide all transaction data into two parts, one is the basic information data of the transaction, and the other part is the signature information of the transaction, and saves the signature information in a new data structureIn the new block, which is called “Witness” and is transmitted separately from the original transaction.
>
Technically, the implementation of SEGWIT means that transactions no longer need to include witness data (not occupying 1MB spaces that Bitcoin originally arranged for block).Instead, at the end of a block, an extra independent space is created for witnessing data.It supports any data transfer and has a discount “block weight”, which cleverly keeps a large amount of data in the block size of Bitcoin to avoid the needs of hard forks.In this way, the size of the transaction data of Bitcoin transactions increases the upper limit, while reducing the transaction cost of the signature data.Before the SEGWIT upgrade, the capacity of the Bitcoin was 1 MB, and after SEGWIT, although the capacity of the simple transaction was still 1m, the size of the isolation witness space reached 4 MB.
Taproot was implemented in November 2021. It consists of three different Bitcoin improvement proposals (BIP), including: Taproot, Tapscript, and its new digital signature scheme named “Schnorr Signature”.Taproot aims to bring many benefits to Bitcoin users, such as increasing transaction privacy and reducing transaction costs.It will also allow Bitcoin to perform more complex transactions, thereby broaden application scenarios (adding some operating code OPCODES).
These updates are the key promotion factor of Ordinals NFT, which stores NFT data in Spent Script (witnessed data space) in the Taproot script path.This upgrade makes it easier for structured and storage to witness data, laying the foundation for the “ORD” standard.With the relaxation of the data requirements, assuming that a transaction can fill the entire block with its transaction and witness data-the limitation of the block size (witness data space) of 4MB-greatly expand the type of media type that can be placed on the chain.Essence
Some people may ask, since there are some string in the script, is there no restriction on these string?What if these scripts are really executed?If the content is placed casually, will the error code refuse to get out?This is to mention the OP_FALSE instruction.OP_FALSE (also expressed in Bitcoin scripts as “0”) ensures that the execution path in the script language will never enter the OP_IF branch and keep it in an unremitting state.It acts as a place or air operation in the script, similar to “annotations” in advanced languages to ensure that subsequent code is not executed.
>
UTXO transfer model
The above are the basic principles of BTC from the computer data structure. We will discuss the UTXO model from the financial model.
UTXO is the abbreviation of Unspent Transaction Outputs. Chinese translation is “no transaction output without spending”. It can actually be understood as funds that are not transferred from the surplus during a transfer.So why does Bitcoin use such a concept?This starts with the account trading model and account balance model of the bookkeeping method.
Because we have been in the centralized system for too long, we are very accustomed to the accounting method of account balance models.When the user A transfers 100 yuan to the user B, the bank will check whether there is 100 yuan on the bank account of A.The stroke is completed.
However, the Bitcoin’s bookkeeping algorithm does not have the concept of balance.There is only a transaction recorded on the distributed ledger of the blockchain, and it will not directly record the current balance of an account (the record balance generally requires a special server node to record, then centralized).Suppose the current user A balance is 1,000 yuan. If the user A transfer to the user B to 100 yuan, the transfer will be recorded:
Transaction 1 User A to user B transfer 100 yuan
Transaction 2 User A to user A transfer 900 yuan (UTXO) (UTXO)
>
Although the transaction here is a transaction, in terms of function, he played the role of account balance, indicating that there is still 900 yuan left on the account of A’s account after completing the 100 yuan transfer.
So the question is, why do you have to build such a UTXO?Because only transactions can be recorded on the BTC blockchain, the account balance cannot be recorded.Without this UTXO, you need to calculate the balance of the balance and accumulate all the transactions and accounts of all the account. This is a very time -consuming and computing resources.The appearance of UTXO cleverly avoids the pain points of all transactions when calculating the balance.
UTXO has a characteristic, that is, like a coin, you can’t open it. So how to get enough input amount during the transaction process and how to find zero?We can use the coin to make an analogy (in fact, it is better to automatically translate it into “coin” when you see the word UTXO).
Xiaoming transferred 1 Bitcoin for Xiaogang.The whole process is like this. Xiaoming wants to collect enough input. For example, in the previous transactions corresponding to Xiaoming’s address, a face value of 0.9 was found.Xiaoming found an UTXO with a face value of 0.2, so that there will be two inputs in this transfer transaction.At the same time, there will be two output, one is to the little pigrant address, and the face value is 1 Bitcoin.Another address to Xiaoming’s own address is 0.1 Bitcoin. This output is to find zero (this example ignores GAS).
In other words, there are two coins in Xiaoming’s pocket, one face value is 0.9 and the other is 0.2. At this time, Xiaoming needs to pay a coin with a face value of 1, and you need to hand over these two coins to Xiaogang at the same time.Zero 0.1 to Xiaoming.Therefore, the essence of this accounting model is to avoid the “calculation balance” through the action of “finding zero”.
The ordering system of the Ordinal protocol
The Ordinal protocol can be said to be the source of this round of BTC ecological explosion. It is to break down the homogeneous BTC as the smallest unit SAT, and then mark a serial number for each SAT.How did that do?
We know that the total amount of BTC is 21 million, and a BTC can be split to 100 million (SAT), so the smallest unit of BTC is SAT.Homogeneous tokens FT.We now try to allocate a serial number to these SATS.
When talking about the block data structure earlier, we mentioned that the transaction information needs to indicate the address and amount of INPUT and the address and amount of Output.Each block contains two parts of transactions: BTC’s delivery and transfer fees.The handling fee trading must have Input and Output, but because the outlet reward is a BTC generated by out of thin air, there is no INPUT address. Therefore, this “Input from” field is blank, also called “Coinbase transaction”.The total number of BTCs is derived from this Coinbase transaction, which is also ranked first in all block transactions.
The Ordinal protocol stipulates as follows:
-
Number: Each SAT is numbered in the order of their mining
-
Transfer: According to the advanced rules of advanced first, transfer from the input of transaction to the output
Article 1 The rules are relatively simple, and it determines that the number can only be generated by the coinbase transaction in the mining reward.For example, if the first block of mining rewards is 50 BTCs, the first block will be assigned [0; 1; 2; …; 4,999,999,999]At 50 BTC, the second block will allocate SATS with a range of [5,000,000,000,000; 5,000,000,000; 5,000,000,000,001; …; 9,999,999,999]. -
Submitting (Commit) stage: At this stage, users submit their information (such as voting selection or bidding price), but this information is encrypted.Generally, users will generate the hash value (that is, the encryption of information), and then send this hash value to the blockchain.Due to the characteristics of the hash function, they can generate a unique output (hash value), which is irreversible for the original information.This means that the original information cannot be inferred from the hash value.This process ensures the confidentiality of information when submitting.
-
Reveal stage: After a booked time, users must reveal their original information and prove that it matches the hash value submitted earlier.This is usually done by submitting the original information and any additional data (such as random numbers or “salt”) used to generate hash.The network then verifies whether the hash value of this original information is the same as the hash value submitted before.If matching, the original information is accepted as valid.
-
Create costs
To create a P2TR transaction, users first define a conditional condition, such as a single public key or more complicated script, specifying the requirements for spending Bitcoin (for example, multiple signature wallets or smart contracts). -
Generate taproot output
The user then generates a Taproot output, which includes a single public key (the public key represents the condition of spending).This public key is derived from the combination of the user’s public key and the hash of the user, using a process called “TWEAKING”.This ensures that the output looks like a standard public key, making it difficult to distinguish it with other transactions on the blockchain. -
Spend bitcoin
When users want to spend Bitcoin, they can use their single key (if the cost is met), or disclose the original script and provide the necessary signatures or data to meet the cost.This is done by using TapScript, which allows more efficient and flexible execution of costs. -
Verification transaction
Miners and nodes were subsequently verified by checking the SchnorR signatures and data and spending conditions provided by the inspection.If the conditions are met and the transaction is considered valid, Bitcoin can be expected. -
Enhanced privacy and flexibility
Because P2TR transactions only disclose the necessary costs when spending Bitcoin, they maintain high -level privacy.In addition, the signatures of MAST and Schnorr make it can efficiently encode multiple costs and allow more complicated and flexible transactions without increasing the overall size of the transaction.
>
The more difficult part here is that because UTXO actually contains a lot of Cong, every Cong in this UTXO looks the same. How can we sort them?This is actually determined by the second rules. Take a simple example:
I first assume that the smallest division unit of the BTC is 1, which has a total of 10 blocks, and the outlet rewards of each block are 10 BTCs, that is, the total amount is 100.We can give these 100 BTCs a serial number of (0-99).If there is no transfer situation, then we only know that the 10 BTC numbers of the first block are (0-9), and the 10 BTC numbers of the second block are (10-19), until the tenth areaThe 10 BTC numbers of the block are (90-99).There is no output because there is no cost, and we can only give a number range to each 10 BTC.
Suppose two expenditures are added to the second block, one is 3BTC, and the other is 7 BTC with “find zero”, which corresponds to 3 BTCs for others and finds 7 BTCs for themselves.At this time, in the list of block transactions, it is ranked first in the 7 BTC rankings that you find zero (the corresponding number is 10-16) and the 3BTC ranking for others (the corresponding number is 17-19).This confirms the sequence collection of SATS contained in an UTXO through the transfer of Output.
Note that every SAT is not UTXO! Since UTXO is an indispensable minimum trading unit, SAT can only exist in UTXO, and UTXO contains a certain range of SATS, and can only generate new output after spending a certain UTXO.Sepaled SATS number.
As for how to express this “number”, Ordinal supports multiple forms, such as the “integer method” mentioned above, other decimal decimal methods, degree method, percentage method, and pure letters naming method.
>
After SATS has a unified serial number, you can consider inspection.We mentioned above that we can upload any data type files in the 4M size of the data area, whether it is text, or pictures and videos. After uploading, the file will automatically convert to the Taproot script area of hexadecimal storage.So, 1 UTXO corresponds to a Taproot script area, and these UTXO will also include many SATS (overall SATS sequence collection. In order to prevent dust attacks, the number of bitcoins in a single UTXO cannot be less than 546 Cong Cong).In order to facilitate the record, the Ordinal protocol artificially stipulates that “the first SAT number using this sequence collection represents the binding relationship” (the original word of the white paper is the first Output number)) The UTXO of the number SATS directly uses the 17th to replace the collection and the inscription content binding.
Casting and transfer of Ordinal assets#
The Ordinal NFT is obviously uploaded to the script in the isolation testimony area and binds it to a SATS sequence to gather to issue NFT assets on the BTC chain.But there is also a problem here. The script of the isolated witness area contains the unlocked script of Input and the lock script of Output. So which script is the content?The correct answer is that both are available.Here I have to mention the Commit-Reveal mechanism in blockchain technology.
The Commit-Reveal mechanism in the blockchain is a protocol for ensuring fairness and transparent processing of information.This mechanism is usually used in the scenario that needs to be submitted to hidden information (such as voting or bidding), and then reveals this information at a certain point in the future.The Commit-Reveal mechanism is divided into two stages: the commission (Commit) stage and the revealed stage.
As mentioned earlier, the content of the inscription is to be binded with the SATS sequence set contained in UTXO. UTXO is an output in the block, so it must be attached to the lock script of Output.However, the full node of BTC needs to be a local maintenance and transmission of all UTXO sets in the entire network.Imagine that if there are 10,000 4M video files uploaded directly to 10,000 UTXO lock script, then all the full nodes need to have high storage space and ultra -fast network speed.EssenceTherefore, the only solution is to put the content in the unlocking script in INPUT, and then let this content “point” to another output.
Therefore, the casting of Ordinal assets needs to be divided into two steps (the wallet is to combine these two steps. When constructing a transaction, and at the same time, the father-son transaction is constructed.fee).
During the casting stage, the user first needs to upload the hash value of a file to the lock script in the UTXO of the COMMIT transaction (the address of the A address to the B address of the B address).UTXO database space.Secondly, the user constructs a new transaction (the address B address is transferred to yourself), which is called a Reveal transaction. At this time, the INPUT needs to use the UTXO containing the file hash value in the previous Commit transaction, and the INPUT’sThe unlocking script must contain the original inscription file.The description of the original words in the white paper is “First of all, in the Commit, create a taproot output submitted to the script containing the inscription content. Second, in the Reveal transaction”” “
During the transfer stage, the Ordinal NFT and the BRC20 are slightly different. Because the Ordinal NFT is a overall transfer, you only need to transfer the NFT that binds a certain UTXO to the receiver, similar to ordinary BTC transfer.However, the BRC20 is divided into two steps because it involves a custom amount transfer. The first step is called inscription “transaction” transfer “, and the second step isThe inscription carrier transaction is actually similar to the casting process of Ordinal NFT, which implies the COMMIT-Reveral Father and Son transaction pair. The second step transfers are similar to a ordinary Ordinal NFT transfer.EssenceSome wallets will build these three transactions (three -generation transactions of their children and grandchildren) at the same time, so as to save time and GAS.
>
In summary, the Commit transaction is used to bind the inscription content (hash value of the original content) with the SATS (UTXO) with serial number, and the REVEAL transaction is used to display the content (original content).This father -son transaction has completed the casting of NFT.
P2TR and an example#
The above technical discussion on casting is not over, because some people will be curious, how does the Reveal transaction verify the inscription information in the Commit transaction?Why do I need to transfer each other’s two addresses when constructing a transaction?I didn’t see two wallets when I was playing inscriptions.Here we need to talk about one of the major upgrades of Taproot P2TR.
P2TR (Pay-to-Taproot) is a new type of Bitcoin transaction introduced by Taproot.P2TR transactions spend Bitcoin by allowing users to use a single public key or more complicated script (such as multiple signature wallets or smart contracts) to achieve higher privacy and flexibility.This is achieved by signing the signatures of Merkleized Abstract Syntax Trees (MAST) and Schnorr. These technologies can effectively encode a variety of costs in a single transaction.
The above is the application method of the Commit-Reveal mechanism in P2TR. We use a practical case to explain.
Use the blockchain browser https://www.blockchain.com/ Let’s study the casting process of a Ordinal image NFT, including the previous COMMIT-Reveal.
First of all, we see that the Hash ID of the Commit transaction is (2DDF90DDF7C929C8038888FC2B7591FB999C3BA3C7B49D54D01F8DB4AF585C).It can be noted that the output of this transaction does not contain inscription data (in fact, the hash value of the 16 mechanism picture file), and there is no relevant inscription information in the webpage.This output (BC1P4MTC …) address is actually a temporary address generated by the “TWEAKING” process (representing the public key of the script unlocking condition), and a private key with the main address (BC1PG2MP …).The second UTXO in this transaction belongs to the “zero” operation of the return.In this way, the binding of the inscription content and the SATS contained in the first UTXO.
>
Then, we checked the Reveal transaction record, and its hash ID is (E7454DB518CA3910D2F17F41C7B215D6CBA00F29BD186AE77D7FCD7F0BA7C0E1).Here, we can see the information of Ordinals Inscript.The input address of this transaction is the temporary output address generated by the previous transaction (BC1P4MTC …..), and the unlocking script of the Input contains the hexadecimal file of the original picture, while the output 0.00000546btc (546 Cong)This is to send this NFT to its own taproot main address (BC1PG2MP …).Based on the FIRST In First OUT principle and “the first Cong Number of the first Output is bound”. Although the number of SATS contained in the two UTXOs has changed, the binding SAT serial number remains unchanged.Therefore, we can find Cong, where the inscription is located in (SAT 1893640468329373).
(Https://ordinals.com/sat/1893640468329373)
>
These two transactions (belonging to the father and son transaction) will be submitted to the memory pool by the wallet at the same time when casting, so it only takes a GAS, and it is also a great chance that it will be recorded and broadcast by the miners in the same block (in the above examples (the above examplesThe two transactions exist in the block 790468).Miners and nodes were subsequently verified by checking the Schnorr signature provided by Input in the Reveal transaction and the hash values of hexadecimal pictures and the 16 -proof picture hash values in the Output script in the Commit transaction.If the two are the same and the transaction is regarded as valid, the UTXO of this bitcoin can be spent, then these two transactions are naturally permanently recorded in the BTC’s blockchain database.EssenceIf the two hash values are different, the two transactions will be canceled and the inscription fails.
BRC20 protocol and indexer
For the Ordinal protocol, we are engraved with a text, which is the text NFT (corresponding to the LOOT on the Ethereum), the inscription is a picture, it is the picture NFT (corresponding to the PFP on Ethereum), which is inscribed for a period of music. It is the audio NFT.So what if we are engraved with a code and this code is a code of “issuing FT homogenization tokens”?
The BRC20 is to deploy, cast and transfer token by using the Ordinal protocol to deploy, cast and transfer to JSON data format. JSON contains some code fragments to describe the various attributes of Token, such as its supply, maximum casting unit and unique code.We have already said in the previous article that the essence of the BRC20 token is the semi -homogeneous token SFT, that is, in some cases, it can be used as NFT transactions, and some cases can be used as FT transactions. This kind of pair isHow can the control of “different situations” be controlled?The answer is the index.
The indexer is actually a bookkeeper, which is used to record the receiving information in the database.In the Ordinal protocol, the indexes determine the changes of sATS in different addresses by tracking the Input and Output.In the BRC-20 protocol, the indexes have one more function: record the changes in different addresses in the inscription.
Therefore, we can see different token existences from the perspective of the bookkeeper: the BRC20 protocol tokens actually exist in a triple database.The first Layer1, the bookkeeper is BTC miner, the database type is the “chain database”, and the BTC generated is FT assets.The second layer2, the bookkeeper is the ORDINAL indexer, the database type is the “relational database”, and the SATS with serial number is NFT asset.The third layer3, the bookkeeper is the BRC20 indexer, the database type is the “relational database”, and the BRC20 asset generated is FT assets.当我们把BRC20 按照“张” 来算的时候,站的角度是ordinal 索引器(由该索引器记录),它自然是NFT;当我们把BRC20 按照分拆好的“个” 来思考的时候(Especially after recharging to centralized exchanges), the angle of the station is the BRC20 index (recorded by the index record or the server of the centralized exchange), which is naturally FT.From this we can get a conclusion that the existence of semi -homogenized tokens SFT is caused by different levels of bookkeeppers.
Blockchain is not a distributed database, so there is a miner’s accountant to jointly maintain this “chain database” (because only the chain database can be truly decentralized).But when we went around, we still returned to the old path of centralized “relational database”.This is why the order of the Ordinal Agreement some time ago, the promoter of the BRC20 protocol, the Unisat wallet for the indispensable essential reason for whether the indexer wants to upgrade the stir -frying.
However, after more than ten years of development, the industry has accumulated a lot of experience in “decentralization”. Can the indexes use the “chain database” to replace the relational database?Can you adopt fraud or ZKP to ensure safety and decentralization?Will the DA demand of the Bitcoin ecosystem overflow to other DAs to promote multi -chain ecological prosperity and integration?I seem to see more possibilities.
Reference information
https://www.aixinzhijie.com/books/261/master_bitcoin/_book/
https://learnblockchain.cn/article/5717
https://zhuanlan.zhihu.com/p/361854961
https://www.odaily.news/post/5187233
https://learnblockchain.cn/article/5376
https://www.panewslab.com/zh/articleDetails/1301r1ibp79c.html
https://docs.ordinals.com/inscriptions.html
https://thebitcoinmanual.com/articleS/pay-taproot-p2tr/