1. by
Topalidis Georgios
under the supervision of
Professor Stefanidis Georgios
12 February 2016
University of Macedonia
Department of Applied Informatics
Bachelor’s Thesis: Analyzing and Programming the
Basic Transactions of Bitcoin System
2. Purpose of Thesis
Analyzing the Basic Transactions and executing the
Scripts, in stack which are responsible for their behavior in
Bitcoin system.
Programming the Basic Transactions with the aid of
BitcoinJ(library of Java).
3. Contents
What is Bitcoin?
Features of Bitcoin
Node Types and Roles
The Technology Behind Bitcoin
The Basic Mechanism
Structure of an Elliptic Key
Public Key to Bitcoin Address
Anatomy of a Transaction
Inputs and Outputs of a Transaction
Thinking in Transaction Scripts
Basic Transactions and Scripting Language
A Pay-to-Pub-Key-Hash Transaction
Execution in Stack
Applications of Bitcoin Scripts
Facts
4. What is Bitcoin?
Is a global currency
Around since January of 2009
Peer-to-peer/decentralized
Trading over the Internet
Protocol is open source
Somewhat anonymous
Protected by strong encryption(cryptocurrency)
5. Features of Bitcoin
All-electronic
Provable value
Fast transactions
Low-cost transactions
No third-party trust required
Uncontrollable(Decentralized)
Deflationary (Maximum 21M issued)
International
Widely accepted as a currency
6. Node Types and Roles
Bitcoin System
Wallet
Network
Routing
Node
B
Full
Blockchain
Miner
7. The Technology Behind Bitcoin
Cryptographic Hash Functions(SHA256,RIPEMD160)
Proof-of-Work(hash cash proof) miners must solve the
problem:
H (nonce || prev_hash||tx||tx) <target
Elliptic curve Digital Signature Algorithm (ECDSA)
(sk,pk) := generateKeys(keysize)
sig := sign(sk,message)
isValid :=verify(pk,message,sig)
Merkle Tree
S
c
h
e
m
e
8. The Basic Mechanism
1
TX1 Published
to the P2P
network
2
3TX1 added to my
block
My Block
Coinbase
TX
TX1
.
TXn
N-2
CB TX
Tx1
.
.
Txn
4
N-1
CB TX
Tx1
.
.
Txn
N=My Block
CB TX
Tx1
.
.
Txn
The Blockchain 25
BT
C
9. Structure of an Elliptic Key
Private Key: k Public Key : K
K=k*G
G: generator point of elliptic
curve
10. Public Key to Bitcoin Address
Public Key: K
SHA256(K)
RIPEMD(SHA256(K))
Base58Check
Encoding
Bitcoin Address
12. Inputs and Outputs of a Transaction
Inputs:
Value in BTs which is going to be spend if the receiver holds a valid signature in
Unlocking Script.
This value came from a previous TX which still has unspent outputs (UTXO).
Outputs from previous TX becoming Inputs of present TX.
Outputs:
Set the conditions, in the Locking Script, which have to be fulfilled in order the
receiver to be able to redeem the BTs.
13. Thinking in Transaction Scripts
A new transaction is valid if the transaction scripts of its
input field and the transaction script of its preceding
validates to true.
Input TX Unlocking
Script
Output TX Locking
Script
Validation Script
[Unlocking Script, Locking Script
14. Basic Transactions and Scripting Language
Basic Transactions
1) Pay-to-Public-Key-Hash Transaction (P2PKH)
2) Pay-to-Public-Key Transaction (Coinbase
Transactions)
3) Multi-Signature Transaction
4) Pay-to-Script-Hash Transaction (P2SH)
5) Data Output Transaction (OP_RETURN)
Scripting Language
Stack-based
Every instruction is executed exactly once, in a linear
Example
follows
17. Applications of Bitcoin Scripts
Escrow Transactions
Introduce a third party and implement a MULTISIG(2-of-3)
Transaction.
Green Addresses
Being able to send BTs without the recipient being able to
access the Blockchain. Example: Mt.Gox(Bitcoin Exchange
company)bankruptcy
Efficient Micro-Payments
Being able to pay small amounts of money for some
provided service
18. Facts
Current Bitcoin Price: 1BT=376.95 euros (11/2/2016)
Reward for finding blocks: 25BT
every 4 years this price is divided by 2 (200950BT,
201225BT)
Hash Rate=1,031,625,717 GH/s, 1GH/s=109 H/s
(7/2/2016)
every 10 minutes a new block is going to be mined
Number of blocks so far: 397933 (11/2/2016)
every block can include maximum 4000 transactions