[Taproot y Firmas Schnorr] -Steemit Crypto Academy | S5W6| Homework Post for @pelon53

in SteemitCryptoAcademy2 years ago

P2SH vs P2PKH

P2SH

P2SH also known as Pay-to-script- Hash was incorporated in 2012 to Bitcoin which changes the way it authenticate trànsactions. This P2SH address are special types of address in the Bitcoin network that allows for the creation of addresses that can send or receive trànsaction until after some instructions or criteria has been met which will then unlock the balance of the address that contains the Bitcoin.

In other words, P2SH is a script which is used on Bitcoin network that allows one to lock Bitcoin in the script hash and then requires one to provide the original script whenever they want to unlock the Bitcoin during trànsaction. It makes it possible for one to create a customized script that can be shared to other people who one intends to transact with. Instead of trànsactions been sent to the public key they are usually sent to the customized script and this address attached to the script hash usually begin with 3 instead of 1.

The P2SH feature is very useful in trànsactions that needs more than one signature to authorize a trànsaction and this is called multi-sig which is used on the Bitcoin network. The P2SH makes use of two scripts which are known as the SCRIPTSIG and SCRIPTPUBKEY. The scriptSig can be called the unlocking script as it is used to unblock the trànsaction that is about to be carried out it usually makes use of the public key and digital signature while the ScriptPubKey is the locking script which is sometimes known as the Bitcoin address as it contains the public key hash.

20211225_140505.jpeg

A graphical example of how the P2SH transaction works using the scripts explained above.

This is a ScriptSig shown in the screenshot above, the ~ stands for the signature which is two while the K1, K2, K3 stands for the keys which are three then the OP code, this are what makes you the scriptSig.

20211225_140510.jpeg

From the screenshot above, it is noted that it is a multi-sig trànsaction, we see that there was two signature out of three which belongs to the users trànsacting the token which is needed to authorize the trànsaction and there is the operation code which is used to verify the two signatures to ensure that it corresponds with the three keys in that particular trànsaction, it is also neccessary in unlocking the operation of the operation is successful.

After the success of the scriptSig, it then leads us to ScriptPubKey as shown in the screenshot above, the OP_HASH 160 is used to generate the SHA-256 and the RIPEMD-160 Hash which is also responsible for letting us know if the ScriptPubKey will be unlocked as long as the ShA-256 generated is corresponding to the ScriptSig.

P2PKH

P2PKH is a script which is used on Bitcoin network that has been created since January 2009 just after Bitcoin mining started. Its full form is pay to pubkey Hash which means that trànsactions carried out with this script sends trànsactions to the hash of the receiver's public key. It provides more security and less stressful when sending and receiving funds on blockchains network and this is because it uses two features which are the public key hashing and error detection.

The public key hashing is used to ensure that the public keys aren't visible to other users and this gives more encryption to a user private key and the public giving increased security. Pubkey hash is a shorter alphanumeric character compared to the public keys which makes it easier to manage and shorter.

Error detection is the second feature of the P2PKH, it helps in detecting the errors that could occur in a trànsaction on the blockchain, let's take a deeper look at how it does that. Whenever a recipient of a fund wants to receive he or she shares their wallet address to the sender. Converting the pub key to an address is a two step process, firstly the pubkey is hashed twice by first using the SHA-256 algorithm and the hash gotten is then hashed again with the RIPEMD+160 algorithm, this is what produces the pubkey hash that will be used in the P2PKH trànsaction.

The pubkey hash is then converted into an address by first adding the version byte which is usually 0x00 are added to the begining of the pubkey hash, after which the new string is hashed with SHA-256 then the first four bytes of the result is added to the end of the RIPEMD-160 hash we got earlier, then this is converted to a base 58 encoding string which is the address needed. The blockchain software is able to recognize if the address is invalid it won't create a transaction.

20211225_140519.png

WORKING MECHANISM OF P2PKH

20211225_140525.png

SOURCE: komodoplatform

If for example I want to send BTC to a friend using the P2PKH script, before the trànsaction can start, my friend will first need to generate a private or public key, which will then be converted to a pubkey hash and then converted again into an address. My friend then sends me the Address and I send the payment to my friends new address.

