0% found this document useful (0 votes)
92 views

Script U-III

The Bitcoin scripting language, also called Bitcoin Script, is a simple stack-based programming language that enables transaction processing on the Bitcoin blockchain. It allows for various transaction types including pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH). Bitcoin Script transactions use locking and unlocking scripts to verify transactions by combining and executing the scripts. Common uses of Bitcoin Script include multi-signature wallets, time-locked transactions, escrow transactions, and applications like the Lightning Network.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Script U-III

The Bitcoin scripting language, also called Bitcoin Script, is a simple stack-based programming language that enables transaction processing on the Bitcoin blockchain. It allows for various transaction types including pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH). Bitcoin Script transactions use locking and unlocking scripts to verify transactions by combining and executing the scripts. Common uses of Bitcoin Script include multi-signature wallets, time-locked transactions, escrow transactions, and applications like the Lightning Network.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Bitcoin Scripting language

 Bitcoin scripting language is simply called forth.


 Bitcoin Script is a simple, stack-based programming language that enables
the processing of transactions on the Bitcoinblockchain
 It is very easy to write and supports cryptographic operations.

Some of the properties of bitcoin scripting language are:

The Bitcoin scripting language consists of four main attributes:

 Forth-like: Script is simple, stack-based, and processed from left to right.


 Stack-based: uses stack data structure for executing the instructions;
Executing Script involves two stack operations PUSH and POP.
 Reverse-polish Notation:also called postfix notation, is a mathematical
notation in which operators follow their operands,

 Turing incomplete: It is a simple language that is not Turing complete,


meaning it lacks several logical functions, no loops or complex flow control
capabilities.

Bitcoin Transaction:
What Is a Transaction?
A transaction is a completed agreement between a buyer and a seller to exchange
goods, services, or financial assets in return for money.

A Bitcoin transaction is a transfer of bitcoin from one address to another. The valid
transaction must be signed by the sender.

The principal properties are:

 Amount – the amount of bitcoin, in satoshis


 Inputs – the source of funds
 Outputs – the recipient or change destination(s)
 Lock time – the earliest the transaction can be broadcasted (optional)

Example:

Mark wants to send 1 BTC to Jessica. To do this, he uses his private key to 'sign' a
message with the transaction-specific details.
Inputs. This contains information about the bitcoin previously sent to Mark's
address. For example, imagine Mark previously received 0.6 BTC from Alice and
0.6 BTC from Bo

Amount. the amount Mark wants to send is 1 BTC.

Outputs. There are two outputs. The first is 1 BTC to Jessica’s address. The
second is 0.2 BTC returned as 'change' to Mark. This second output is calculated as
the total of the inputs [0.6 + 0.6 = 1.2], minus the amount Mark wants to send [1
BTC].

If the transaction contains multiple inputs, this means the amount is coming from
different bitcoin addresses. Having multiple output means, funds are being
distributed to different wallet addresses.

 A public key is derived from a wallet address and is used to facilitate transactions,
while a wallet address is used to identify a destination for cryptocurrency
transactions.
 A private key is an alphanumeric code that acts similarly to a password. Private keys
are used to authorize cryptocurrency transactions. Your private key is generated by
your wallet and is used to create your public key (your wallet address) using
encryption.

What is a digital signature?


The transaction must be signed using your private key through a cryptographic process.

Bitcoin uses public-key cryptography to create a “key pair” (a pair of keys) that controls
access to bitcoins.

 The key pair consists of a private key and a public key.


 The private key generates a public key.
 The two keys are mathematically linked
 The public key then generates an address that is shared with others so you
can receive bitcoin.

For example, if ‘X’ wishes to transfer ‘Y’ 1 bitcoin, X must sign a


transaction using its private key and submit it to network nodes. Miners
having the ‘X’ public key will then examine the transaction conditions and
validate the signature
Locking and unlocking scripts
There are two types of script in bitcoin transaction:

 Unlocking script (located at the input) also known as ‘scriptSig’


 Locking script (located at the output) also known as ‘scriptPubKey’
 Bitcoin transactions use locking and unlocking scripts, which are executed together to verify a
transaction.
 Locking script is a spending condition specified in the transaction output,
 Unlocking script satisfies this condition when the two scripts are executed together.
 Any node will validate these scripts by combining and executing the locking and unlocking
scripts

 Combining scriptSig and scriptPubKey to evaluate a transaction script is an example of the


