0% found this document useful (0 votes)
78 views27 pages

Muhammad Hammad Mechanics of Blockchain: Scripts & Block

This document summarizes key aspects of scripts and blocks in blockchain mechanics. It describes how scripts are the programs that control transaction validation and comprise opcodes to perform operations like signature verification. Blocks bundle multiple transactions together in a permanent record that builds the blockchain ledger as each new block is added. Sample scripts and block structures are provided to illustrate how transactions are executed and blocks store blockchain data.

Uploaded by

Osama Yaqoob
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)
78 views27 pages

Muhammad Hammad Mechanics of Blockchain: Scripts & Block

This document summarizes key aspects of scripts and blocks in blockchain mechanics. It describes how scripts are the programs that control transaction validation and comprise opcodes to perform operations like signature verification. Blocks bundle multiple transactions together in a permanent record that builds the blockchain ledger as each new block is added. Sample scripts and block structures are provided to illustrate how transactions are executed and blocks store blockchain data.

Uploaded by

Osama Yaqoob
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/ 27

Muhammad Hammad

Mechanics of Blockchain: Scripts & Block


Outline
● Scripts
○ Features
○ opcodes
○ Execution
● Blocks
○ Structure
○ Example
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 (inspired from Forth language)
● Bitcoin scripts are compact, simple, finite, supports
cryptography and contains no loops
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!

99% of Bitcoin
Sample the Bitcoin transactions has this exact same
Script:
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_CHECKSI Takes public key and signature and validates the signature of the hash
G 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
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
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)
● Coin swapping protocols
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 bundles
multiple transactions together.
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
Reference Book
Bitcoin and Cryptocurrency Technologies
Authors: Arvind Narayanan, Joseph Bonneau,
Edward Felten, Andrew Miller, Steven Goldfeder

Publisher: Princeton University Press

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