If paradaventure My friend exposed are private key then another person can gain access to the funds that I will be sending to him because anyone who provided the digital signature from the private key is the one who will have access to the funds. This way only the pubkey hash and address is used for the trànsaction and no one knows each other public key and this enhances security.

DIFFERENCES BETWEEN P2SH AND P2PKH

The major difference between the P2SH and P2PKH is that the P2PKH is the first script created for Bitcoin network and has some limitations such as it's incompatibility with segwit feature whereas the P2SH is very much compatible with the segwit feature. Another difference is that the P2PKH address starts with 1 while that of P2SH starts with 3, also the P2SH uses lower gas fee compared to the P2PKH and the P2SH allows for multi sig unlike the P2PKH.

Example:

It is required to transfer 10 BTC that belong to a 3 of 5 multi-signature portfolio, to the MTC company, for the purchase of some equipment using the ScriptSig and the Scriptpubkey.

To send 10 BTC using a 3 of 5 multi-sig portfolio, it is required that 3 out of the 5 authorized signature needs to be use to authorize the trànsaction to send the BTC to the company. The OP_CHECKMULTISIG is used to verify that the three signatures are corresponding with the 5 keys that is used in the trànsaction and it's eligible to unlock the operation.

20211225_140532.png

For BTC trànsactions they make use of UTXOs which are the unspent trànsaction outputs, so if we will be sending 10BTC to MTC company, usinng UTXOs for the transaction the inputs for MTC might be;

Input 1 - 2.5 BTC
Input 2 - 2.5 BTC
Input 3 - 2.5 BTC
Input 4 - 2.5 BTC

The company then recieves 10 BTC at the end of the transaction although it's sent in fractions. In other for the Company to be able to spend their BTC, each BTC they receive contains a Scriptpubkey which is the lock and must be satisfied with the ScriptSig which is the key to unlock the trànsaction.

In other words when We send the transaction to the company and the 3 out of 5 signatory has signed and it has been confirmed to be for the key, the output BTC we send to the company that has been received can only be spent when the conditions laid out by our scriptPubKey are satisfied, the company will need to create an input which contains an unlocking script the scriptSig which must meet the condition set by the senders.

Just like the image above the ScriptSig cknatins the digital signature and a public key which is needed to unlock the trànsaction while the Scriptpubkey is a public key hash or an address, the process works step by step where the unlocking must be done first and locked when recipient recieves the BTC.
Using Schnorr signatures

20211225_140537.png

20211225_140541.png

Source: Here
If the schnorr signatures has been used it gives room for a better privacy and scalability and also reduces the gas fee that will be paid in that the higher the signatory needed the higher the size of the transaction and the gas fee is based on the size of a trànsaction. The schnorr signatures allows all signatory to combine their signatures into a single signature which can be called a master signature and it will still be the same length as the regular signature and this saves time and space. It also makes it difficult for those monitoring the transaction bit to know who signed the trànsaction.

WILL TAPROOT AND SCHNORR FIRM HELP THE PRIVACY OF BITCOIN NETWORK.

The Taproot upgrade consist of 3 proposals to increase the Bitcoin network which includes the privacy, the upgrade uses the Taproot, Tapscript and also the Schnorr signatures. This upgrade enhances security as well as lower gas fee. The schboor signature takes multiple keys and put them into a single signature and this makes approving of transactions more secured since no one knows who is signing the trànsaction and hackers don't know who to traget.

Also Taproot gives possibility to hiding the Bitcoin script used in a transaction but only make it obvious that a peer to peer trànsaction has been run. This way there is more anonymity and security on the Bitcoin network.

USING BLOCKCHAIN DEMO TO WRITE MESSAGE

First, we load the website of the blockchain demo by clicking on the link Blockchain Demo, then we input the message we want to generate it's signature which is the SCHNORR SIGNATURES as shown below.

20211225_140545.png

After inputting the message we click sign to generate the signature, then we navigate to verify and verify the signature.

20211225_140548.png

After verifying and we remove any character from the signature and we click verify, the page shows red and this means the signature isn't aligning with the message and it's wrong.

In conclusion, the use of schnorr signature and the Taproot in the Bitcoin network is a good upgrade for the network and it will bring in more investors and also give old users more privacy as everyone cherishes their privacy.

@pelon53
#club5050

Sort:  
Loading...

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63464.16
ETH 3111.33
USDT 1.00
SBD 3.98