Bitcoin Forum
June 24, 2024, 09:05:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Compilation of Bitcoin Standard Scripts  (Read 168 times)
Felicity_Tide (OP)
Member
**
Offline Offline

Activity: 70
Merit: 61


View Profile
June 18, 2024, 05:25:27 AM
Last edit: June 18, 2024, 10:02:21 PM by Felicity_Tide
 #1

The Bitcoin script happens to be a very powerful programming tool/language used within the Bitcoin protocol primarily for transaction purposes. Every transaction output has a locking script (ScriptPubKey) and an unlocking script that helps to unlock the output.

Script basically comprises of two things, which are: Opcodes and Data. The Opcode enables several operations on the data, while the data contains public keys and signatures.

There are several scripts used in Bitcoin for transaction purposes, which I pointed out in my previous Thread . I saw the need to conduct my own research on how these scripts work and share my findings with others who might want to make reference to them in the future.

The following are examples of Bitcoin Scripts I listed, along with their explanations. Note that these are all standard scripts that fall under two main categories: Legacy and SegWit.

Legacy contains:
  • P2PK
  • P2PKH
  • P2SH
  • P2MS
  • OP_RETURN

SegWit contains:
 
  • P2TR
  • P2WPKH
  • P2WSH

Starting with Legacy
P2PK
  P2PK stands for Pay-To-Public-Key. It is a script that locks a Bitcoin output to a public key. This pattern only allows someone to receive Bitcoin on their public key. This was the first method used for receiving Bitcoin. To unlock a P2PK, a valid signature is required in the ScriptSig.

A typical example is the transaction made in block 170, as shown below. There are two separate transactions of 1B sats and 4B sats, making a total of 5B sats. When you take a close look at the address on the left, you see a P2PK.


P2PKH
  P2PKH stands for Pay-To-Public-Key-Hash. Unlike P2PK which contains a public key, P2PKH contains a public key hash also known as an address. As I stated in another of my old Thread , addresses are generated from a public key by a process called hashing. Note that P2PKH is literally the most common method used for receiving Bitcoin today. To unlock P2PKH, it requires the public key and corresponding signature. Addresses that usually begin with the prefix '1' and contain 33 to 34 characters are P2PKH addresses.


P2SH
 P2SH stands for Pay-To-Script-Hash. Unlike P2PKH, which produces an address by hashing a single public key, P2SH's address are created by hashing a redeem script. They usually have a prefix of '3' and contain about 34 characters.

Code:
3M2GhZW2FsMdfezHDBvjMEAZz6wkB32LMG

P2MS
  P2MS stands for Pay-to-Multisig. Most of us might have heard about multi-signature or maybe multi-signature wallets, where it involves more than one person signing the signature of a particular transaction. In this case, this script helps to lock Bitcoin in multiple public keys and requires at least two corresponding signatures to unlock them, or the assigned number of signature permitted to unlock them.
A general example is when a multi-signature wallet address is created for three parties, but only two parties can unlock the Bitcoin with their signatures.

Edited: https://www.talkimg.com/images/2024/06/18/hUY5d.jpeg

SegWit
P2TR
 P2TR stands for Pay-To-Taproot. P2TR uses a form of digital signature called Schnorr, which is different from the initial ECDSA. P2TR uses the Bech32m encoding scheme and is usually around 62 characters in length. P2TR is still a very new address format that is still growing in terms of adoption.

P2WPKH
  P2WPKH stands for Pay-To-Witness-Public-Key-Hash. This is a script that locks an output to a public key hash. This output can only be unlocked via the witness, unlike the P2PKH that unlocks via ScriptSig.
P2WPKH was literally an upgrade to serve as a replacement for P2PKH.

P2WSH stands for Pay-To-Witness-Script-Hash. This is also part of the SegWit upgrade but serves as a replacement for P2SH. It has a greater benefit when used because it requires lower transaction fees when unlocking a P2WSH. This is clearly unlike the P2SH. Just like P2WPKH, the output of P2WSH can also be unlocked via the witness. They usually begin with 'bc1'.

Code:
bc1q34aq5drpuwy3wgl9lhup9892qp6svr8ldzyy7c



If you want to read further in details, use the reference link

Reference is located at the bottom of the thread, though the images are screenshots made by me for illustrations which are not visually present in any of the reference material.

I am 100% open to correction as I still see myself as a learner. Pardon any of my error and share your personal opinion. You might want to also DOYR after reading this.




Public keys and Addresses - Are there striking similarities or difference:
https://bitcointalk.org/index.php?topic=5499462.msg64193874#msg64193874

Total confusion about Scriptpubkey,  Standard and non standard Transactions: https://bitcointalk.org/index.php?topic=5499658.msg64201432#msg64201432

Bitcoin Scripts: https://learnmeabitcoin.com/technical/script/#legacy

