The document discusses blockchain technology and mining in blockchain networks. It explains that blockchain aims to replace centralized systems with decentralized networks to facilitate trustless transactions without third parties. Mining is the process by which transactions are verified and added to the blockchain in a decentralized manner. Miners use cryptographic hashing algorithms like SHA256 to find valid hashes that meet the network's difficulty criteria, allowing new blocks to be added to the immutable blockchain ledger. The nonce is a variable miners increment to get new hashes during the mining process.
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)
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 !!!
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)
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)
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)
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”
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
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)
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