0% found this document useful (0 votes)
22 views29 pages

Lec 5 - BCT

slides for lecture of blockchain

Uploaded by

hassaanawan777
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)
22 views29 pages

Lec 5 - BCT

slides for lecture of blockchain

Uploaded by

hassaanawan777
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/ 29

Blockchain Technology

Scripts
Mechanics of Blockchain:
Scripts
● A script is a program or sequence of
instructions that is interpreted or carried
out by another program rather than by
the computer processor
● Bitcoin script is based on stack-based
programming. The stack-based scripting
language embedded in Bitcoin
transactions.
● Bitcoin scripts are compact, simple,
Scripts
● When bitcoins are sent to a recipient, Script commands
in an unlocking script (scriptSig) validate the available
bitcoins (UTXOs), while Script commands in a locking
script (scriptPubKey) set the conditions for spending
them.
Input Script
Output Script
Bitcoin Scripts
Bitcoin Scripts
● There are 2 components of Bitcoin Script
(separated by whitespace): Data & Instruction
● Data: Digital Signature, Public Key of sender,
Public key of receiver, etc. Data is always pushed
to stack!
● Operation: A keyword recognizable by Bitcoin
client software, has a prefix of “OP_”. Operation
always executes a specific function!

Sample Bitcoin Script:

99% of the Bitcoin transactions has this exact same


Bitcoin Script Features
There are total 256 opcodes

● Arithmetic Operations
● If/Then Conditions
● Logic/Data Handling
● Cryptographic Functions
○ Computation of Hashes
○ Signature Verification
○ Multi-signature Verification
Bitcoin Script opcodes
opcode Description
OP_CHECKSIG Takes public key and signature and validates the signature of the hash of
the transaction.

OP_DUP Duplicates the top item in the stack.

OP_EQUAL Returns 1 if inputs are exactly equal, returns 0 if otherwise.

OP_IF If top stack value is not False, the statements are executed. The top
stack value is removed.

OP_AND Boolean AND between each bit of the inputs

OP_SPLIT Split byte sequence x at position n

OP_DROP Removes the top stack item

OP_HASH160 The input is hashed twice: first with SHA-256 and then with RIPEMD-160.

OP_DIV Input a is divided by input b

OP_MOD Return the remainder after input a is divided by input b

OP_SWAP The top two items on the stack are swapped.


Advanced Scripts
● Multi-signature
○ Escrow (Guarantor node)
○ Green Addresses (Guarantor bank)
● Micro-payments (Deliberate Double
Spending)
● Multiplayer Lotteries (Complex lottery
system)
● Hash pre-image challenge (Paid brute-
force job)
Bitcoin Script Execution
● Execution starts from left-to-right side of
the script
● First step is to push the digital signature
“<sig>” to the stack
Bitcoin Script Execution
● Public key of the sender “<pubKey>” is
also pushed to stack
Bitcoin Script Execution
● “OP_DUP” operation pops an item from
stack, makes a duplicate of the item and
then pushes it back
Bitcoin Script Execution
● “OP_HASH160” takes the top value of
stack, computes its hash and pushes it
back to the stack
Bitcoin Script Execution
● Public key hash, provided by the Bitcoin
owner, is pushed to stack
Bitcoin Script Execution
● “OP_EQUALVERIFY” operation takes top
2 values from stack and compares them
● If both are equal then a execution moves
towards next instruction
● If both are not equal then an error
message is generated and the execution
is stopped
Bitcoin Script Execution
● “OP_CHECKSIG” verifies the digital signature of the
sender
● 2 required parameters to verify signature, i.e.
signature and public key, are popped from stack
and consumed for this operation
● Since signature is tied to the whole transaction, so
this operation verifies that the whole transaction is
valid or not
● If signature is verified then it means the
transaction is valid and script is finished executing
Blocks
Mechanics of Blockchain:
Blocks
● Blocks are files where data pertaining to
the Blockchain are permanently
recorded.
● Each time a block is ‘completed’, it gives
way to the next block in the blockchain.
● A block is thus a permanent store of
records which, once written, cannot be
altered or removed.
● A block is like a page of a ledger which
Why Bundle Transactions
Together?
● Single unit of work for miners
● Shorten the length of the chain
● Less time to verify the chain
● Less amount of metadata
A Typical Blockchain Data
Structure
Example Bitcoin Block
Example Bitcoin Block
Header
Example Special Coin-
Creation Transaction
Real-Time Bitcoin Block View
Thanks

You might also like