P2PK: https://learnmeabitcoin.com/technical/script/p2pk/

P2PKH: https://learnmeabitcoin.com/technical/script/p2pkh/

P2MS: https://learnmeabitcoin.com/technical/script/p2ms/

P2SH:
https://learnmeabitcoin.com/technical/script/p2sh/

P2WPKH:
https://learnmeabitcoin.com/technical/script/p2wpkh/

P2WSH:
https://learnmeabitcoin.com/technical/script/p2wsh/

P2TR:
https://thebitcoinmanual.com/articles/pay-to-taproot-p2tr/

Bitcoinmagazine:
https://bitcoinmagazine.com/technical/bitcoin-address-types-compared-p2pkh-p2sh-p2wpkh-and-more

List of address prefixes: https://en.bitcoin.it/wiki/List_of_address_prefixes
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5733


Self-proclaimed Genius


View Profile
June 18, 2024, 05:53:59 AM
Merited by vapourminer (1), Felicity_Tide (1)
 #2

P2MS
-snip-
A general example is when a multi-signature wallet address is created for three parties, but only two parties can unlock the Bitcoin with their signatures.
While the description fits, the general example shouldn't mention or display an address because:
Like P2PK, P2MS can't be encoded into an address since the script isn't "wrapped" in P2SH or P2WSH script.

The common term they use for P2MS is "Bare MultiSig" while the wrapped script we use today is commonly called as "MultiSig".
But to be specific, call them: "P2SH-MultiSig" and "P2WSH-MultiSig".

So your example belongs to P2SH.
You can use this example instead: 949591ad468cef5c41656c0a502d9500671ee421fadb590fbc6373000039b693
(notice that it doesn't show an address)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
promise444c5
Full Member
***
Online Online

Activity: 322
Merit: 182


Keep Promises !


View Profile
June 18, 2024, 08:53:59 AM
Last edit: June 18, 2024, 10:50:02 AM by promise444c5
Merited by _act_ (2), vapourminer (1), Felicity_Tide (1)
 #3

In addition to P2WSH...
The low transaction  fee is as a result of providing an increase in blocksize plus the transactions(outputs) signature gets separated from the  transaction hash,  the separated signature is referred to as witness data or witness  thus qualifying your statement below
Quote
This output can also be unlocked via the witness
Witness =>Segwit
Legacy => ScriptSig

Felicity_Tide (OP)
Member
**
Offline Offline

Activity: 70
Merit: 61


View Profile
June 18, 2024, 11:01:34 AM
 #4

The common term they use for P2MS is "Bare MultiSig" while the wrapped script we use today is commonly called as "MultiSig".
But to be specific, call them: "P2SH-MultiSig" and "P2WSH-MultiSig".

Thanks for pointing this out. The transaction is even identified as a Bare multisig from the link you sent.

Quote
So your example belongs to P2SH.
You can use this example instead: 949591ad468cef5c41656c0a502d9500671ee421fadb590fbc6373000039b693
(notice that it doesn't show an address)

Perfect. I have made the necessary adjustment.
tranthidung
Legendary
*
Offline Offline

Activity: 2310
Merit: 4090


Farewell o_e_l_e_o


View Profile WWW
June 18, 2024, 11:11:21 AM
Merited by vapourminer (1)
 #5

You can add following resources to your reference document list too.

▄▄███████▄▄
▄██████████████▄
▄██████████████████▄
▄████▀▀▀▀███▀▀▀▀█████▄
▄█████████████▄█▀████▄
███████████▄███████████
██████████▄█▀███████████
██████████▀████████████
▀█████▄█▀█████████████▀
▀████▄▄▄▄███▄▄▄▄████▀
▀██████████████████▀
▀███████████████▀
▀▀███████▀▀
.
 MΞTAWIN  THE FIRST WEB3 CASINO   
.
.. PLAY NOW ..
NotATether
Legendary
*
Offline Offline

Activity: 1638
Merit: 6911


bitcoincleanup.com / bitmixlist.org


View Profile WWW
June 20, 2024, 10:41:54 AM
 #6

You missed P2WPKH-P2SH, also known as the nested segwit script. That one is basically a P2WPKH script wrapped inside a P2SH as its name suggests, so it technically looks like any other P2SH when software that only supports the old, pre-segwit transaction format looks at it.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Felicity_Tide (OP)
Member
**
Offline Offline

Activity: 70
Merit: 61


View Profile
June 21, 2024, 07:18:23 AM
 #7

You missed P2WPKH-P2SH, also known as the nested segwit script. That one is basically a P2WPKH script wrapped inside a P2SH as its name suggests, so it technically looks like any other P2SH when software that only supports the old, pre-segwit transaction format looks at it.

I actually aim to address the ones I pointed out in a previous thread, but since this is a compilation, it makes more sense to add both nested segwits to the thread. Let me start working on it
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!