Torq (formerly LN Capital) on Nostr: #Bitcoin's scripting language was a genius foresight. Satoshi was thinking ...
#Bitcoin's scripting language was a genius foresight.
Satoshi was thinking light-years ahead when he added this programmability.
Bitcoin Script: A Beginner’s Guide:
1/
What is script?
Script is a simple programming language that is not Turing complete.
It lacks certain logical functionality, including loops, to prevent people from spamming the network and harming nodes.
Script logic is used to check the validity of signatures in bitcoin transactions.
If a script is valid- nodes will relay the tx to other nodes.
Script executes in a stack data structure, similar to an array.
The most common script type is Pay to Public Key Hash (P2PKH), a simple script that pays to the hash of a public key, otherwise known as an address.
However, since the advent of SegWit, we’ve seen a marked increase in the amount of Pay to Witness Script Hash (P2WSH) outputs.
There are many different types of Script, including:
Pay to Pubkey (P2PK)
Pay to Pubkey Hash (P2PKH)
Pay to Script Hash (P2SH)
Pay to Witness Pubkey Hash (P2WPKH)
Pay to Witness Script Hash (P2WSH)
Pay to Multisig (P2MS)
Pay to Taproot (P2TR)
NULLdata (OP_RETURN)
The simplest script is Pay to Pubkey.
It has one operator, “Checksig”.
All it does is compare the signature of the tx to the public key, to verify that the signature could only have been produced by the person with the private key that was used to derive the public key.
In fact, the first-ever coinbase transaction from the genesis block in 2009 was a Pay to Pubkey output.
There are tons of different functions that script can execute.
They are defined by the Opcodes used to construct the script.
Here are some of the most common Opcodes:
The SHA256 and RIPEMD160 functions are pretty straightforward.
They just compute the hash of a given input.
CHECKSIG consumes a public key and checks the validity of a signature, like in the Pay to Pubkey example.
CHECKMULTISIG consumes multiple public keys and multiple signatures, and checks to make sure that there are enough valid signatures to unlock the BTC.
You can also execute addition, subtraction, duplication, and a myriad of other functions.
TLDR;
Bitcoin Script is a simple programming language that isn't Turing complete.
It’s used to lock and unlock bitcoin, not to build applications.
Nodes run script when they receive a tx to verify its validity.
Opcodes execute different functions within a script.
We hope you learned something new from this thread!
Special thanks to Greg Walker for his amazing tutorials and graphics.
Follow us for more Bitcoin and Lightning content.
Satoshi was thinking light-years ahead when he added this programmability.
Bitcoin Script: A Beginner’s Guide:
1/
What is script?
Script is a simple programming language that is not Turing complete.
It lacks certain logical functionality, including loops, to prevent people from spamming the network and harming nodes.
Script logic is used to check the validity of signatures in bitcoin transactions.
If a script is valid- nodes will relay the tx to other nodes.
Script executes in a stack data structure, similar to an array.
The most common script type is Pay to Public Key Hash (P2PKH), a simple script that pays to the hash of a public key, otherwise known as an address.
However, since the advent of SegWit, we’ve seen a marked increase in the amount of Pay to Witness Script Hash (P2WSH) outputs.
There are many different types of Script, including:
Pay to Pubkey (P2PK)
Pay to Pubkey Hash (P2PKH)
Pay to Script Hash (P2SH)
Pay to Witness Pubkey Hash (P2WPKH)
Pay to Witness Script Hash (P2WSH)
Pay to Multisig (P2MS)
Pay to Taproot (P2TR)
NULLdata (OP_RETURN)
The simplest script is Pay to Pubkey.
It has one operator, “Checksig”.
All it does is compare the signature of the tx to the public key, to verify that the signature could only have been produced by the person with the private key that was used to derive the public key.
In fact, the first-ever coinbase transaction from the genesis block in 2009 was a Pay to Pubkey output.
There are tons of different functions that script can execute.
They are defined by the Opcodes used to construct the script.
Here are some of the most common Opcodes:
The SHA256 and RIPEMD160 functions are pretty straightforward.
They just compute the hash of a given input.
CHECKSIG consumes a public key and checks the validity of a signature, like in the Pay to Pubkey example.
CHECKMULTISIG consumes multiple public keys and multiple signatures, and checks to make sure that there are enough valid signatures to unlock the BTC.
You can also execute addition, subtraction, duplication, and a myriad of other functions.
TLDR;
Bitcoin Script is a simple programming language that isn't Turing complete.
It’s used to lock and unlock bitcoin, not to build applications.
Nodes run script when they receive a tx to verify its validity.
Opcodes execute different functions within a script.
We hope you learned something new from this thread!
Special thanks to Greg Walker for his amazing tutorials and graphics.
Follow us for more Bitcoin and Lightning content.