You are on page 1of 63

Dr.N.

Sharmili

UNIt3: Blockchain
technologies
Syllabus
Introduction to Bitcoin :
Bitcoin Block chain and scripts,

BCt Use cases of Bitcoin


Blockchain scripting language in micropayment,
escrow etc
Downside of Bit coin mining,
Block chain Science: Grid coin, Folding coin,
Block chain Genomics,
Bit coin MOOCs

Presentation title 2
Introduction to Bitcoin

• Bitcoin is a completely decentralised, peer-to-


peer, permissionless cryptocurrency put forth
in 2009 by Satoshi Nakamoto.
• Bitcoin is the first blockchain application.
• It is permissionless , i.e. open to anyone.
• Bitcoin blockchain size is growing
exponentially.

Presentation title 3
Presentation title 4
Bitcoin Script

• Bitcoin Script is the language Bitcoin uses to do everything it can do, from sending funds from a wallet to allowing the creation of
multi-user accounts.
• bitcoinscript, is a simple programming language used in Bitcoin for the processing of transactions that is read from left to right. this is
based on a series of linear structures, known as stack, which contain existing data in order LIFO (Last In - Firt Out). Each instruction in
this language is executed one after the other consecutively .
• In BitcoinIn, the opcodes (OP CODES), serve various functions. Like memory manipulation, math, loops, function calls, among many
others.
• Due to the structure in which BItcoin has been created, there is the possibility of defining 256 OP_CODES, different of which start from
number 0 to 255. Of these 256 OP_CODES, a total of 116 are currently active.
• these OP_CODES are the ones that allow you to carry out the different operations in Bitcoin and its transaction scheduling, such as
data flow control, constant management, stack management, logical management, arithmetic, time lock, pseudo-words, cryptographic
operations, and reserved words. You can see a complete and updated list of the different OP_CODES directly in the bitcoin code.
• Bitcoin Script is a set of instructions that record every transaction made.

Presentation title 5
Presentation title 6
Presentation title 7
Presentation title 8
Presentation title 9
0-false 1-true
Presentation title 10
Presentation title 11
Presentation title 12
Presentation title 13
Presentation title 14
Presentation title 15
Presentation title 16
Presentation title 17
Presentation title 18
Presentation title 19
Presentation title 21
Presentation title 22
Presentation title 23
Standard Scripts

Despite being able to create a variety of different locking scripts with various combinations of,
most nodes will only relay a handful of “standard scripts”:
•P2PK (Pay to Pubkey)
•P2PKH (Pay to Pubkey Hash)
•P2MS (Pay to Multisig)
•P2SH (Pay to Script Hash)
•NULL DAtA

Presentation title 24
Presentation title 25
Presentation title 26
P2PK(Pay to Pubkey)

Presentation title 27
this script pattern is used to “send” someone bitcoins. It’s the most common script used for locking
an output to someone’s public key.

Every time you send bitcoins to


an address that starts with a 1 you
are creating a P2PKH locking
script.

Presentation title 28
P2MS(Pay to Multisig
For example, you could create a P2MS script that
includes the public keys of 3 different people,
but only 2 of those people would need to provide
their signatures to spend the bitcoins:

Presentation title 29
Presentation title 30
•If the signature does not match the public key,
we move on to the next public key and check
that one. However, that public key will also
be ignored for every subsequent signature (so
make sure you put your signatures in order in
the scriptSig!).
•If the signature matches the public key, we
increment a tally and repeat for the next
signature.

Presentation title 31
Presentation title 32
Presentation title 33
Presentation title 34
Presentation title 35
Presentation title 36
Presentation title 37
• he first two instructions of such a transaction are the signature and the public key used to
generate that signature. this information is identified as “<sig>” and “<pubKey>” and pushed
onto the stack. Mitchell determines these values as he is the recipient. this first half of the
transaction is often called “scriptSig” or the “Unlocking Script.” In this section of the operation,
there is also reference to a previously existing Unspent transaction Output (UtXO).
• “Each input contains an unlocking script and refers to a previously existing UtXO. the validation software will copy the
unlocking script, retrieve the UtXO referenced by the input, and copy the locking script from that UtXO.”
• the second portion of the transaction, the “Locking Script” or “scriptPubkey,” is then executed by the author. Based on the
above image, the next instruction “OP_DUP” pops off the <pubKey> from the stack, duplicates it, then returns it to the
stack.

Presentation title 38
Bitcoin Script Features

• the Bitcoin programming language has features that differentiate it from other languages. Below we will
see some of them.
• Small language. this language is considered small, since it contains only 256 instructions and each
instruction is expressed in one byte.
• It contains all the information. there is no state of the transaction before or after the script, since all the
information is contained in it.
• Limited functionality. Bitcoin Script is limited so it brings a higher level of security to the system.
• It is simple as it requires minimal processing.
• Adaptability. because of its simplicity it can be run on a wide range of devices.
• Incomplete turing language. Being incomplete, it does not allow loops. this ensures that the program
stops repeating itself and with it the errors in the network.

Presentation title 39
• this top value, or the duplicate of the <pubKey>, is then cryptographically hashed by the
“OP_HASH160” instruction and becomes “<pubKeyHash>.”

• the specific hashing function used for Bitcoin transactions is called SHA-256 (Secure Hash
Algorithm) and is part of a larger group of functions known as SHA-2, which comes from a
National Security Agency development in 1993. Other members of the SHA-2 family include
SHA-224, SHA-256, SHA-384, and SHA-512 with each number representing the bit length of the
message they produce.
• the applications are vast within the field of information security, with the most relevant being
Bitcoin and Haschash’s Proof-of-Work (PoW) consensus mechanism. the most notable feature
of SHA-256 is its ability to prevent DoS attacks as mentioned above.

Presentation title 40
Presentation title 41
• In the Bitcoin network, each Bitcoin Script is divided into two types
of scripts, the scriptSig y scriptPubKey. First, the scriptSig is the
unlock script, which requires a public key and a digital signature.
• the scriptPubKey, is the blocking script, which contains a public
key hash, also called a Bitcoin address.

Presentation title 42
What is Escrow Smart Contract?

• Escrow is the third party that holds the asset(asset can be


money, bond, or stocks) in the presence of two parties.Escrow
will release the fund when certain conditions are met.
• For Example: “A” is a seller and wants to sell his car, and “B” is
a buyer who wants to buy “A”‘s car so they will contact Escrow
“C”(an arbiter) which holds the asset until “B” receives the car.
When this condition will be met, Escrow will release the fund
to “A”. this solves the issue of trust and prevents any
discrepancy.
• Let us write a smart contract for the Escrow using solidity
language.
}