unlocking and locking scripts for the most common type of bitcoin transaction

Figure 4. Combining scriptSig and scriptPubKey to evaluate a transaction script

Types of bitcoin transactions:

Pay-to-Pubkey (P2PK)
 P2PK (Pay ToPubkey) is a script pattern that locks an output to a public key.

 The locking script for a P2PK transaction follows the format of

<public key> OP_CHECKSIG.


 OP_CHECKSIG checks for a signature against the provided public key
 When the script runs, the CHECKSIG opcode compares
the signature against the public key, and pushes a 1 on to the stack if
it is valid.
Pay-to-Pubkey-Hash (P2PKH):

 Pay-to-Pubkey-Hash (P2PKH) is now the most common type of transaction.

The scriptPubKey in P2PKH is the following:

OP_DUP OP_HASH160 <public key hash> OP_EQUALVERIFY OP_CHECKSIG

OP_DUP

OP_DUP pops the first element, and duplicates it. Then, it adds both back to the stack
OP_HASH160:

This pops the first element and hashes it twice. The first round will hash with the SHA-256
algorithm. The SHA-256 output is then hashed with the RIPEMD-160 algorithm. The
resulting output is added back onto the stack.

OP_EQUALVERIFY:

OP_EQUALVERIFY combines two other operators – OP_EQUAL and OP_VERIFY.


OP_EQUAL pops two elements and checks if they’re identical. If they are, it adds a 1 to the
stack. If not, it adds a 0.

OP_CHECKSIG:

pops them both and verifies the signature against the public key. If they match, it adds
a <1> to the stack. Otherwise, it adds a <0>.

The scriptSig looks like this:

<signature> <public key>


Pay-to-Script-Hash (P2SH)(MultiSig)

 It allows you to lock bitcoins to the hash of a script, and you


then provide that original script when you come unlock those
bitcoins.
 It basically allows you to create your own custom “redeem
scripts”, but still be able to share them easily with other
people.

A P2SH script is executed in two parts:


1. Standard Execution - The redeem script is hashed, and is
then checked that it is equal the script hash in the locking
script.
2. Redeem Script Execution - This is the special part.
The redeem script is deserialized and ran as if it were a
locking script.
3. redeemScript:
4. <signature> <public key> <redeemScript>
5. the scriptPubKey for a P2SH output is:
6. OP_HASH160 <redeemScript hash> OP_EQUAL
Pay-to-Witness-Pubkey-Hash (P2WPKH):

Pay-to-Witness-Pubkey-Hash (P2WPKH) is the SegWit version of P2PKH. Our witness


looks like this:

<signature> <public key>


The scriptPubKey resembles the following:

<OP_0> <public key hash>

witness: <signature><pubkey>

scriptSig: (empty)

scriptPubKey: 0 <20-byte-key-hash>

Then each validating node:

 Checks that Witness is <sig><pubKey>


 HASH160 of the public key match the 20-byte witness program
 verify the signature against the public key with CHECKSIG operation
Pay-to-Witness-Script-Hash (P2WSH)

 Pay-to-Witness-Script Hash (P2WSH) is the new P2SH.

 A P2WSH transaction locks bitcoin to the hash of a script.

scriptPubKey:

<OP_0> <script hash>

Witness:

<signature 1> <public key>

Examples of Bitcoin Script

Here are some examples of how Bitcoin Script can be used:

1. Multi-signature wallets - This is a popular use case for


Bitcoin Script. Multi-signature wallets require multiple
signatures before Bitcoin can be spent. For example, a 2-
of-3 multi-signature wallet would require two out of three
parties to sign the transaction before it can be processed.

2. Time-locked transactions - Bitcoin Script can also be used


to create time-locked transactions. For example, a time-
locked transaction can be set up to only be processed after
a specific date and time.

3. Escrow transactions - Escrow transactions are another


common use case for Bitcoin Script. An escrow transaction
allows two parties to send Bitcoin to a third party, who will
hold the Bitcoin until certain conditions are met. For
example, the Bitcoin might be released to one party once a
product has been delivered.

4. Bitcoin wallets - Bitcoin wallets like Electrum, Bitcoin Core,


and Trezor all use Bitcoin Script to create and verify
transactions.

5. Bitcoin exchanges - Bitcoin exchanges like Coinbase,


Binance, and Kraken all use Bitcoin Script to process
transactions on their platforms.

6. Decentralized applications (dApps) - Many decentralized


