SlideShare a Scribd company logo
1 of 113
BLOCKCHAIN
TECHNOLOGY IN JAVA
About The Course
• blockchain fundamentals
• blockchain implementation in Java
More and more people are looking to invest in Bitcoin and other cryptocurrencies, in hopes of making it rich.
While the buzz and hype surrounding cryptocurrency don’t seem like it is going to die down anytime soon, the underlying
foundation of Bitcoin is starting to take center stage.
If you’re like a majority of the population, you probably have a lot of questions about blockchain technology and the
hype surrounding the emerging technology.
Blockchain Secrets
click here
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
wants to buy a car wants to sell a car
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
wants to buy a car wants to sell a car
PROBLEM: no trust
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
wants to buy a car wants to sell a car
PROBLEM: no trust
TRUSTED THIRD PARTY
(centralized system such as governments)
the buyer has to notify
the government that now
he owns a car
the seller has to notify
the government that
he sold his car
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
wants to buy a car wants to sell a car
PROBLEM: no trust
BLOCKCHAIN TECHNOLOGY CAN GET RID
OF THESE THIRD PARTIES !!!
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
DECENTRALIZED NETWORK OF CAR BUYERS
AND SELLERS WITH BLOCKCHAIN !!!
it is a trustless system without
any third party
(the blockchain itself guarantees trust)
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and to use decentralized ones instead)
A wants to send money to B B want to receive money from A
PROBLEM: no trust
TRUSTED THIRD PARTY
(centralized system such as bank)
sender has to notify the bank
to send $x to B the trusted third party (bank)
will send money to B
Blockchain - motivation
At the moment centralized system are dominating
~ the aim of the blockchain technology is to get rid of these
centralized systems (and use decentralized ones instead)
DECENTRALIZED NETWORK OF CLIENTS
WITH BLOCKCHAIN !!!
it is a trustless system without
any third party
(the blockchain itself guarantees trust)
Blockchain - motivation
Further articles/videos on the topic:
https://www.youtube.com/watch?v=dVsdy7fUynw
Blockchain
„A blockchain is a continuously growing list of records, called blocks,
which are linked and secured using cryptography”
 it was first constructed by Stuart Haber and W. Scott Tornetta in 1991
 blockchain is the underlying technology and data structure of cryptocurrencies
~ we can store for example transactions in the blocks
 it is a linked list where the nodes are the blocks in the blockchain and the
references are hashes of the previous block in the chain
REFERENCES ARE CRYPTOGRAPHIC HASHES !!!
Blockchain
GENESIS
BLOCK
BLOCK #1 BLOCK #2 BLOCK #3 ...
Data: ...
Prev. Hash: 0000
Hash: 056FH
Data: ...
Prev. Hash: 056FH
Hash: HJI66
Data: ...
Prev. Hash: HJI66
Hash: ZU77F
Data: ...
Prev. Hash: ZU77F
Hash: 789BV
Blockchain
...
...
GIVEN BLOCK IN
THE BLOCKCHAIN
(cryptocurrency)
block id
transaction(s)
hash
previous hash
timestamp
nonce
merkle root
Blockchain
GENESIS
BLOCK
BLOCK #1 BLOCK #2 BLOCK #3 ...
Data: ...
Prev. Hash: 0000
Hash: 056FH
Data: ...
Prev. Hash: 056FH
Hash: HJI66
Data: ...
Prev. Hash: HJI66
Hash: ZU77F
Data: ...
Prev. Hash: ZU77F
Hash: 789BV
 so the blockchain itself is a linked list with hash-pointers
 every node in the blockchain has 2 hash values: own hash and
the hash value of the previous block
„Blocks form a linked list where the nodes are cryptographically linked together”
Blockchain – SHA256
So blocks in a blockchain use hash-pointers to reference the
previous node in the linked-list
~ we assign a hash to every node: this is how we identify them
How to calculate these hashes?
It is very similar to fingerprints: we identify every human with his/her fingerprint
~ we want to do the same but with the blocks in the blockchain
THE SHA256 HASHES ARE THE FINGERPRINTS OF THE BLOCKS !!!
 SHA256 was constructed by the National Security Agency (NSA)
 it is a generic cryptographic hash function: the input can be anything
and the output is a 256 bit long hexadecimal sequence
What is the input when dealing with blockchains? The given block is the input for the SHA256
Blockchain – SHA256
36f47ded94c31186f3a1d6c27fb7d607b47ff2a91b4e98d84e1e28ec583cedbd
Hexadecimal: [0:9] and [A:F] these are the possible values
 it means there are 16 possibilities which can be represented
on 4 bits (24=16)
Output: 64 character hexadecimal string (independent of the input)
 because the hash itself takes up 256 bits in the memory and
every character’s size is 4 bits thats why the length
of the output is 64
Blockchain – SHA256
FEATURES OF HASHING ALGORITHMS
1.) deterministic: it means that if we apply to same hash-function (SHA256) on
the exact same input then the output must be the same
2.) one-way: it is easy to generate the hash with the given hashing algorithm but
on the other hand it is extremely hard (time-consuming) to restore the original input
~ it is like a trap-door function
3.) collision-free: there are no collisions in SHA256 (ok there are but with extremely low probability)
It means that no two different inputs share the same output hash
~ and this is good: we want to make these hashes unique, this
is how we identify a block in the blockchain
4.) avalanche effect: a little change in the input results in a completely different output hash
~ otherwise a cryptoanalyst can make predictions about the input
based on the output exclusively
Blockchain – SHA256
Further articles/videos on the topic:
Implementation and pseudocode of the SHA256 algorithm:
https://www.movable-type.co.uk/scripts/sha256.html
SHA256 and collisions
https://crypto.stackexchange.com/questions/47809/why-havent-any-sha-256-collisions-been-found-yet?rq=1
Blockchain – immutable ledger
PROBLEM: no trust
TRUSTED THIRD PARTY
(centralized system such as banks)
In centralized systems there is a central database or server where
the data is stored (centralized ledger)
~ it has all the information (identity of users or transactions)
PROBLEM: if we hack the central database then its done
CENTRAL LEDGER
Transaction #1
Transaction #2
Transaction #3
Transaction #4
A wants to send money to B B want to receive money from A
sender has to notify the bank
to send $x to B
the trusted third party (bank)
will send money to B
Blockchain – immutable ledger
By the way this architecture is very similar to the client-server model
It is a centralized architecture: the server is the center
 data (and the database) is present on a
single logical server
 anyone with the right credentials (username/password)
can access these systems (databases for example)
Blockchain – immutable ledger
In decentralized systems there is NO central database or server where
the data is stored (decentralized ledger)
~ we are not able to hack the system: we should hack most of the nodes
in the network to do so
It is a P2P (peer-to-peer) decentralized
network of nodes
 every node in the network have a copy of the blockchain
 if someone tempers the data in a block: the cryptographic
hash changes as well so the pointers are broken
OK the hacker may change the hash values
in other blocks as well ...
EXTREMELY HARD TO HACK DECENTRALIZED SYSTEMS !!!
Data that has been written to a block cannot be changed
or erased: this is why it is called immutable
Blockchain – immutable ledger
the transactions
(blocks and the blockchain itself)
are visible to everyone in the network
(decentralized ledger)
Blockchain – immutable ledger
Blockchain – immutable ledger
because of the decentralized
feature of the system the nodes
will notify each other on every update
Blockchain – immutable ledger
Blockchain – immutable ledger
Blockchain – immutable ledger
Blockchain – immutable ledger
Blockchain – immutable ledger
because of the decentralized
feature of the system the nodes
will notify the attacked node
that there is some inconsistency
Blockchain – immutable ledger
Blockchain – immutable ledger
Blockchain – mining
Mining is basically the most important concept in blockchain
as well as in cryptocurrencies (such as Bitcoin)
in a centralized system the
trusted third party (banks)
handle the transactions
(softwares and databases)
PROBLEM: in a decentralized system who will handle the transactions?
MINERS WILL HANDLE AND VERIFY THE TRANSACTIONS !!!
 getting paid is not the aim of mining it is just the by-product
 mining is the mechanism that allows the blockchain to be
a decentralized security
 it is about finding the right hash values for the blocks and
adding these blocks to the blockchain
MINERS WILL ADD THE BLOCKS TO THE BLOCKCHAIN !!!
Blockchain – mining
GENESIS
BLOCK
BLOCK #1 BLOCK #2 BLOCK #3 ...
Data: ...
Prev. Hash: 0000
Hash: 056FH
Data: ...
Prev. Hash: 056FH
Hash: HJI66
Data: ...
Prev. Hash: HJI66
Hash: ZU77F
Data: ...
Prev. Hash: ZU77F
Hash: 789BV
 miners find the hash values for the blocks
 so they try to find the right hash values (computational heavy procedure)
Blockchain – mining
0000000000000000000000000000000000000000000000000000000000000000
1000000000000000000000000000000000000000000000000000000000000000
2000000000000000000000000000000000000000000000000000000000000000
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD
.
.
.
How many SHA256 hashes are there?
One hash takes up 256 bits in the memory
with binary values (0 or 1): it means the
total number of hashes is 2256
The same result in hexadecimal format:
there are 64 hexadecimal characters (so 16
possible values) which yield 1664
 mining has an important parameter: in bitcoin it is called „difficulty”
and it is characterized by leading zeros
The aim of mining is to generate hashes: BUT there is some constraints
~ most of the generated SHA256 hashes are not allowed
THE DIFFICULTY OF MINING IS DEFINED BY THE LEADING ZEROS !!!
Blockchain – mining
00008ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc
In this case there are 4 leading zeros in the hash: so the aim of mining is to
find an arbitrary hash with 4 leading zeros
 why is it called difficulty? Because the more leading zeros are there,
the harder to find that given hash
Blockchain – mining
02d38ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc
In this case there are 4 leading zeros in the hash: so the aim of mining is to
find an arbitrary hash with 4 leading zeros
 why is it called difficulty? Because the more leading zeros are there,
the harder to find that given hash
P(finding hash with 1 leading zero) =
𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟏𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨
𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬
𝟏𝟔𝟔𝟑
𝟏𝟔𝟔𝟒
= 1/16 = 6.25%
=
Blockchain – mining
00d38ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc
In this case there are 4 leading zeros in the hash: so the aim of mining is to
find an arbitrary hash with 4 leading zeros
 why is it called difficulty? Because the more leading zeros are there,
the harder to find that given hash
P(finding hash with 2 leading zero) =
𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟐𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨
𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬
𝟏𝟔𝟔𝟐
𝟏𝟔𝟔𝟒
= 1/256 = 0.39%
=
Blockchain – mining
0000000000000000008f3cdce825df28d36d8fdc39904060d2c18b13c096edc
In this case there are 4 leading zeros in the hash: so the aim of mining is to
find an arbitrary hash with 4 leading zeros
 why is it called difficulty? Because the more leading zeros are there,
the harder to find that given hash
P(finding hash with 18 leading zero) =
𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟏𝟖𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨
𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬
𝟏𝟔𝟒𝟔
𝟏𝟔𝟔𝟒
= 2.1x10-20%
=
(this is the actual difficulty of bitcoin)
Blockchain – mining
How to generate these hashes? We use all the information present in the block and
feed this data to the SHA256 algorithm to get the 64 characters long hash
GIVEN BLOCK IN
THE BLOCKCHAIN
block id
transaction(s)
previous hash
nonce
merkle root
 we we use the data in the block BUT most of the data
is immutable: we can not change the ID or the transactions
 but of course we have to change something to change the
hash (so the output of the SHA256 algorithm)
THIS IS WHY WE HAVE THE NONCE: we change the value thus
we change the SHA256 hash
Blockchain – mining
NONCE: „number only used once”
 it is a 32 bit unsigned integer so the range is [0 - 4billion]
 during the mining operation miners change the value of this nonce
Why is it good? Because for every possible value of the nonce the
miners get a new SHA256 hash
 miners can not guess the value of the nonce (because of the avalanche-effect)
so usually they start with 0 and keep incrementing it by 1
(Why to make mining difficult? It is called proof of work)
Blockchain – consensus
Byzantine generals problem: illustrates the problem of how distributed consensus work
Blockchain nodes are synchronizing their data all the time
~ there is no central authority to approve the operations (transactions for example) so the
majority of the nodes should reach a consensus before updating the dibstributed ledger
THIS IS THE PROCESS OF CONSENSUS !!!
For example: a given miner adds a block to the blockchain
and the other nodes must reach a consensus
(whether to approve or to reject)
Blockchain – consensus
TWO GENERALS PROBLEM
GENERAL #1 GENERAL #2
ENEMY
The problem is that 2 generals plan to attack
the enemy’s city BUT somehow they have to
reach a consensus whether to attack or not
 they have to use messages because
their camps are far apart
 the messages can be lost
The problem is that the generals must reach a consensus to avoid total annihilation
Best-case scenario: both of them attacks in this case they can win the battle (or both retreive)
Worst-case scenario: just one of them attacks and the enemy wins
SOMEHOW THEY HAVE TO REACH A CONSENSUS !!!
(in this case the network itself can not be trusted)
Blockchain – consensus
GENERAL #1
wants to attack
GENERAL #2
TWO GENERALS PROBLEM
Blockchain – consensus
GENERAL #1
wants to attack
GENERAL #2
#1 will attack
#2 want to attack
TWO GENERALS PROBLEM
Blockchain – consensus
GENERAL #1
wants to attack
GENERAL #2
#1 will attack
#2 want to attack
#1 will attack
#2 will attack
TWO GENERALS PROBLEM
Blockchain – consensus
GENERAL #1
wants to attack
GENERAL #2
#1 will attack
#2 want to attack
#1 will attack
#2 will attack
TWO GENERALS PROBLEM
Blockchain – consensus
GENERAL #1
wants to attack
GENERAL #2
#1 will attack
#2 want to attack
#1 will attack
#2 will attack
PROBLEM: this approach needs infinite number of messages between the generals
~ if last message is lost then #2 will not attack and #1 will attack
which means there is no consensus
(by the way there is no solution to this problem)
TWO GENERALS PROBLEM
Blockchain – consensus
CONCLUSION: so if the network is corrupted (and can not be trusted) there is
nothing we can do to reach a consensus
 usually: the network can be statistically byzantine which means that somet
transmits the messages sometimes it does not
~ in this case we have to send 1000 messages to
sure one of them will reach the destin
TWO GENERALS PROBLEM
Blockchain – consensus
ASSUMPTION: the network itself works perfectly but the nodes can be corrupted
Question: how to reach consensus in a distributed network where
nodes can be corrupted (traitors)
BYZANTINE GENERALS PROBLEM
 the traitors’ aim is to make sure there won’t
be any consensus (so some of the generals will attack
some of them will retreat so the enemy will win)
 the generals (traitors as well) broadcast the messages
through the network
 majority vote: every general selects an alternative
which have a majority (more than half of the votes)
[attack,attack,retreat,attack]  ATTACK !!!
Blockchain – consensus
ASSUMPTION: the network itself works perfectly but the nodes can be corrupted
Question: how to reach consensus in a distributed network where
nodes can be corrupted (traitors)
BYZANTINE GENERALS PROBLEM
general #1 general #2
general #3
Attack! Attack!
Attack!
Blockchain – consensus
ASSUMPTION: the network itself works perfectly but the nodes can be corrupted
Question: how to reach consensus in a distributed network where
nodes can be corrupted (traitors)
BYZANTINE GENERALS PROBLEM
general #1 traitor
general #3
Attack! Attack!
Retreat!
NO CONSENSUS
Blockchain – consensus
ASSUMPTION: the network itself works perfectly but the nodes can be corrupted
Question: how to reach consensus in a distributed network where
nodes can be corrupted (traitors)
BYZANTINE GENERALS PROBLEM
general #1 traitor
general #3
Attack! Attack!
Retreat!
NO CONSENSUS
Lemma: there are no solutions (no consensus) for the
byzantine generals problem for 3n+1 generals
with greater than n traitors
 if more than 1/3 of the generals are traitors then
there is no consensus (no solution)
Blockchain – consensus
How to make sure that all the transactions are valid and not created by hackers?
If 51% of the nodes in the network agrees on something then the transaction is accepted !!!
Approaches to handle fault tolerance (byzantine generals problem):
1.) proof of work
2.) proof of stake
DISTRIBUTED CONSENSUS
Blockchain – proof of work
Mining itself is made to be a difficult operation (computationally expensive)
 hard to find the right hash BUT very easy (fast) to verify it
 why does it solve the byzantine generals problem? Because the system makes it
very expensive to become a traitor
// it was first used to prevent spam emails: you’d have to perform a small amount of
proof of work and attach that in the header of the email + receiver can check
whether you’d put some work into that before you sent it
(spammer will not wait years to send >10k spam emails)
THE SYSTEM MAKES SURE THE OPERATIONS ARE EXPENSIVE ENOUGH !!!
Blockchain – proof of work
 finding the „golden hash” is so expensive that it would make
it really costly for that person to attack the network
Why is it expensive? Computers and electricity
 the original problem is that there is no way to trust everyone in the network
and proof-of-work (PoW) makes sure the miners do not cheat
„There is no way to trust that everyone in the network is honest, so there has
to be some way to prevent miners from creating new blocks that benefit themselves”
 if a miner finds the right hash he/she gets a reward but only if the other miners
agree to accept that transaction (others can verify these easily with SHA256)
 if a certain miner creates a fraudulent transaction then all the other miners
will refuse to accept it as a new block (so no point in creating a whole bunch of fraudulent blocks)
NASH-EQUILIBRIUM IS TO CREATE VALID BLOCKS (and this is what secures the networks)
Blockchain – proof of work
Disadvantages of PoW:
 it is rather inefficient: the main problem it does not solve anything
(we set the leading zeros to be 18 just to make it a hard problem to solve)
 so it is costly and wasteful (from an electricity perspective)
It cost half a billion dollars every year to secure the network (bitcoin) !!!
Cryptocurrency
PROBLEM: no trust
TRUSTED THIRD PARTY
(centralized system such as banks)
In centralized systems there is a central database or server where
the data is stored (centralized ledger)
~ it has all the information (identity of users or transactions)
PROBLEM: if we hack the central database then its done
CENTRAL LEDGER
transaction #1
transaction #2
transaction #3
transaction #4
A wants to send money to B B want to receive money from A
sender has to notify the bank
to send $x to B
the trusted third party (bank)
will send money to B
Cryptocurrency
There are two important layers in the bitcoin ecosystem:
1.) technology: the underlying technology is blockchain of course
2.) protocol: the protocol is the bitcoin protocol
~ bitcoin is a protocol and a cryptocurrency as well
It defines how the participants of the network communicate
with each other !!!
Bitcoin was constructed by Satoshi Nakamoto in 2009
“It is the first decentralized digital currency, as the system works without a
central bank or single administrator. The network is peer-to-peer
and transactions take place between users directly, without an intermediary.
These transactions are verified by network nodes through
the use of cryptography and recorded in a public distributed ledger called a blockchain”
Cryptocurrency
GENESIS
BLOCK
BLOCK #1 BLOCK #2 BLOCK #3 ...
Data: transaction1
Prev. Hash: 0000
Hash: 056FH
Data: transaction2
Prev. Hash: 056FH
Hash: HJI66
Data: transaction3
Prev. Hash: HJI66
Hash: ZU77F
Data: transaction4
Prev. Hash: ZU77F
Hash: 789BV
Cryptocurrency
Bitcoin has a monetary policy which is controlled entirely by the software
and it contains two main parts:
1.) halving: the number of coins released into the system is halfed every 4 years
(it is halfed after every 210.000 blocks to be precise)
 in 2009 the miners got 50 BTC after every block they verified
 now in 2018 miners get 12.5 BTC after the same operation
2.) block frequency: it means how much does it take on average to mine a block
It is 10 minutes for bitcoin (15 sec for Ethereum)
Cryptocurrency
Difficulty is 18 at the moment in the bitcoin network
~ miners have to find hashes with 18 leading zeros
BITCOIN NETWORK MAKES SURE NEW BLOCKS ARE MINED IN EVERY 10 MINUTES
 so the diffculty may increase or decrease
 the difficulty increases: if it take <10min to mine a block
 difficulty decreases: if it takes >10min to mine a block
Cryptocurrency
MEMPOOL
users add new transactions
(so pre-verified transactions)
are inserted into
the mempool
stores the transactions until a
given miner verifies them and
puts them into a block
miners take the
transactions and put them
into the blocks
Cryptocurrency
How do miners select the optimal set of transactions?
 miners select M transactions from the mempool and create a new block
in the blockchain with these transactions (+find the right hash for the block)
 every transaction has a transaction fee: this is the amount the user is willing to pay
for making the given transaction
It is basically an optimization problem (bin-packing): we have a bin with capacity C (1MB) and we have
N items with values t t ... t
1 2 N
What items to include in the bin to maximize the profit?
~ miners will sort the items and take the ones with the highest
transaction fees (note the miners get the sum of fees after mining)
MINER’S REWARD = X BTC + TRANSACTION FEES
Cryptocurrency
MEMPOOL BLOCK
id: 5127654
timestamp: 1673576643
nonce: 13785
prev. hash: 000000DE543
data:
id: 1 fee: 0.1 BTC
id: 2 fee: 0.01 BTC
id: 3 fee: 0.3 BTC
id: 4 fee: 0.021 BTC
id: 5 fee: 0.6 BTC
id: 6 fee: 0.001 BTC
Cryptocurrency
MEMPOOL BLOCK
id: 5127654
timestamp: 1673576643
nonce: 13785
prev. hash: 000000DE543
data:
id: 1 fee: 0.1 BTC
id: 2 fee: 0.01 BTC
id: 3 fee: 0.3 BTC
id: 4 fee: 0.021 BTC
id: 5 fee: 0.6 BTC
id: 6 fee: 0.001 BTC
Cryptocurrency
MEMPOOL BLOCK
id: 5127654
timestamp: 1673576643
nonce: 13785
prev. hash: 000000DE543
data:
id: 1 fee: 0.1 BTC
id: 2 fee: 0.01 BTC
id: 3 fee: 0.3 BTC
id: 4 fee: 0.021 BTC
id: 5 fee: 0.6 BTC
id: 6 fee: 0.001 BTC
Cryptocurrency – Mempools
Cryptocurrency – Mempools
Cryptocurrency – Mempools
043A6E2
Cryptocurrency – Mempools
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA 76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
76CC3AE
E98A1AC
39261AA
76CC3AE
E98A1AC
39261AA
Cryptocurrency – Mempools
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
043A6E2
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
A53BC34
Cryptocurrency – Merkle Tree
BLOCK
id: 5127654
timestamp: 1673576643
nonce: 13785
prev. hash: 000000DE543
merkle root: A43E5A4C
data:
id: 1 fee: 0.1 BTC
id: 3 fee: 0.3 BTC
id: 5 fee: 0.6 BTC
We use SHA256 hashes to identify a given block in the blockchain
Shall we include all the transactions in the header? Not that optimal ...
 there can be 100-800 transactions within a single block
WE WANT TO REPRESENT ALL THESE TRANSACTIONS
WITH A SINGLE HASH !!!
 we create a tree-like structure and store the root of this
tree in the header (entries are SHA256 hashes)
 this Merkle-root can verify all the transaction and it is just
a single hash value
(if any of the transactions in the block changes then
the root’s value is changed as well: so this is why
we can verify all the transactions with the
Merkle-root exclusively)
Cryptocurrency – Merkle Tree
E65A8740039
A34001BE88C 0854A6EE221 A43C6E9980A
Cryptocurrency – Merkle Tree
E65A8740039
A34001BE88C 0854A6EE221 A43C6E9980A
03C10133A01 0C10E168D10
Cryptocurrency – Merkle Tree
E65A8740039
A34001BE88C 0854A6EE221 A43C6E9980A
03C10133A01 0C10E168D10
11EA79C2A01
Cryptocurrency – Merkle Tree
E65A8740039
A34001BE88C 0854A6EE221 A43C6E9980A
03C10133A01 0C10E168D10
11EA79C2A01 MERKLE-ROOT
Cryptocurrency – Merkle Tree
 we represent a set of transactions with the help of a SHA256
so a 64 characters long hexadecimal string (the Merkle-root itself)
 if a single detail in any of the transactions changes or even the order of the transactions
then the Merkle-root will change as well
+ it is part of the block’s header which forms the hash of the block
(after applying the SHA256 algorithm)
IT IS THE CRYPTOGRAPHIC PROOF OF WHICH TRANSACTIONS ARE IN THE BLOCK
 without the Merkle-root in the block’s header: we would not have proof of which transactions
are included in the given block and that their contents have not been tampered with
Cryptocurrency – Elliptic Curve Cryptography
There is a huge problem: all the data is public ...
Somehow we have to encrypt the transactions and have to make sure
that other nodes in the network can verify these transactions !!!
 bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm) to ensure that
funds can only be spent by their rightful owners
PRIVATE KEY it is a secret number (256 bits integer) known only to the person that generated it
~ we can sign a given transaction with the private key
PUBLIC KEY it is generated from the private key and no need to keep it secret
It is extremely hard to get the private key from the public key
(public key is a 2D point coordinate on an elliptic curve)
 we can verify the message (that has the signature) with the
help of the public key
Cryptocurrency – Elliptic Curve Cryptography
TRANSACTION
sender
receiver
amount
private key
of the owner
TRANSACTION
sender
receiver
amount
signature
...
anybody can verify the signature
and the transactions using
the public key
verify(transaction, publicKey)
Cryptocurrency – Elliptic Curve Cryptography
We identify wallets with the help of public keys
~ so when sending BTCs we have to use public keys
There is another layer of security: with RIPEMD we can generate a 160 bit long
hash which is called the address
WE CAN USE THIS ADDRESS WHEN TRANSFERRING MONEY TO A WALLET
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
these are called unspent
transaction outputs (UTXOs)
The problem: there is no account in the cryptocurrency network
~ we can calculate the balance of a given user (wallet) based on the UTXOs !!!
 we can use previous transactions during the actual transaction
 so the output of a transaction will be the input of another transaction
TRANSACTION INPUT AMOUNT = TRANSACTION OUTPUT AMOUNT
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
these are called unspent
transaction outputs (UTXOs)
I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine
~ we have to update the UTXOs because we make a transaction
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
these are called unspent
transaction outputs (UTXOs)
I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine
~ we have to update the UTXOs because we make a transaction
NEW TRANSACTION
INPUT OUTPUT
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
me  computer shop 0.25 BTC
me  me 0.05 BTC
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
these are called unspent
transaction outputs (UTXOs)
I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine
~ we have to update the UTXOs because we make a transaction
NEW TRANSACTION
INPUT OUTPUT
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
me  computer shop 0.25 BTC
me  me 0.05 BTC
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
these are called unspent
transaction outputs (UTXOs)
I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine
~ we have to update the UTXOs because we make a transaction
NEW TRANSACTION
INPUT OUTPUT
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
me  computer shop 0.25 BTC
me  me 0.05 BTC
Cryptocurrency - UTXOs
There may be several transactions in the cryprocurrency system
Daniel  me 0.01 BTC
these are called unspent
transaction outputs (UTXOs)
I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine
~ we have to update the UTXOs because we make a transaction
NEW TRANSACTION
INPUT OUTPUT
Adam  me 0.2 BTC
Kevin  me 0.1 BTC
me  computer shop 0.25 BTC
me  me 0.05 BTC
me  shop 0.25 BTC
me  me 0.05 BTC
Cryptocurrency - wallets
Bitcoin wallet is where the bitcoins are stores BUT actually bitcoins are not stored anywhere
~ there are the blockchain with the transactions and thats all ...
 in a centralized system the database stores the balance for every client
How to end up with a balance concerning a given wallet?
(so how to find out how much money does a user have)
WE CAN CALCULATE THE BALANCE BASED ON THE UTXOS !!!
Daniel  me 0.01 BTC
me  shop 0.25 BTC
me  me 0.05 BTC
We just have to consider the unspent transaction
outputs that belong to us + sum up the BTC values
BALANCE = 0.06 BTC
Cryptocurrency – 51% Attack
First of all, let’s discuss the competing chains problem
 it may happen that two or more blocks are mined at the same time
in different parts of the network
 these are broadcasted BUT there is a problem ... there are more than one
blockchains. What to accept?
IT IS VERY SIMILAR TO THE BYZANTINE GENERALS PROBLEM
 the network accepts the longer chain !!!
 if there are more chains with the same length then the nodes are waiting until
one of the blocks will grow larger than the others and accept that chain
NODES WITH HIGHER HASHING POWER GENERATE LONGER CHAINS
Cryptocurrency – 51% Attack
 because of the consensus protocol the attacker is able to double spend his coins
„double spending problem”
 if the attacker has 51% of the hashing power: it means that he is able to generate the
hashes faster than anyone else in the network
 because of the consensus protocol the longest chain is consider to be valid
Algorithm:
1.) keep mining the block BUT keep it private (do not broadcast the mined blocks)
2.) spend you coins in the public network AND do not include these transactions
in your own blockchain
3.) broadcast your blockchain: because you have the highest hashing power
it means you have the longest chain so it will be accepted as the valid chain
4.) the network will accept your blockchain ... you have already spent your coins but
after the broadcast (because of the missing transactions) you can do it again

More Related Content

Similar to blockchain.pptx

Blockchain In-Depth Tutorial for Beginners
Blockchain In-Depth Tutorial for BeginnersBlockchain In-Depth Tutorial for Beginners
Blockchain In-Depth Tutorial for Beginners
Simplilearn
 
Blockchain Power.pdf
Blockchain Power.pdfBlockchain Power.pdf
Blockchain Power.pdf
nikhilsmo44
 
Do a research and make a PowerPoint about Insulation for architect
Do a research and make a PowerPoint about Insulation for architectDo a research and make a PowerPoint about Insulation for architect
Do a research and make a PowerPoint about Insulation for architect
DustiBuckner14
 
38 C O M M U N I C AT I O N S O F T H E A C M M A.docx
38    C O M M U N I C AT I O N S  O F  T H E  A C M       M A.docx38    C O M M U N I C AT I O N S  O F  T H E  A C M       M A.docx
38 C O M M U N I C AT I O N S O F T H E A C M M A.docx
domenicacullison
 

Similar to blockchain.pptx (20)

Blockchain mechanism for IET Mauritius Network
Blockchain mechanism for IET Mauritius NetworkBlockchain mechanism for IET Mauritius Network
Blockchain mechanism for IET Mauritius Network
 
Blockchain- Ammar Ahmad.pdf
Blockchain- Ammar Ahmad.pdfBlockchain- Ammar Ahmad.pdf
Blockchain- Ammar Ahmad.pdf
 
Blockchain In-Depth Tutorial for Beginners
Blockchain In-Depth Tutorial for BeginnersBlockchain In-Depth Tutorial for Beginners
Blockchain In-Depth Tutorial for Beginners
 
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
 
BLOCKCHAIN PPT.pptx
BLOCKCHAIN PPT.pptxBLOCKCHAIN PPT.pptx
BLOCKCHAIN PPT.pptx
 
Symposium on Legal Regulation of Bitcoin, Blockchain & Cryptocurrencies
Symposium on Legal Regulation of Bitcoin, Blockchain & Cryptocurrencies Symposium on Legal Regulation of Bitcoin, Blockchain & Cryptocurrencies
Symposium on Legal Regulation of Bitcoin, Blockchain & Cryptocurrencies
 
Blockchain Power.pdf
Blockchain Power.pdfBlockchain Power.pdf
Blockchain Power.pdf
 
Blockchain data structures and fundamental
Blockchain data structures and fundamentalBlockchain data structures and fundamental
Blockchain data structures and fundamental
 
Blockchain Power.pdf
Blockchain Power.pdfBlockchain Power.pdf
Blockchain Power.pdf
 
Blockchain Corporate Style
Blockchain Corporate StyleBlockchain Corporate Style
Blockchain Corporate Style
 
How Blockchain Technology Is Evolving In The Cloud
How Blockchain Technology Is Evolving In The CloudHow Blockchain Technology Is Evolving In The Cloud
How Blockchain Technology Is Evolving In The Cloud
 
How Blockchain Technology Is Evolving In The Cloud - GoDgtl.pdf
How Blockchain Technology Is Evolving In The Cloud - GoDgtl.pdfHow Blockchain Technology Is Evolving In The Cloud - GoDgtl.pdf
How Blockchain Technology Is Evolving In The Cloud - GoDgtl.pdf
 
Blockchaintech
BlockchaintechBlockchaintech
Blockchaintech
 
Do a research and make a PowerPoint about Insulation for architect
Do a research and make a PowerPoint about Insulation for architectDo a research and make a PowerPoint about Insulation for architect
Do a research and make a PowerPoint about Insulation for architect
 
38 C O M M U N I C AT I O N S O F T H E A C M M A.docx
38    C O M M U N I C AT I O N S  O F  T H E  A C M       M A.docx38    C O M M U N I C AT I O N S  O F  T H E  A C M       M A.docx
38 C O M M U N I C AT I O N S O F T H E A C M M A.docx
 
blockchain.pdf
blockchain.pdfblockchain.pdf
blockchain.pdf
 
Blockchain ppt
Blockchain pptBlockchain ppt
Blockchain ppt
 
Blockchain Technology | Bitcoin | Ethereum Coin | Cryptocurrency
Blockchain Technology | Bitcoin | Ethereum Coin | CryptocurrencyBlockchain Technology | Bitcoin | Ethereum Coin | Cryptocurrency
Blockchain Technology | Bitcoin | Ethereum Coin | Cryptocurrency
 
CBGTBT - Part 2 - Blockchains 101
CBGTBT - Part 2 - Blockchains 101CBGTBT - Part 2 - Blockchains 101
CBGTBT - Part 2 - Blockchains 101
 
Bitcoin and Blockchain
Bitcoin and BlockchainBitcoin and Blockchain
Bitcoin and Blockchain
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

blockchain.pptx

  • 2. About The Course • blockchain fundamentals • blockchain implementation in Java More and more people are looking to invest in Bitcoin and other cryptocurrencies, in hopes of making it rich. While the buzz and hype surrounding cryptocurrency don’t seem like it is going to die down anytime soon, the underlying foundation of Bitcoin is starting to take center stage. If you’re like a majority of the population, you probably have a lot of questions about blockchain technology and the hype surrounding the emerging technology. Blockchain Secrets click here
  • 3. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead)
  • 4. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) wants to buy a car wants to sell a car
  • 5. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) wants to buy a car wants to sell a car PROBLEM: no trust
  • 6. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) wants to buy a car wants to sell a car PROBLEM: no trust TRUSTED THIRD PARTY (centralized system such as governments) the buyer has to notify the government that now he owns a car the seller has to notify the government that he sold his car
  • 7. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) wants to buy a car wants to sell a car PROBLEM: no trust BLOCKCHAIN TECHNOLOGY CAN GET RID OF THESE THIRD PARTIES !!!
  • 8. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) DECENTRALIZED NETWORK OF CAR BUYERS AND SELLERS WITH BLOCKCHAIN !!! it is a trustless system without any third party (the blockchain itself guarantees trust)
  • 9. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and to use decentralized ones instead) A wants to send money to B B want to receive money from A PROBLEM: no trust TRUSTED THIRD PARTY (centralized system such as bank) sender has to notify the bank to send $x to B the trusted third party (bank) will send money to B
  • 10. Blockchain - motivation At the moment centralized system are dominating ~ the aim of the blockchain technology is to get rid of these centralized systems (and use decentralized ones instead) DECENTRALIZED NETWORK OF CLIENTS WITH BLOCKCHAIN !!! it is a trustless system without any third party (the blockchain itself guarantees trust)
  • 11. Blockchain - motivation Further articles/videos on the topic: https://www.youtube.com/watch?v=dVsdy7fUynw
  • 12. Blockchain „A blockchain is a continuously growing list of records, called blocks, which are linked and secured using cryptography”  it was first constructed by Stuart Haber and W. Scott Tornetta in 1991  blockchain is the underlying technology and data structure of cryptocurrencies ~ we can store for example transactions in the blocks  it is a linked list where the nodes are the blocks in the blockchain and the references are hashes of the previous block in the chain REFERENCES ARE CRYPTOGRAPHIC HASHES !!!
  • 13. Blockchain GENESIS BLOCK BLOCK #1 BLOCK #2 BLOCK #3 ... Data: ... Prev. Hash: 0000 Hash: 056FH Data: ... Prev. Hash: 056FH Hash: HJI66 Data: ... Prev. Hash: HJI66 Hash: ZU77F Data: ... Prev. Hash: ZU77F Hash: 789BV
  • 14. Blockchain ... ... GIVEN BLOCK IN THE BLOCKCHAIN (cryptocurrency) block id transaction(s) hash previous hash timestamp nonce merkle root
  • 15. Blockchain GENESIS BLOCK BLOCK #1 BLOCK #2 BLOCK #3 ... Data: ... Prev. Hash: 0000 Hash: 056FH Data: ... Prev. Hash: 056FH Hash: HJI66 Data: ... Prev. Hash: HJI66 Hash: ZU77F Data: ... Prev. Hash: ZU77F Hash: 789BV  so the blockchain itself is a linked list with hash-pointers  every node in the blockchain has 2 hash values: own hash and the hash value of the previous block „Blocks form a linked list where the nodes are cryptographically linked together”
  • 16. Blockchain – SHA256 So blocks in a blockchain use hash-pointers to reference the previous node in the linked-list ~ we assign a hash to every node: this is how we identify them How to calculate these hashes? It is very similar to fingerprints: we identify every human with his/her fingerprint ~ we want to do the same but with the blocks in the blockchain THE SHA256 HASHES ARE THE FINGERPRINTS OF THE BLOCKS !!!  SHA256 was constructed by the National Security Agency (NSA)  it is a generic cryptographic hash function: the input can be anything and the output is a 256 bit long hexadecimal sequence What is the input when dealing with blockchains? The given block is the input for the SHA256
  • 17. Blockchain – SHA256 36f47ded94c31186f3a1d6c27fb7d607b47ff2a91b4e98d84e1e28ec583cedbd Hexadecimal: [0:9] and [A:F] these are the possible values  it means there are 16 possibilities which can be represented on 4 bits (24=16) Output: 64 character hexadecimal string (independent of the input)  because the hash itself takes up 256 bits in the memory and every character’s size is 4 bits thats why the length of the output is 64
  • 18. Blockchain – SHA256 FEATURES OF HASHING ALGORITHMS 1.) deterministic: it means that if we apply to same hash-function (SHA256) on the exact same input then the output must be the same 2.) one-way: it is easy to generate the hash with the given hashing algorithm but on the other hand it is extremely hard (time-consuming) to restore the original input ~ it is like a trap-door function 3.) collision-free: there are no collisions in SHA256 (ok there are but with extremely low probability) It means that no two different inputs share the same output hash ~ and this is good: we want to make these hashes unique, this is how we identify a block in the blockchain 4.) avalanche effect: a little change in the input results in a completely different output hash ~ otherwise a cryptoanalyst can make predictions about the input based on the output exclusively
  • 19. Blockchain – SHA256 Further articles/videos on the topic: Implementation and pseudocode of the SHA256 algorithm: https://www.movable-type.co.uk/scripts/sha256.html SHA256 and collisions https://crypto.stackexchange.com/questions/47809/why-havent-any-sha-256-collisions-been-found-yet?rq=1
  • 20. Blockchain – immutable ledger PROBLEM: no trust TRUSTED THIRD PARTY (centralized system such as banks) In centralized systems there is a central database or server where the data is stored (centralized ledger) ~ it has all the information (identity of users or transactions) PROBLEM: if we hack the central database then its done CENTRAL LEDGER Transaction #1 Transaction #2 Transaction #3 Transaction #4 A wants to send money to B B want to receive money from A sender has to notify the bank to send $x to B the trusted third party (bank) will send money to B
  • 21. Blockchain – immutable ledger By the way this architecture is very similar to the client-server model It is a centralized architecture: the server is the center  data (and the database) is present on a single logical server  anyone with the right credentials (username/password) can access these systems (databases for example)
  • 22. Blockchain – immutable ledger In decentralized systems there is NO central database or server where the data is stored (decentralized ledger) ~ we are not able to hack the system: we should hack most of the nodes in the network to do so It is a P2P (peer-to-peer) decentralized network of nodes  every node in the network have a copy of the blockchain  if someone tempers the data in a block: the cryptographic hash changes as well so the pointers are broken OK the hacker may change the hash values in other blocks as well ... EXTREMELY HARD TO HACK DECENTRALIZED SYSTEMS !!! Data that has been written to a block cannot be changed or erased: this is why it is called immutable
  • 23. Blockchain – immutable ledger the transactions (blocks and the blockchain itself) are visible to everyone in the network (decentralized ledger)
  • 25. Blockchain – immutable ledger because of the decentralized feature of the system the nodes will notify each other on every update
  • 30. Blockchain – immutable ledger because of the decentralized feature of the system the nodes will notify the attacked node that there is some inconsistency
  • 33. Blockchain – mining Mining is basically the most important concept in blockchain as well as in cryptocurrencies (such as Bitcoin) in a centralized system the trusted third party (banks) handle the transactions (softwares and databases) PROBLEM: in a decentralized system who will handle the transactions? MINERS WILL HANDLE AND VERIFY THE TRANSACTIONS !!!  getting paid is not the aim of mining it is just the by-product  mining is the mechanism that allows the blockchain to be a decentralized security  it is about finding the right hash values for the blocks and adding these blocks to the blockchain MINERS WILL ADD THE BLOCKS TO THE BLOCKCHAIN !!!
  • 34. Blockchain – mining GENESIS BLOCK BLOCK #1 BLOCK #2 BLOCK #3 ... Data: ... Prev. Hash: 0000 Hash: 056FH Data: ... Prev. Hash: 056FH Hash: HJI66 Data: ... Prev. Hash: HJI66 Hash: ZU77F Data: ... Prev. Hash: ZU77F Hash: 789BV  miners find the hash values for the blocks  so they try to find the right hash values (computational heavy procedure)
  • 35. Blockchain – mining 0000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000 2000000000000000000000000000000000000000000000000000000000000000 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD . . . How many SHA256 hashes are there? One hash takes up 256 bits in the memory with binary values (0 or 1): it means the total number of hashes is 2256 The same result in hexadecimal format: there are 64 hexadecimal characters (so 16 possible values) which yield 1664  mining has an important parameter: in bitcoin it is called „difficulty” and it is characterized by leading zeros The aim of mining is to generate hashes: BUT there is some constraints ~ most of the generated SHA256 hashes are not allowed THE DIFFICULTY OF MINING IS DEFINED BY THE LEADING ZEROS !!!
  • 36. Blockchain – mining 00008ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc In this case there are 4 leading zeros in the hash: so the aim of mining is to find an arbitrary hash with 4 leading zeros  why is it called difficulty? Because the more leading zeros are there, the harder to find that given hash
  • 37. Blockchain – mining 02d38ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc In this case there are 4 leading zeros in the hash: so the aim of mining is to find an arbitrary hash with 4 leading zeros  why is it called difficulty? Because the more leading zeros are there, the harder to find that given hash P(finding hash with 1 leading zero) = 𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟏𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨 𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬 𝟏𝟔𝟔𝟑 𝟏𝟔𝟔𝟒 = 1/16 = 6.25% =
  • 38. Blockchain – mining 00d38ebf07b0ca1ed92f3cdce825df28d36d8fdc39904060d2c18b13c096edc In this case there are 4 leading zeros in the hash: so the aim of mining is to find an arbitrary hash with 4 leading zeros  why is it called difficulty? Because the more leading zeros are there, the harder to find that given hash P(finding hash with 2 leading zero) = 𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟐𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨 𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬 𝟏𝟔𝟔𝟐 𝟏𝟔𝟔𝟒 = 1/256 = 0.39% =
  • 39. Blockchain – mining 0000000000000000008f3cdce825df28d36d8fdc39904060d2c18b13c096edc In this case there are 4 leading zeros in the hash: so the aim of mining is to find an arbitrary hash with 4 leading zeros  why is it called difficulty? Because the more leading zeros are there, the harder to find that given hash P(finding hash with 18 leading zero) = 𝐡𝐚𝐬𝐡𝐞𝐬𝐰𝐢𝐭𝐡𝟏𝟖𝐥𝐞𝐚𝐝𝐢𝐧𝐠𝐳𝐞𝐫𝐨 𝐭𝐨𝐭𝐚𝐥𝐧𝐮𝐦𝐛𝐞𝐫𝐨𝐟𝐡𝐚𝐬𝐡𝐞𝐬 𝟏𝟔𝟒𝟔 𝟏𝟔𝟔𝟒 = 2.1x10-20% = (this is the actual difficulty of bitcoin)
  • 40. Blockchain – mining How to generate these hashes? We use all the information present in the block and feed this data to the SHA256 algorithm to get the 64 characters long hash GIVEN BLOCK IN THE BLOCKCHAIN block id transaction(s) previous hash nonce merkle root  we we use the data in the block BUT most of the data is immutable: we can not change the ID or the transactions  but of course we have to change something to change the hash (so the output of the SHA256 algorithm) THIS IS WHY WE HAVE THE NONCE: we change the value thus we change the SHA256 hash
  • 41. Blockchain – mining NONCE: „number only used once”  it is a 32 bit unsigned integer so the range is [0 - 4billion]  during the mining operation miners change the value of this nonce Why is it good? Because for every possible value of the nonce the miners get a new SHA256 hash  miners can not guess the value of the nonce (because of the avalanche-effect) so usually they start with 0 and keep incrementing it by 1 (Why to make mining difficult? It is called proof of work)
  • 42. Blockchain – consensus Byzantine generals problem: illustrates the problem of how distributed consensus work Blockchain nodes are synchronizing their data all the time ~ there is no central authority to approve the operations (transactions for example) so the majority of the nodes should reach a consensus before updating the dibstributed ledger THIS IS THE PROCESS OF CONSENSUS !!! For example: a given miner adds a block to the blockchain and the other nodes must reach a consensus (whether to approve or to reject)
  • 43. Blockchain – consensus TWO GENERALS PROBLEM GENERAL #1 GENERAL #2 ENEMY The problem is that 2 generals plan to attack the enemy’s city BUT somehow they have to reach a consensus whether to attack or not  they have to use messages because their camps are far apart  the messages can be lost The problem is that the generals must reach a consensus to avoid total annihilation Best-case scenario: both of them attacks in this case they can win the battle (or both retreive) Worst-case scenario: just one of them attacks and the enemy wins SOMEHOW THEY HAVE TO REACH A CONSENSUS !!! (in this case the network itself can not be trusted)
  • 44. Blockchain – consensus GENERAL #1 wants to attack GENERAL #2 TWO GENERALS PROBLEM
  • 45. Blockchain – consensus GENERAL #1 wants to attack GENERAL #2 #1 will attack #2 want to attack TWO GENERALS PROBLEM
  • 46. Blockchain – consensus GENERAL #1 wants to attack GENERAL #2 #1 will attack #2 want to attack #1 will attack #2 will attack TWO GENERALS PROBLEM
  • 47. Blockchain – consensus GENERAL #1 wants to attack GENERAL #2 #1 will attack #2 want to attack #1 will attack #2 will attack TWO GENERALS PROBLEM
  • 48. Blockchain – consensus GENERAL #1 wants to attack GENERAL #2 #1 will attack #2 want to attack #1 will attack #2 will attack PROBLEM: this approach needs infinite number of messages between the generals ~ if last message is lost then #2 will not attack and #1 will attack which means there is no consensus (by the way there is no solution to this problem) TWO GENERALS PROBLEM
  • 49. Blockchain – consensus CONCLUSION: so if the network is corrupted (and can not be trusted) there is nothing we can do to reach a consensus  usually: the network can be statistically byzantine which means that somet transmits the messages sometimes it does not ~ in this case we have to send 1000 messages to sure one of them will reach the destin TWO GENERALS PROBLEM
  • 50. Blockchain – consensus ASSUMPTION: the network itself works perfectly but the nodes can be corrupted Question: how to reach consensus in a distributed network where nodes can be corrupted (traitors) BYZANTINE GENERALS PROBLEM  the traitors’ aim is to make sure there won’t be any consensus (so some of the generals will attack some of them will retreat so the enemy will win)  the generals (traitors as well) broadcast the messages through the network  majority vote: every general selects an alternative which have a majority (more than half of the votes) [attack,attack,retreat,attack]  ATTACK !!!
  • 51. Blockchain – consensus ASSUMPTION: the network itself works perfectly but the nodes can be corrupted Question: how to reach consensus in a distributed network where nodes can be corrupted (traitors) BYZANTINE GENERALS PROBLEM general #1 general #2 general #3 Attack! Attack! Attack!
  • 52. Blockchain – consensus ASSUMPTION: the network itself works perfectly but the nodes can be corrupted Question: how to reach consensus in a distributed network where nodes can be corrupted (traitors) BYZANTINE GENERALS PROBLEM general #1 traitor general #3 Attack! Attack! Retreat! NO CONSENSUS
  • 53. Blockchain – consensus ASSUMPTION: the network itself works perfectly but the nodes can be corrupted Question: how to reach consensus in a distributed network where nodes can be corrupted (traitors) BYZANTINE GENERALS PROBLEM general #1 traitor general #3 Attack! Attack! Retreat! NO CONSENSUS Lemma: there are no solutions (no consensus) for the byzantine generals problem for 3n+1 generals with greater than n traitors  if more than 1/3 of the generals are traitors then there is no consensus (no solution)
  • 54. Blockchain – consensus How to make sure that all the transactions are valid and not created by hackers? If 51% of the nodes in the network agrees on something then the transaction is accepted !!! Approaches to handle fault tolerance (byzantine generals problem): 1.) proof of work 2.) proof of stake DISTRIBUTED CONSENSUS
  • 55. Blockchain – proof of work Mining itself is made to be a difficult operation (computationally expensive)  hard to find the right hash BUT very easy (fast) to verify it  why does it solve the byzantine generals problem? Because the system makes it very expensive to become a traitor // it was first used to prevent spam emails: you’d have to perform a small amount of proof of work and attach that in the header of the email + receiver can check whether you’d put some work into that before you sent it (spammer will not wait years to send >10k spam emails) THE SYSTEM MAKES SURE THE OPERATIONS ARE EXPENSIVE ENOUGH !!!
  • 56. Blockchain – proof of work  finding the „golden hash” is so expensive that it would make it really costly for that person to attack the network Why is it expensive? Computers and electricity  the original problem is that there is no way to trust everyone in the network and proof-of-work (PoW) makes sure the miners do not cheat „There is no way to trust that everyone in the network is honest, so there has to be some way to prevent miners from creating new blocks that benefit themselves”  if a miner finds the right hash he/she gets a reward but only if the other miners agree to accept that transaction (others can verify these easily with SHA256)  if a certain miner creates a fraudulent transaction then all the other miners will refuse to accept it as a new block (so no point in creating a whole bunch of fraudulent blocks) NASH-EQUILIBRIUM IS TO CREATE VALID BLOCKS (and this is what secures the networks)
  • 57. Blockchain – proof of work Disadvantages of PoW:  it is rather inefficient: the main problem it does not solve anything (we set the leading zeros to be 18 just to make it a hard problem to solve)  so it is costly and wasteful (from an electricity perspective) It cost half a billion dollars every year to secure the network (bitcoin) !!!
  • 58. Cryptocurrency PROBLEM: no trust TRUSTED THIRD PARTY (centralized system such as banks) In centralized systems there is a central database or server where the data is stored (centralized ledger) ~ it has all the information (identity of users or transactions) PROBLEM: if we hack the central database then its done CENTRAL LEDGER transaction #1 transaction #2 transaction #3 transaction #4 A wants to send money to B B want to receive money from A sender has to notify the bank to send $x to B the trusted third party (bank) will send money to B
  • 59. Cryptocurrency There are two important layers in the bitcoin ecosystem: 1.) technology: the underlying technology is blockchain of course 2.) protocol: the protocol is the bitcoin protocol ~ bitcoin is a protocol and a cryptocurrency as well It defines how the participants of the network communicate with each other !!! Bitcoin was constructed by Satoshi Nakamoto in 2009 “It is the first decentralized digital currency, as the system works without a central bank or single administrator. The network is peer-to-peer and transactions take place between users directly, without an intermediary. These transactions are verified by network nodes through the use of cryptography and recorded in a public distributed ledger called a blockchain”
  • 60. Cryptocurrency GENESIS BLOCK BLOCK #1 BLOCK #2 BLOCK #3 ... Data: transaction1 Prev. Hash: 0000 Hash: 056FH Data: transaction2 Prev. Hash: 056FH Hash: HJI66 Data: transaction3 Prev. Hash: HJI66 Hash: ZU77F Data: transaction4 Prev. Hash: ZU77F Hash: 789BV
  • 61. Cryptocurrency Bitcoin has a monetary policy which is controlled entirely by the software and it contains two main parts: 1.) halving: the number of coins released into the system is halfed every 4 years (it is halfed after every 210.000 blocks to be precise)  in 2009 the miners got 50 BTC after every block they verified  now in 2018 miners get 12.5 BTC after the same operation 2.) block frequency: it means how much does it take on average to mine a block It is 10 minutes for bitcoin (15 sec for Ethereum)
  • 62. Cryptocurrency Difficulty is 18 at the moment in the bitcoin network ~ miners have to find hashes with 18 leading zeros BITCOIN NETWORK MAKES SURE NEW BLOCKS ARE MINED IN EVERY 10 MINUTES  so the diffculty may increase or decrease  the difficulty increases: if it take <10min to mine a block  difficulty decreases: if it takes >10min to mine a block
  • 63. Cryptocurrency MEMPOOL users add new transactions (so pre-verified transactions) are inserted into the mempool stores the transactions until a given miner verifies them and puts them into a block miners take the transactions and put them into the blocks
  • 64. Cryptocurrency How do miners select the optimal set of transactions?  miners select M transactions from the mempool and create a new block in the blockchain with these transactions (+find the right hash for the block)  every transaction has a transaction fee: this is the amount the user is willing to pay for making the given transaction It is basically an optimization problem (bin-packing): we have a bin with capacity C (1MB) and we have N items with values t t ... t 1 2 N What items to include in the bin to maximize the profit? ~ miners will sort the items and take the ones with the highest transaction fees (note the miners get the sum of fees after mining) MINER’S REWARD = X BTC + TRANSACTION FEES
  • 65. Cryptocurrency MEMPOOL BLOCK id: 5127654 timestamp: 1673576643 nonce: 13785 prev. hash: 000000DE543 data: id: 1 fee: 0.1 BTC id: 2 fee: 0.01 BTC id: 3 fee: 0.3 BTC id: 4 fee: 0.021 BTC id: 5 fee: 0.6 BTC id: 6 fee: 0.001 BTC
  • 66. Cryptocurrency MEMPOOL BLOCK id: 5127654 timestamp: 1673576643 nonce: 13785 prev. hash: 000000DE543 data: id: 1 fee: 0.1 BTC id: 2 fee: 0.01 BTC id: 3 fee: 0.3 BTC id: 4 fee: 0.021 BTC id: 5 fee: 0.6 BTC id: 6 fee: 0.001 BTC
  • 67. Cryptocurrency MEMPOOL BLOCK id: 5127654 timestamp: 1673576643 nonce: 13785 prev. hash: 000000DE543 data: id: 1 fee: 0.1 BTC id: 2 fee: 0.01 BTC id: 3 fee: 0.3 BTC id: 4 fee: 0.021 BTC id: 5 fee: 0.6 BTC id: 6 fee: 0.001 BTC
  • 96. Cryptocurrency – Merkle Tree BLOCK id: 5127654 timestamp: 1673576643 nonce: 13785 prev. hash: 000000DE543 merkle root: A43E5A4C data: id: 1 fee: 0.1 BTC id: 3 fee: 0.3 BTC id: 5 fee: 0.6 BTC We use SHA256 hashes to identify a given block in the blockchain Shall we include all the transactions in the header? Not that optimal ...  there can be 100-800 transactions within a single block WE WANT TO REPRESENT ALL THESE TRANSACTIONS WITH A SINGLE HASH !!!  we create a tree-like structure and store the root of this tree in the header (entries are SHA256 hashes)  this Merkle-root can verify all the transaction and it is just a single hash value (if any of the transactions in the block changes then the root’s value is changed as well: so this is why we can verify all the transactions with the Merkle-root exclusively)
  • 97. Cryptocurrency – Merkle Tree E65A8740039 A34001BE88C 0854A6EE221 A43C6E9980A
  • 98. Cryptocurrency – Merkle Tree E65A8740039 A34001BE88C 0854A6EE221 A43C6E9980A 03C10133A01 0C10E168D10
  • 99. Cryptocurrency – Merkle Tree E65A8740039 A34001BE88C 0854A6EE221 A43C6E9980A 03C10133A01 0C10E168D10 11EA79C2A01
  • 100. Cryptocurrency – Merkle Tree E65A8740039 A34001BE88C 0854A6EE221 A43C6E9980A 03C10133A01 0C10E168D10 11EA79C2A01 MERKLE-ROOT
  • 101. Cryptocurrency – Merkle Tree  we represent a set of transactions with the help of a SHA256 so a 64 characters long hexadecimal string (the Merkle-root itself)  if a single detail in any of the transactions changes or even the order of the transactions then the Merkle-root will change as well + it is part of the block’s header which forms the hash of the block (after applying the SHA256 algorithm) IT IS THE CRYPTOGRAPHIC PROOF OF WHICH TRANSACTIONS ARE IN THE BLOCK  without the Merkle-root in the block’s header: we would not have proof of which transactions are included in the given block and that their contents have not been tampered with
  • 102. Cryptocurrency – Elliptic Curve Cryptography There is a huge problem: all the data is public ... Somehow we have to encrypt the transactions and have to make sure that other nodes in the network can verify these transactions !!!  bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm) to ensure that funds can only be spent by their rightful owners PRIVATE KEY it is a secret number (256 bits integer) known only to the person that generated it ~ we can sign a given transaction with the private key PUBLIC KEY it is generated from the private key and no need to keep it secret It is extremely hard to get the private key from the public key (public key is a 2D point coordinate on an elliptic curve)  we can verify the message (that has the signature) with the help of the public key
  • 103. Cryptocurrency – Elliptic Curve Cryptography TRANSACTION sender receiver amount private key of the owner TRANSACTION sender receiver amount signature ... anybody can verify the signature and the transactions using the public key verify(transaction, publicKey)
  • 104. Cryptocurrency – Elliptic Curve Cryptography We identify wallets with the help of public keys ~ so when sending BTCs we have to use public keys There is another layer of security: with RIPEMD we can generate a 160 bit long hash which is called the address WE CAN USE THIS ADDRESS WHEN TRANSFERRING MONEY TO A WALLET
  • 105. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC Adam  me 0.2 BTC Kevin  me 0.1 BTC these are called unspent transaction outputs (UTXOs) The problem: there is no account in the cryptocurrency network ~ we can calculate the balance of a given user (wallet) based on the UTXOs !!!  we can use previous transactions during the actual transaction  so the output of a transaction will be the input of another transaction TRANSACTION INPUT AMOUNT = TRANSACTION OUTPUT AMOUNT
  • 106. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC Adam  me 0.2 BTC Kevin  me 0.1 BTC these are called unspent transaction outputs (UTXOs) I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine ~ we have to update the UTXOs because we make a transaction
  • 107. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC Adam  me 0.2 BTC Kevin  me 0.1 BTC these are called unspent transaction outputs (UTXOs) I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine ~ we have to update the UTXOs because we make a transaction NEW TRANSACTION INPUT OUTPUT Adam  me 0.2 BTC Kevin  me 0.1 BTC me  computer shop 0.25 BTC me  me 0.05 BTC
  • 108. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC Adam  me 0.2 BTC Kevin  me 0.1 BTC these are called unspent transaction outputs (UTXOs) I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine ~ we have to update the UTXOs because we make a transaction NEW TRANSACTION INPUT OUTPUT Adam  me 0.2 BTC Kevin  me 0.1 BTC me  computer shop 0.25 BTC me  me 0.05 BTC
  • 109. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC these are called unspent transaction outputs (UTXOs) I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine ~ we have to update the UTXOs because we make a transaction NEW TRANSACTION INPUT OUTPUT Adam  me 0.2 BTC Kevin  me 0.1 BTC me  computer shop 0.25 BTC me  me 0.05 BTC
  • 110. Cryptocurrency - UTXOs There may be several transactions in the cryprocurrency system Daniel  me 0.01 BTC these are called unspent transaction outputs (UTXOs) I want to buy a computer for 0.25 BTC: I can use the unspent transactions of mine ~ we have to update the UTXOs because we make a transaction NEW TRANSACTION INPUT OUTPUT Adam  me 0.2 BTC Kevin  me 0.1 BTC me  computer shop 0.25 BTC me  me 0.05 BTC me  shop 0.25 BTC me  me 0.05 BTC
  • 111. Cryptocurrency - wallets Bitcoin wallet is where the bitcoins are stores BUT actually bitcoins are not stored anywhere ~ there are the blockchain with the transactions and thats all ...  in a centralized system the database stores the balance for every client How to end up with a balance concerning a given wallet? (so how to find out how much money does a user have) WE CAN CALCULATE THE BALANCE BASED ON THE UTXOS !!! Daniel  me 0.01 BTC me  shop 0.25 BTC me  me 0.05 BTC We just have to consider the unspent transaction outputs that belong to us + sum up the BTC values BALANCE = 0.06 BTC
  • 112. Cryptocurrency – 51% Attack First of all, let’s discuss the competing chains problem  it may happen that two or more blocks are mined at the same time in different parts of the network  these are broadcasted BUT there is a problem ... there are more than one blockchains. What to accept? IT IS VERY SIMILAR TO THE BYZANTINE GENERALS PROBLEM  the network accepts the longer chain !!!  if there are more chains with the same length then the nodes are waiting until one of the blocks will grow larger than the others and accept that chain NODES WITH HIGHER HASHING POWER GENERATE LONGER CHAINS
  • 113. Cryptocurrency – 51% Attack  because of the consensus protocol the attacker is able to double spend his coins „double spending problem”  if the attacker has 51% of the hashing power: it means that he is able to generate the hashes faster than anyone else in the network  because of the consensus protocol the longest chain is consider to be valid Algorithm: 1.) keep mining the block BUT keep it private (do not broadcast the mined blocks) 2.) spend you coins in the public network AND do not include these transactions in your own blockchain 3.) broadcast your blockchain: because you have the highest hashing power it means you have the longest chain so it will be accepted as the valid chain 4.) the network will accept your blockchain ... you have already spent your coins but after the broadcast (because of the missing transactions) you can do it again