// Declaring the object of the enumerator


State public state;

// Defining function modifier 'instate'


modifier instate(State expected_state){

require(state == expected_state);
_;
}

// Defining function modifier 'onlyBuyer'


modifier onlyBuyer(){
require(msg.sender == buyer ||
msg.sender == arbiter);
_;
}

// Defining function modifier 'onlySeller'


modifier onlySeller(){
require(msg.sender == seller);
_;
}

// Defining a constructor
constructor(address payable _buyer,
address payable _sender){

// Assigning the values of the


// state variables
arbiter = payable(msg.sender);
buyer = _buyer;
seller = _sender;
state = State.awate_payment;
}

Presentation title
// Defining function to confirm payment 44
function confirm_payment() onlyBuyer instate(
• Escrow transactons
• An escrow is a Fnancial arrangemen where a third party holds and
regulates payment of the funds required for two parties involved in a
given transacton.
• –
• It helps make transactons more secure by keeping the payment in a
secure escrowaccount which is only released when all of the terms of
an agreement are met asoverseen by the escrow company

Presentation title 45
How does Escrow Work?
1.Escrow.com reduces the risk of fraud by acting as a trusted third-party that collects, holds and
only disburses funds when both Buyers and Sellers are satisfied.
2.Buyer and Seller agree to terms - Either the Buyer or Seller begins a transaction. After registering
at Escrow.com, all parties agree to the terms of the transaction.
3.Buyer pays Escrow.com - the Buyer submits a payment by approved payment method to our
secure Escrow Account, Escrow.com verifies the payment, the Seller is notified that funds have been
secured 'In Escrow’.
4.Seller ships merchandise to Buyer - Upon payment verification, the Seller is authorised to send the
merchandise and submit tracking information. Escrow.com verifies that the Buyer receives the
merchandise.
5.Buyer accepts merchandise - the Buyer has a set number of days to inspect the merchandise and
the option to accept or reject it. the Buyer accepts the merchandise
6.Escrow.com pays the Seller - Escrow.com releases funds to the Seller from the EscrowAccount.

Presentation title 46
Presentation title 47
Escrow transactions
• What are the advantages of having a scripting language, since it's more
complicated than just using public keys?
• One is to do escrow transactons, that could be useful in the following
situaton:
• –Alice wants to buy some things from Bob
• –She wants to pay with Bitcoins and Bob has to send physical goods to
Alice
• –Alice doesn't want to pay until she receives it. And Bob doesn't want to
send it, until he has received the payment

Presentation title 48
Soluton in Bitcoin system:
–Alice creates a MULTISIG transaction that requires two or three people to sign in order to redeem the coins. These people are
Alice, Bob and Judy. Judy is a judge, who will come into play only if there's any dispute.
–Alice signs the transaction redeeming some coins that she owns. These coins are held in escrow between Alice, Bob, and Judy.
Any two of them can specify where the coin should go.
–Bob can safely send the goods to Alice and sign the transaction that releases money to him.
–If the goods arrive and corresponds to what Alice expected, she can release the money towards Bob signing the transaction.
The money will be sent to Bob without the need of Judy's intervention. This happens if both are honest.
–Otherwise Alice could ask for her money back. And maybe Bob doesn't agree to sign the transactons that releases the money
towards Alice.
–Now it's Judy's turn to decide who's right and sign the transaction that releases money either towards Alice or Bob.
•In both cases, since only two signatures are required, the money will be sent towards one of them.

Presentation title 49
Presentation title 50
Presentation title 51
Presentation title 52
Micropayments
• Micropayments using Bitcoin work by sending very small amounts of
Bitcoin from one party to another for specific services, content, or
goods. The concept behind micropayments is to enable transactions
of tiny fractions of a Bitcoin, which can be a challenge due to Bitcoin's
transaction fees and scalability limitations. To address these
challenges, various solutions and techniques have been developed.
Here's a simplified example of how micropayments using Bitcoin
might work:

Presentation title 53
Presentation title 54
Presentation title 55
Presentation title 56
Lock time

Presentation title 57
Presentation title 58
• Scenario: Alice wants to access a premium article on Bob's website,
and the cost is 0.001 BTC (1,000 satoshis). Alice doesn't want to pay a
high transaction fee, so they use a Lightning Network channel for
micropayments.

Presentation title 59
Steps:
1.Opening a Lightning Channel:
•Alice and Bob both open a Lightning Network channel by depositing a certain amount of Bitcoin. Let's say they each
deposit 0.01 BTC into the channel.
2.Funding the Channel:
•Once the channel is open, it's funded with a total of 0.02 BTC (0.01 BTC from Alice and 0.01 BTC from Bob).
3.Creating an Invoice:
•Bob generates an invoice for Alice to access the premium article, which costs 0.001 BTC. The invoice contains the
payment request and a payment hash.
4.Payment Authorization:
•Alice authorizes the payment of 0.001 BTC by signing the payment with her private key.
5.Payment Execution:
•The payment is instantly executed within the Lightning Network. The payment channel updates to reflect the new
balance. Alice's channel balance decreases by 0.001 BTC, and Bob's balance increases by 0.001 BTC.
6.Closing the Channel:
•At any point, either Alice or Bob can close the Lightning channel. The final balances are settled on the Bitcoin blockchain.
In this case, Alice would receive her remaining 0.009 BTC, and Bob would receive 0.011 BTC.
In this example, Alice can make multiple micropayments to Bob within the same channel without incurring additional Bitcoin
transaction fees. The Lightning Network is a layer-2 solution built on top of the Bitcoin blockchain, designed specifically for fast
and low-cost transactions, making it suitable for micropayments.
Keep in mind that this is a simplified explanation, and the actual process involves more technical details. Additionally, the
Lightning Network is just one approach to enabling micropayments with Bitcoin, and there are other emerging solutions and
protocols in this space as well.
Presentation title 60
Certainly, let's illustrate the scenario with a simple example involving Alice and Bob using a multisignature (multisig) Bitcoin
wallet:
1.Setting Up the Multisig Wallet:
•Alice and Bob decide to create a 2-of-2 multisig wallet, meaning it requires both of their signatures to spend funds.
•They fund the wallet with 5 BTC.
2.Initiating Transactions:
•After a conversation, Alice decides to pay Bob for some service they agreed upon. She creates a transaction within the
multisig wallet that sends 1 BTC to Bob and returns 4 BTC to the wallet.
•This transaction is only signed by Alice at this point, and it remains unpublished on the Bitcoin blockchain.
3.Repeat Process:
•Every minute, Alice repeats this process, creating a new transaction that sends a portion of the remaining balance to Bob
and returns the rest to the wallet. For example:
•After 2 minutes, Alice sends another transaction, sending 2 BTC to Bob and returning 3 BTC to the wallet.
•After 3 minutes, Alice sends yet another transaction, sending 1.5 BTC to Bob and returning 1.5 BTC to the wallet.
•Alice can continue this process for as long as needed, always creating a new transaction every minute.
4.Bob's Action:
•Bob can choose when he wants to access the funds he's received from Alice. When he's ready, he signs the most recent
transaction created by Alice, which corresponds to the amount he's owed.
•For instance, if Bob wants to claim 2.5 BTC, he signs the transaction that sends 2.5 BTC to him and returns the remaining
balance to the wallet.
Presentation title 61
5.Blockchain Publication:
•Bob then publishes the signed transaction on the Bitcoin blockchain.
•The transaction gets confirmed on the blockchain, and Bob receives the 2.5 BTC he claimed.
6.Remaining Transactions:
•The previously created but unsigned transactions by Alice are never published on the blockchain. Since
Bob has chosen to claim only one of them, the other transactions remain unused and do not affect the
blockchain.
This process allows Alice to make multiple payments to Bob without overloading the blockchain with individual
transactions. It ensures that only the necessary transaction for the actual payment is recorded on the
blockchain, while the others remain unexecuted unless needed.
Was this response better or worse?

Presentation title 62
Sharmili Nukapeyi
thank you
logintosharmi@gvpcew.ac.in

You might also like