applications built on top of the Bitcoin network use Bitcoin
Script to create smart contracts. For example, the Lightning
Network, which is a layer-2 scaling solution for Bitcoin,
uses Bitcoin Script to enable instant micropayments.

7. Bitcoin payment processors - Bitcoin payment processors


like BitPay and CoinPayments use Bitcoin Script to process
payments and verify transactions.

8. Gambling sites - Some online gambling sites use Bitcoin


Script to create provably fair games. These games use
cryptographic algorithms to ensure that the outcome of
each game is fair and random.

9. Blockchain explorers - Blockchain explorers like Blockchair


and Blockchain.info use Bitcoin Script to parse and analyze
transactions on the Bitcoin network.

Usecases:
Escrow
A third party on behalf of two other parties that are in the process of
completing a transaction.

 An escrow is a third-party service that acts as an intermediary to increase the


security of transactions.
 For example, an escrow can be used when buying and selling goods.
 When the buyer has paid for the item, the escrow service will deposit the
purchase amount and inform the seller to deliver the item to the buyer.
 Once it has been confirmed that the buyer has received the goods, the
escrow service then sends the purchase amount to the seller.
 If the goods are inadequate, the buyer can send them to the escrow service to
get their money back. Since the escrow service acts as an intermediary, the
buyer does not need to negotiate the return with the seller.
Green Address:

GreenAddress is a multi-platform Bitcoin Wallet service. This wallet


provides security, privacy, and ease of use through multi-platform
mobility.

The green address is a third party trust trick and can help resolve most problems related
to the need to wait for confirmations (slow transactions).

To make it very simple :

 Service A publishes its green address, service B decides to trust service A.


 When someone sendbitcoins from service A to service B, he will send from the
service A green address.
 This is mostly useful for transferring bitcoins b2b (business to business),
 The green address is just a bitcoin address, but it's a "from" address people
decide to trust and accept transactions from this address without waiting for
confirmations.

Example:

As an example, assume website Z accepts incoming Bitcoin payments, but also trusts the green
address published by Mt. Gox. Customer C wants to withdraw funds from Mt. Gox and send
them to a payment address of website Z. A customer who does a withdrawal from Mt. Gox could
click the use green address checkbox, which will result in the payment being sent to the "green
address" derived from the special keypair as an intermediate step before forwarding the payment
to site Z. Site Z can confirm that the payment passed through Mt. Gox'skeypair and trust the
payment as confirmed immediately,
What are micropayments Bitcoin?
Micropayments are small online financial transactions that value less than a dollar,

The micropayment protocol allows one party (the client) to make repeated micropayments to
another party (the server). It works in two stages. Firstly, some value is locked up with a
multi-signature transaction that places it under the control of both parties.

This ensures that the refund won’t become valid until some period of time has passed
(currently, one day)
Downside of Bitcoin Mining
1.Volatility and Market Risk: The profitability of mining depends not only on the
amount of Bitcoin mined but also on its market value. Fluctuations in Bitcoin’s price
can affect mining profitability, potentially rendering some mining operations
unprofitable, especially during bear markets. Miners must carefully manage their
operational costs and be prepared for market uncertainties.
2.High Energy Consumption: Bitcoin mining is an energy-intensive process,
primarily due to the computational power required to solve complex mathematical
puzzles. As a result, mining operations consume significant amounts of electricity,
contributing to environmental concerns and carbon emissions. Critics argue that the
energy consumption associated with mining is unsustainable and exacerbates climate
change.
3.Cost of Equipment and Maintenance: Mining Bitcoin requires specialized
hardware, such as ASICs, which can be expensive to purchase and maintain.
Additionally, as the network difficulty increases, miners need to continually upgrade
their equipment to stay competitive. The capital expenditure and ongoing
maintenance costs can pose a barrier to entry for aspiring miners.
4.Long-Term Viability: A greater supply of coins result in a decrease in mining
rewards through a mechanism called halving. The decreased block rewards
combined with the increasing difficulty level can make mining less profitable over
time. Miners will need to rely more on transaction fees to sustain their operations
with some challenges too regarding profitability.
5.Centralization Concerns: While Bitcoin is designed to be decentralized, the reality
is that mining has become increasingly concentrated in the hands of a few large
players. Large-scale mining operations have access to more resources, allowing them
to dominate the network and potentially control the consensus process. This
concentration of power raises concerns about the centralization of Bitcoin mining
and the security of the network.

You might also like