0% found this document useful (0 votes)
195 views30 pages

PPT7-Bitcoin Scripts

The document discusses Bitcoin scripts which are used to validate transactions. Bitcoin scripts use a Forth-like language and are stack-based. A transaction is defined by its inputs and outputs, and scripts are used to ensure inputs correctly claim outputs. Scripts contain public keys, signatures, and opcodes to verify transactions.

Uploaded by

Jitin Jitin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views30 pages

PPT7-Bitcoin Scripts

The document discusses Bitcoin scripts which are used to validate transactions. Bitcoin scripts use a Forth-like language and are stack-based. A transaction is defined by its inputs and outputs, and scripts are used to ensure inputs correctly claim outputs. Scripts contain public keys, signatures, and opcodes to verify transactions.

Uploaded by

Jitin Jitin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

BITCOIN SCRIPTS

Athira Jayavarma
Dept. of EEE

1
• A transaction is characterized by two parameters

• The output (out) of the transaction

• The input (in) of the transaction

• We need to determine that a transaction input is correctly claimed a transaction


output

• Scripts –A simple, compact, mini programming language to validate the bitcoin


transactions

• It is a list of instructions recorded with each transaction

• Describes how the public key and private key interacts during a transaction.

• Forth like language,stack based and processed left to right 2


FORTH Language
• A stacked based computer programming language originally designed
by Charles Moore
• A procedural programming language without type checking
• Use a stack for recursive subroutine execution
• Uses reverse polish notation(RPN) or Postfix notation

3
4
FORTH sample execution using RPN

5
First put 30 to the stack.Then 10 is also pushed into the stack.

Next, it is a multiplication operator. Whenever, getting an operator, popout the


two elements from the stack and do the operation.

Here multiplication operator is used, so do the multiplication.Then the answer is


pushed into the stack.

Next operand is 15, push it into the stack.

Next, ‘+’ operator.,

Pop out the two top operand from the stack and perform the operation and after
operation,push it again in the stack

Now the value is 315. and now next is CR instruction.


6
After getting CR instruction you finally get the output which is there at the top of
FORTH sample code

Equivalent C Code
int floor5(int n) {
if (n < 6) {
return 5;
} else {
return n - 1; }}

7
• FLOOR5: This is the name of the word being defined.
• (n—n`) :is used to describe what the word expects on the stack before execution and what it
leaves on the stack after execution.
In this case, "n" represents the input value, and "n`" represents the modified value that will be left
on the stack.
• DUP: This word duplicates the top value on the stack. After this operation, the stack contains two
copies of the same value.
• 6 < IF: This checks if the duplicated value on the stack is less than 6.
• DROP: If the value is less than 6, this word discards (removes) the top value from the stack. This
effectively removes the duplicated value.
• 5: If the value is less than 6, the code pushes the value 5 onto the stack.
• ELSE: If the value is not less than 6, the execution continues here.
• 1 -: This subtracts 1 from the duplicated value on the stack.
• THEN: This marks the end of the conditional block. It corresponds to the end of the IF-ELSE
construct.
8
Bitcoin Transactions and Input and Output

9
• Transactions in a bitcoin can be characterized by the input and corresponding output.
• You can represent the bitcoin transactions in the form of a series of inputs and outputs
• If one user Alice has received some 100 bitcoins, out of this100 bitcoins, Alice sends 40 bitcoins to Bob and
60 bitcoins to Charley. This transaction has one input which is coming to Alice from someone else and has
two outputs one output is going to the input of Bob and another output is going as input of Charley
• With the help of bitcoin script we want to actually ensure that this particular input corresponds to this
particular output

10
 An example, Alice wants to make a certain transaction with Bob. Alice
initiated a transaction with a certain amount that contain the address of
bob and Alice
 The transaction includes two parameters one is the Alice public key and
signature.
 Alice has the private key with her and with that, she has generated this
particular signature and if Alice public key is available, Bob can verify the
signature and he can be sure that the transaction has actually been sent by
Alice and is a valid one.
 What bitcoin has does that instead of sending public key and digital
signature, Bitcoin actually transfer some scripts.
11
• Traditionally bitcoin uses two scripts one is corresponding to the signature which is called
scriptsig and another script corresponds to the public key which is scriptpubkey.

• scripts don’t support all the operations like a loop and it was intentionally made simple

• With every transaction Alice must provide

• A public key that, when hashed, yields the address of Alice embedded in the script

• A signature to provide ownership of the private key corresponding to the public key of Alice

12
Example of Bitcoin Script

 If we want to make a transaction, a script for it would be like this


 All the above content is a simple Bitcoin transaction of the type of P2PKH(Pay
to Public Key Hash)
 This type of script is a standard script and in fact it is the most used way to send
bitcoins.
13
• The previous Bitcoin Script is delimited in two parts: scriptPubKey and
scriptSig.
• In the first, there are the actions to be performed, while the second
contains the signature and public key to verify the authenticity of such
actions.
• This ensures that only those who have access to the funds can carry
out any operation with them.
• Every script contains some data like public key and signature and
some operators or opcodes

14
15
16
17
18
19
20
21
• There are the OP_CODES that in the operation are the following:
• OP_DUP: Duplicate the item on the top stack.
• OP_HASH160: The input is encoded twice: first with SHA-256 and
then with RIPEMD-160.
• OP_EQUALVERIFY: Verify that the data entered is correct and valid.
• OP_CHECKSIG: The outputs, inputs, and script of the entire
transaction are summarized in a hash. The signature used must be a
valid signature for this hash and must be next to the public key.
Checksig is the particular operator that check a signature against the
public key to make sure they match.
22
• Now what happens during script execution is as follows:
1.First, the original public key of the owner (which is in the scriptSig) of
the funds is duplicated.
2.The duplicate public key then goes through a hashing process. In this
process, a hash is applied first SHA-256 and a RIPEMD-160 hash is
then applied to the result.
3.The result of the hashes is compared with the hash of the public key
that is in the scriptPubKey to make sure it is EQUALVERIFY (that is, it is
the same key and is verified as valid).
4.If it matches, the script continues to run and CHECKSIG is performed
to verify the signature with the public key.

23
Bitcoin Script Instructions
Total256 Opcodes(15 disabled,75 reserved)
• Arithmetic operations
• If-then conditions
• Logical operators
• Data Handling
Cryptographic Operations
• Hash Functions
• Signature verification
• Multi signature verification
24
25
26
27
• Locking script can be found in the output of a transaction and
unlocking script can be found in input of a transaction .

28
Join in a Bitcoin Network

To join in the bitcoin network, open up your wallet and immediately start send a
join message to join in the network.

if the old nodes are not responding for certain duration in generally it is for three
hours then they are automatically removed from the bitcoin network

whenever a new node comes and once to join in the network, there are certain
nodes in the network which work as the seed node.

The task of the seed node is to provide the initial information to the new nodes
who are going to join in the network 29
whenever you are trying to join in the network you send a message to one of the
seed node.

In response, this seed node will send you a set of addresses whom you can
consider as the peer .

Now, among that set of addresses which has been returned by the seed node;
you can select certain random number of nodes and you can create a kind of
peering relationship with those particular nodes and you can join in this overly
network.

Once you have joint in the network the first task of a node is to get the most
recent blockchain from your peer nodes and update your local copy of
blockchain. 30

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy