Science | Why does my Bitcoin have multiple addresses?

24-05-24 11:43
Read this article in 13 Minutes
总结 AI summary
View the summary 收起
Original title: "Web3 Newbie Series: Why does my Bitcoin have multiple addresses?"
Original source: ZAN Team


There may be many new friends like me who, when using the WEB3 wallet for the first time, happily opened the Bitcoin wallet and prepared to copy the address, suddenly found that the wallet they created actually had multiple different addresses. It was like walking to an unfamiliar crossroads, with a blank face.


Why are there different addresses? Which of these addresses should I use?


Multiple Bitcoin addresses of OKX wallet


What are these addresses


The Bitcoin community is a community with ever-evolving technology, and the development of technology produces new content. Different address formats can be considered the result of the application of new technologies. Next, let's explore the differences between different address formats.


01 Legacy Address (P2PKH)


This format was adopted when Bitcoin was first launched in 2009, so it is called the Legacy format. Because the Bitcoin address was created from a public key/private key pair at that time, it is also called a Pay Public Key Hash (P2PKH) address.


At present, it seems that Legacy type addresses will take up more space in transactions, resulting in higher transaction fees. At present, people will only use this type of address when using some old wallets that are incompatible with new addresses.


It can be found that Legacy addresses have a feature that the addresses all start with "1". This is because when generating addresses, a prefix will be added to the generated public key according to different scenarios (such as: test network/main network). After the public key with the prefix is calculated through Hash, the address will eventually start with "1".


02 Nested SegWit Address (P2SH-P2WPKH)


Compared with the traditional Legacy address, the P2SH address uses the hash of the redeem script instead of the public key hash. In layman's terms, P2PKH pays to the hash of a public key, while P2SH pays to the redemption script. Only when the recipient meets the transfer conditions of the redemption script can the funds in it be spent.


Since the object of payment is converted from a public key to a script, the flexibility is greatly expanded, and the execution logic of the redemption script can be customized. Typical applications include implementing multi-signature transactions.


Based on P2SH, if the segregated witness technology is embedded, the format of this address is the segregated witness compatible address (Nested SegWit). You can learn about the content related to segregated witness when introducing the segregated witness address. After the introduction of segregated witness technology, the volume of transactions can be reduced, thereby reducing the transaction fees.


You can see that the P2SH address starts with "3".


03 Segregated Witness Address (Native SegWit) Address


Before introducing this type of address, it is necessary to introduce the key technology inside it - Segregated Witness (SegWit). As the name suggests, segregated witness is to isolate the witness data (witness) and process it separately.


A significant advantage of doing so is that it reduces the size of transaction information, thereby reducing transaction fees. Another benefit of the reduced size is that it increases the upper limit of the size of Bitcoin block transactions from 1 MB to 4 MB.


The characteristic of the isolated witness address is that the address starts with "bc1".


04 Taproot


The advantages of the Taproot address are privacy and efficiency in complex transaction scenarios. Compared with Native SegWit, it uses the Schnorr algorithm instead of the elliptic curve digital signature algorithm. The former is more efficient in batch transaction scenarios and improves the privacy of multi-signature wallets.


The characteristic of the taproot address is that the address generally starts with "bc1q".


What address format should I choose?


Current mainstream wallets such as OKX, Unisat and other wallets support the above four addresses. Therefore, in order to reduce transaction costs, it is more reasonable to use Native SegWit and Taproot format addresses.


In addition, if you are interested in Bitcoin inscriptions, etc., then these two addresses are your best choice. Most wallets have made additional processing on the inscriptions of these two addresses, which can protect your special UTXO from being transferred incorrectly in transactions. Look for wallet addresses starting with "bc1"!


Of course, wallets with different address formats can trade funds, so don't worry.


If you want to check the balance or block information of Bitcoin, you are welcome to use ZAN's node service. We provide a rich API for developers to use. API document details: https://docs.zan.top/reference/zan_getbalance-enhance


A little deeper - introduction to key technologies


After the above introduction, everyone has a preliminary understanding of the wallet. Then, as I am very interested in some technical acquisitions in the wallet, let's take a look at the mysterious technology inside.


01Redeem Script


When introducing P2SH, we know that this is a technology for redemption script transactions. So what is a redemption script and what is its role in the Bitcoin ecosystem.


Before introducing the redemption script, we need to introduce the basic structure of Bitcoin transactions.


The following is a typical P2PK transaction, where the address starting with 04ae wants to transfer 10 BTC to the address starting with 15kD. The account with the 04ae address needs to show others on the chain that he does have the right to use this account (owns the private key), so he needs to provide a signature (ScriptSig) in this transaction to prove his identity.


In addition to obtaining the signature, the verifier also needs to find the output script of the previous transaction corresponding to the UTXO. The two scripts are spliced together to form the redemption script. The function of the redemption script is to prove the legitimacy of the transaction.



In this transaction, you can see that the signature and the output script are both a computer instruction. OP_PUSHBYTES means PUSHing a piece of data into the stack. First, in ScriptSig, 04ae signs the entire transaction with his own private key, and the signature will be pushed into the stack. Then push the public key into the stack, and finally in OP_CHECKSIG, use the public key to decrypt the signature and compare whether the transaction is consistent. If it is consistent, it means the identity is valid.


In addition to this P2PK method, the redemption script can also implement different identity authentication methods such as P2PKH and P2SH.


02 Segregated Witness


From the above introduction, we can know that the newer wallet formats currently use the segregated witness technology, so what is a witness and how is it isolated?


The Witness here can be considered as the script signature (scriptSig) information in the basic structure of Bitcoin. Segregated witness extracts it from the basic structure and places it in a new data structure.



As can be seen in the figure above, the only necessary content in the transaction is the information of the transaction source and the transaction output. The size of the transaction has been reduced. Since the yellow part (the total size of the transaction) has a size limit, the signature of the transaction is transmitted separately to allow a block to accommodate more transactions. In addition, since the content of the signature part is not calculated when calculating the signature of the transaction, the problem of transaction ductility can be effectively solved.


The following is a P2TR transaction. You can see that this transaction has an additional Witness part. Its function is to verify the legitimacy of the transaction. After using Witness instead of ScriptSig, the way to verify legitimacy is still the same, that is, by using the public key to decrypt the Witness signature and verify whether the content of the transaction is consistent. Only when the node needs to verify the legitimacy of the transaction will it request the Witness information.



To summarize, the segregated witness is to transmit the content of the transaction signature part and the rest of the content separately, thereby reducing the size of a single transaction and increasing the capacity of the entire block. In addition, since the content of the signature part is not counted when calculating the Hash value of the transaction, the problem of transaction ductility can be effectively solved.


Original link


欢迎加入律动 BlockBeats 官方社群:

Telegram 订阅群:https://t.me/theblockbeats

Telegram 交流群:https://t.me/BlockBeats_App

Twitter 官方账号:https://twitter.com/BlockBeatsAsia

PleaseLogin Farcaster Submit a comment afterwards
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit